-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapp.js
91 lines (69 loc) · 2.28 KB
/
app.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
let SteamBot = require('./steamBot');
let apiRequests = new (require('./apiRequests'));
let args = process.argv.slice(2);
let config;
if(args[0]) config = require('./config.'+args[0]+'.js');
else config = require('./config.js');
let accountCredentials = config.account;
let steamBot = new SteamBot(accountCredentials.login, accountCredentials.password, accountCredentials.shared_secret, accountCredentials.identity_secret, accountCredentials.apiKey);
let steamID = null;
let processedInv = null;
let numOfItems = null;
let globalItemsSold = 0;
steamBot.logOn((name, id) => {
console.log('Account ' + name + ' successfully logged in.')
steamID = id.getSteamID64();
steamBot.startTradeOffers(() => {
steamBot.loadMyInventory(config.gameCode ,(err, res) => {
if(err){
console.log(err);
process.exit();
}
processedInvRes = steamBot.processInventory(res);
processedInv = processedInvRes.inv;
numOfItems = processedInvRes.numOfItems;
console.log('There are ' + numOfItems + ' marketable items in inventory.');
console.log('Successfully downloaded and processed inventory.');
startSelling();
});
})
});
function getPrice(name){
return new Promise((resolve, reject) => {
apiRequests.getPrice(name,config.account.currencyCode, (err, price) =>{
if(err) reject(err);
resolve(price);
})
});
}
function sellItem(id, contextid, price){
return new Promise((resolve, reject) => {
apiRequests.sellItem(id, contextid, price, config.gameCode ,steamBot, steamID, (err) => {
if(err) reject(err);
resolve();
})
})
}
function sellTimeout(){
return new Promise(resolve => {
setTimeout(resolve, config.sellTimeout);
})
}
async function startSelling() {
for(name in processedInv){
await sellAllItems(name);
}
}
async function sellAllItems(name){
let price = await getPrice(name);
console.log(`Selling ${processedInv[name].length} of ${name} for ${price} each.`);
for(let i=0;i<processedInv[name].length;i++){
await sellItem(processedInv[name][i].assetid, processedInv[name][i].contextid, price).catch((err)=>{
console.log(`Couldln't sell one of ${processedInv[name]}. Reason : ${err}`);
});
globalItemsSold++;
console.log(i+1 + '/' + processedInv[name].length + ' (' + globalItemsSold + '/' + numOfItems + ')')
await sellTimeout();
}
return;
}