-
-
Notifications
You must be signed in to change notification settings - Fork 129
/
project3.js
55 lines (47 loc) · 1.32 KB
/
project3.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
const SteamUser = require('steam-user');
const SteamTotp = require('steam-totp');
const SteamCommunity = require('steamcommunity');
const TradeOfferManager = require('steam-tradeoffer-manager');
const config = require('./config.json');
const client = new SteamUser();
const community = new SteamCommunity();
const manager = new TradeOfferManager({
steam: client,
community: community,
language: 'en'
});
const logOnOptions = {
accountName: config.username,
password: config.password,
twoFactorCode: SteamTotp.generateAuthCode(config.sharedSecret)
};
client.logOn(logOnOptions);
client.on('loggedOn', () => {
console.log('Logged into Steam');
client.setPersona(SteamUser.EPersonaState.Online);
client.gamesPlayed(440);
});
client.on('webSession', (sessionid, cookies) => {
manager.setCookies(cookies);
community.setCookies(cookies);
community.startConfirmationChecker(10000, config.idSecret);
});
manager.on('newOffer', offer => {
if (offer.itemsToGive.length === 0) {
offer.accept((err, status) => {
if (err) {
console.log(err);
} else {
console.log(`Donation accepted. Status: ${status}.`);
}
});
} else {
offer.decline(err => {
if (err) {
console.log(err);
} else {
console.log('Donation declined (wanted our items).');
}
});
}
});