-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.js
100 lines (80 loc) · 2.24 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import SteamUser from 'steam-user';
import SteamCommunity from 'steamcommunity';
import TradeOfferManager from 'steam-tradeoffer-manager';
class SteamBot {
constructor(logOnOptions) {
this.client = new SteamUser();
this.community = new SteamCommunity();
this.manager = new TradeOfferManager({
steam: this.client,
community: this.community,
language: 'en',
});
this.logOn(logOnOptions);
}
logOn(logOnOptions) {
this.client.logOn(logOnOptions);
this.client.on('loggedOn', () => {
console.log('Logged into Steam');
this.client.setPersona(SteamUser.EPersonaState.Online);
});
this.client.on('webSession', (sessionid, cookies) => {
this.manager.setCookies(cookies);
this.community.setCookies(cookies);
this.community.startConfirmationChecker(1000, process.env.STEAM_IDENTITY_SECRET);
});
}
sendWithdrawTrade(partnerId, item, callback) {
const offer = this.manager.createOffer(partnerId);
offer.addMyItem(item);
offer.setMessage('Withdraw item from the website!');
offer.send((err, status) => {
if (err) {
console.log("Error sending offer:", err);
callback(err, null, null);
} else {
console.log("Trade offer sent");
const tradelink = `https://steamcommunity.com/tradeoffer/${offer.id}`;
callback(null, tradelink, offer);
}
});
}
sendDepositTrade(partnerId, item, callback){
const offer = this.manager.createOffer(partnerId);
offer.addTheirItem(item);
offer.setMessage('Deposit item on the website!');
offer.send((err, status) => {
if (err) {
console.log("Error sending offer:", err);
callback(err, null);
} else {
console.log("Trade offer sent");
const tradelink = `https://steamcommunity.com/tradeoffer/${offer.id}`;
callback(null, tradelink);
}
});
}
getInventory() {
return new Promise((resolve, reject) => {
this.manager.getInventoryContents(730, 2, true, (err, inv) => {
if (err) {
reject(err);
} else {
resolve(inv);
}
});
});
}
getPartnerInventory(partnerId) {
return new Promise((resolve, reject) => {
this.manager.getUserInventoryContents(partnerId , 730, 2, true, (err, inv) => {
if (err) {
reject(err);
} else {
resolve(inv);
}
});
});
}
}
export default SteamBot;