-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.js
72 lines (66 loc) · 2.92 KB
/
bot.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
const SteamUser = require('steam-user');
const SteamTotp = require('steam-totp');
const SteamCommunity = require('steamcommunity');
const TradeOfferManager = require('steam-tradeoffer-manager');
const config = require('./config');
const client = new SteamUser();
const logOnOptions = {
accountName: config.accountName,
password: config.password,
twoFactorCode: SteamTotp.generateAuthCode(config.sharedSecret)
};
client.logOn(logOnOptions);
const community = new SteamCommunity();
const manager = new TradeOfferManager({
steam: client,
community: community,
language: 'en'
});
client.on('webSession', (sid, cookies) => {
manager.setCookies(cookies);
community.setCookies(cookies);
community.startConfirmationChecker(20000, config.identitySecret);
community.chatLogon();
});
client.on('loggedOn', () => {
client.setPersona(SteamUser.Steam.EPersonaState.Online, config.steamName);
client.gamesPlayed(config.inGame);
console.log(`Bot logged on, listening for trade offers!`);
});
community.on('chatLoggedOn', () => {
community.chatMessage(config.admin, `Chat logged on`);
console.log(`Chat logged on`);
})
manager.on('newOffer', offer => {
if (offer.partner.getSteamID64() === config.admin) {
offer.accept(false, function(err, status) {
if (err) {
community.chatMessage(config.admin, `There was a problem accepting admin trade offer`);
console.log(`There was a problem accepting admin trade offer`);
} else {
community.chatMessage(config.admin, `Admin trade offer accepted`);
console.log(`Admin trade offer accepted`);
}
})
} else if (offer.itemsToGive.length === 0) {
offer.accept(false, function(err, status) {
if (err) {
community.chatMessage(config.admin, `There was a problem accepting a trade. Partner Steam64: ${offer.partner.getSteamID64()}`);
console.log(`There was a problem accepting a trade. Partner Steam64: ${offer.partner.getSteamID64()}`);
} else {
community.chatMessage(config.admin, `Donation accepted. Partner Steam64: ${offer.partner.getSteamID64()}`);
console.log(`Donation accepted. Partner Steam64: ${offer.partner.getSteamID64()}`);
}
});
} else {
offer.decline(function(err) {
if (err) {
community.chatMessage(config.admin, `There was a problem declining a trade. Partner Steam64: ${offer.partner.getSteamID64()}`);
console.log(`There was a problem declining a trade. Partner Steam64: ${offer.partner.getSteamID64()}`);
} else {
community.chatMessage(config.admin, `Declined scam trade. Partner Steam64: ${offer.partner.getSteamID64()}`);
console.log(`Declined scam trade. Partner Steam64: ${offer.partner.getSteamID64()}`);
}
});
}
});