-
-
Notifications
You must be signed in to change notification settings - Fork 128
/
Copy pathproject2.js
101 lines (87 loc) · 2.45 KB
/
project2.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
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);
sendRandomItem();
});
manager.on('newOffer', offer => {
if (offer.partner.getSteamID64() === 'your_trusted_account_id') {
offer.accept((err, status) => {
if (err) {
console.log(err);
} else {
console.log(`Accepted offer. Status: ${status}.`);
}
});
} else {
offer.decline(err => {
if (err) {
console.log(err);
} else {
console.log('Canceled offer from scammer.');
}
});
}
});
function sendRandomItem() {
const partner = 'partner_steam_id';
const appid = 440;
const contextid = 2;
const offer = manager.createOffer(partner);
manager.loadInventory(appid, contextid, true, (err, myInv) => {
if (err) {
console.log(err);
} else {
const myItem = myInv[Math.floor(Math.random() * myInv.length - 1)];
offer.addMyItem(myItem);
manager.loadUserInventory(
partner,
appid,
contextid,
true,
(err, theirInv) => {
if (err) {
console.log(err);
} else {
const theirItem =
theirInv[Math.floor(Math.random() * theirInv.length - 1)];
offer.addTheirItem(theirItem);
offer.setMessage(
`Will you trade your ${theirItem.name} for my ${myItem.name}?`
);
offer.send((err, status) => {
if (err) {
console.log(err);
} else {
console.log(`Sent offer. Status: ${status}.`);
}
});
}
}
);
}
});
}