-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.js
121 lines (93 loc) · 2.73 KB
/
index.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
const SteamUser = require('steam-user');
const SteamTotp = require('steam-totp')
const GlobalOffensive = require('globaloffensive');
const FileSystem = require("fs");
const config = require('./config');
let user = new SteamUser();
let csgo = new GlobalOffensive(user);
function quit() {
user.gamesPlayed([]);
user.logOff();
user.on('disconnected', () => {
process.exit(1);
});
};
const logInOptions = {
accountName: config.accountName,
password: config.password,
twoFactorCode: SteamTotp.generateAuthCode(config.sharedSecret)
};
user.logOn(logInOptions);
user.on('loggedOn', () => {
user.on('accountInfo', (username) => {
console.log("Logged into Steam as " + username);
});
user.setPersona(SteamUser.EPersonaState.Online);
user.gamesPlayed([730]);
});
csgo.on('disconnectedFromGC', (reason) => {
if (reason == GlobalOffensive.GCConnectionStatus.GC_GOING_DOWN) {
console.log('GC going down');
}
});
function sleep(millis) {
return new Promise(resolve => setTimeout(resolve, millis));
}
function add_to_casket() {
let inventory = csgo.inventory;
let currentTime = new Date().getTime();
let cnt = 0;
console.log(inventory.length);
const regex = /(?<=\), )0\.\d+(?=,)/g;
const purchase_data = FileSystem.readFileSync(config.file_path, 'utf8').trim().split('\n').splice(-500);
for (var i=0; i<purchase_data.length; i++) purchase_data[i] = parseFloat(purchase_data[i].match(regex)[0]);
for (const item of inventory)
{
if(cnt > 49) break;
if(currentTime < new Date(item['tradable_after']).getTime() && purchase_data.includes(item['paint_wear']) && !item.hasOwnProperty('casket_id'))
{
csgo.addToCasket(config.casket_id, item['id']);
cnt++;
}
}
console.log(`${inventory.length}, added ${cnt} items to storage units`);
return cnt;
}
function remove_from_casket() {
var cnt = 0;
csgo.getCasketContents(config.casket_id, function(err, items) {
if (err) throw err;
let currentTime = new Date().getTime();
// let cnt = 0;
console.log(items.length);
for (const item of items) {
if(cnt > 49) break;
if(currentTime > new Date(item['tradable_after']).getTime())
{
csgo.removeFromCasket(config.casket_id, item['id']);
cnt++;
}
}
console.log(`${items.length}, removed ${cnt} items from storage units`);
});
return cnt;
}
function do_stuff() {
let a = add_to_casket();
let b = remove_from_casket();
console.log(a+b);
return a+b;
}
csgo.on('connectedToGC', () => {
console.log('Connected to GC!');
if(csgo.haveGCSession) {
console.log('Have Session!');
var cnt = 1;
setInterval(function() {
cnt = do_stuff();
if (cnt == 0) {
quit();
}
}, 3000);
};
});