-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
186 lines (154 loc) · 6.6 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
// Config file
// const config = require('./config.json');
const config = require('./config-totp.json');
// Modules
const SteamUser = require('steam-user'),
SteamTopt = require('steam-totp'),
SteamCommunity = require('steamcommunity'),
TradeOfferManager = require('steam-tradeoffer-manager');
// Objects
const client = new SteamUser(),
community = new SteamCommunity();
const manager = new TradeOfferManager({
steam: client,
community: community,
language: 'en'
});
const logOnOptions = {
accountName: config.username,
password: config.password
// twoFactorCode: SteamTopt.generateAuthCode(config.shared_secret)
};
// Logins on Steam and simulates its client
client.logOn(logOnOptions);
console.log(`\nSteam Bot v2.0`);
console.log(`\nHere we go~\n`);
client.on('loggedOn', () => {
console.log('Successfully logged into Steam!');
// Sets status (can also receive a second parameter to change steam name)
client.setPersona(SteamUser.EPersonaState.Online);
// Sets currently playing game(s)
client.gamesPlayed(config.games);
});
let wallet;
client.chat.on('friendMessage', (message) => {
// getPersonas() for nickname is having issues
let id64 = message.steamid_friend.getSteamID64();
let name = client.users[id64] ? client.users[id64].player_name + ' ' : '';
console.log('Message from ' + name + '(' + id64 + '): ' + message.message);
});
// friendMessage#id64 only works on deprecated
client.on('friendMessage#76561198235235440', (steamId, message) => {
if (!message.startsWith(`${config.prefix}`))
return;
const args = message.split(" ").slice(1);
if (message.startsWith(`${config.prefix}idle`)) {
if (!args[0]) return client.chatMessage(steamId, `Please use the command correctly! (${config.prefix}idle <appid1 appid2>)`);
let gamesNum = args.map(parseFloat);
client.gamesPlayed(gamesNum);
}
if (message.startsWith(`${config.prefix}add`)) {
if (!args[0]) return client.chatMessage(steamId, `Please specify a Steam64 ID (${config.prefix}add <steam64id>)`);
client.addFriend(args[0]);
}
if (message.startsWith(`${config.prefix}remove`)) {
if (!args[0]) return client.chatMessage(steamId, `Please specify a Steam64 ID (${config.prefix}remove <steam64id>)`);
client.removeFriend(args[0]);
}
if (message.startsWith(`${config.prefix}block`)) {
if (!args[0]) return client.chatMessage(steamId, `Please specify a Steam64 ID (${config.prefix}block <steam64id>)`);
client.blockUser(args[0]);
}
if (message.startsWith(`${config.prefix}unblock`)) {
if (!args[0]) return client.chatMessage(steamId, `Please specify a Steam64 ID (${config.prefix}unblock <steam64id>)`);
client.unblockUser(args[0]);
}
if (message.startsWith(`${config.prefix}funds`)) {
client.chatMessage(steamId, `My wallet balance is: ${wallet}`);
}
if (message.startsWith(`${config.prefix}reply`)) {
let message2 = args.join(" ");
client.chatMessage(steamId, message2)
}
if (message.startsWith(`${config.prefix}comment`)) {
let steamId2 = args[0];
let comment = args.slice(1).join(" ");
if (!steamId2) return;
community.postUserComment(steamId2, comment);
}
if (message.startsWith(`${config.prefix}reboot`)) {
process.exit(1);
}
if (message.startsWith(`${config.prefix}rename`)) {
let username = args.slice(0).join(' ');
if (!username) {
client.chatMessage(steamId, 'Syntax Error (/setname <personaName)');
} else {
if (username.length < 2) {
client.chatMessage(steamId, 'Username must be longer than 2 characters');
} else if (username.length > 32) {
client.chatMessage(steamId, 'Username must not be greater than 32 characters');
} else {
client.setPersona(SteamUser.Steam.EPersonaState.Online, username);
}
}
}
if (message.startsWith(`${config.prefix}setstatus`)) {
if (!args[0])
return client.chatMessage(steamId, `Please use the command correctly! (${config.prefix}setstatus <status>)`);
let state = args[0];
let states = new Map([
["online", SteamUser.Steam.EPersonaState.Online],
["away", SteamUser.Steam.EPersonaState.Away],
["snooze", SteamUser.Steam.EPersonaState.Snooze],
["busy", SteamUser.Steam.EPersonaState.Busy],
["trade", SteamUser.Steam.EPersonaState.LookingToTrade],
["play", SteamUser.Steam.EPersonaState.LookingToPlay]
]);
if (states.has(state))
client.setPersona(states.get(state));
else
return client.chatMessage(steamId, `Sorry but I couldn't find a state with the name ${state}\nAvailable states: online, away, snooze, busy, trade, play`);
}
});
client.on('friendRelationship', (steamId, relationship) => {
// getPersonas() for nickname is having issues
if (relationship === 2) {
let id64 = steamId.getSteamID64();
client.addFriend(steamId);
let name = client.users[id64] ? client.users[id64].player_name + ' ' : '';
console.log('Accepted a friend request from ' + name + '(' + id64 +')');
}
});
client.on('wallet', function(hasWallet, currency, balance) {
wallet = SteamUser.formatCurrency(balance, currency);
});
client.on('error', (err) => {
console.log(err);
});
// Event listener to pass the cookies to the manager
// client.on('webSession', (sessionid, cookies) => {
// manager.setCookies(cookies);
// community.setCookies(cookies);
// community.startConfirmationChecker(15000, config.identity_secret); // <- checks if there's any pending confirmation every 10 secs
// });
// Accepts all trade offers from an specific account i.e your main account
// manager.on('newOffer', offer => {
// if (offer.partner.getSteamID64() === config.trusted_account) {
// offer.accept((err, status) => {
// if (err) { // <- if error occurs, show output to the user
// console.log('Something went wrong Status: ', err);
// } else { // <- else, trade confirmed
// console.log(`Trade offer accepted. Status: ${status}.`);
// }
// });
// } else { // <- if trade offer comes from an untrusted account
// offer.decline(err => {
// if (err) {
// console.log('Something went wrong Status: ' + err);
// } else {
// console.log('Cancelled offer from other account.');
// }
// });
// }
// });