-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
162 lines (143 loc) · 5.98 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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
var request = require('request')
, cheerio = require('cheerio')
, async = require('async')
, steam = require("steam")
, util = require("util")
, fs = require("fs")
, bot = new steam.SteamClient(); //WHERE THE MAGIC HAPPENS FOR NOW
global.config = require("./config");
var onSteamLogOn = function onSteamLogOn() {
bot.setPersonaState(steam.EPersonaState.Busy); // to display your bot's status as "Online"
bot.setPersonaName(config.steam_name); // to change its nickname
util.log("Logged on.");
var game_to_idle = 0;
var url = config.badge_url;
var j = request.jar();
var getCookie = function (callback) {
bot.webLogOn(function (cookie) {
util.log("Grabbing new cookie.");
//util.log(cookie);
var cookie_string_split = cookie.toString().split(',');
cookie_string_split.every(function (value) {
//util.log(value);
j.setCookie(request.cookie(value), url);
return 1;
});
callback();
});
};
var findGameToIdle = function (callback) {
var numGamesFound = 0;
//var gameToIdleTemp = game_to_idle;
//util.log('Re-enumerating remaining drops');
request({url: url, jar: j}, function (err, response, body) {
game_to_idle = 0;
//if (err) throw err;
if (err) {
util.log('Problem grabbing card status.');
callback(game_to_idle);
}
else {
//fs.writeFileSync('test.html', body); //SO WE CAN SEE WHAT IT SEES
var doBadgeProfileReq = function (callback2) {
var $ = cheerio.load(body);
$('span.progress_info_bold').each(function () {
if (($(this).text() !== 'undefined')
&& ($(this).text() !== null)
&& ($(this).text().indexOf("task") == -1)
&& ($(this).text() != 'No card drops remaining')) {
numGamesFound++;
//var num_drops = $(this).text().replace(' card drops remaining', '');
if (numGamesFound == 1) {
game_to_idle = $(this).prev().parent().children('div.badge_title_playgame').children('a.btn_green_white_innerfade').attr('href').replace('steam://run/', '');
//util.log(game_to_idle + ' || ' + num_drops);
}
}
});
callback2();
};
doBadgeProfileReq(function () {
callback(game_to_idle);
});
}
});
};
var gameToIdle_index = 0;
var numTimesNoGame = 0;
function cardIdleMain() {
findGameToIdle(function (gameToIdle) {
//util.log('Finished poll');
if (gameToIdle != gameToIdle_index) {
if (gameToIdle == 0) {
if (numTimesNoGame > 12) {
bot.gamesPlayed([gameToIdle]);
util.log('No game to idle for ' + ((config.badge_check_idle * numTimesNoGame) / 60000) + 'mins');
}
else {
util.log('No game to idle.');
}
//util.log('Getting a new cookie and waiting until next check. Attempt: ' + numTimesNoGame);
numTimesNoGame++;
getCookie(function () {
util.log('Cookie set.');
});
}
else {
gameToIdle_index = gameToIdle;
util.log('Changing idle game to: ' + gameToIdle);
bot.gamesPlayed([gameToIdle]);
numTimesNoGame = 0;
}
}
else if (numTimesNoGame > 12) {
util.log('Changing idle game to: ' + gameToIdle);
bot.gamesPlayed([gameToIdle]);
numTimesNoGame = 0;
}
else {
util.log('Still idling: ' + gameToIdle);
}
});
}
getCookie(function () {
util.log('Cookie set.');
cardIdleMain();
});
setInterval(function () {
cardIdleMain();
}, config.badge_check_idle);
},
onSteamSentry = function onSteamSentry(sentry) {
util.log("Received sentry.");
require('fs').writeFileSync('sentry', sentry);
},
onSteamServers = function onSteamServers(servers) {
util.log("Received servers.");
fs.writeFile('servers', JSON.stringify(servers));
};
//,onWebSessionID = function onWebSessionID(webSessionID) {
//util.log("Received web session id.");
// steamTrade.sessionID = webSessionID;
/*bot.webLogOn(function onWebLogonSetTradeCookies(cookies) {
util.log("Received cookies.");
util.log(cookies);
fs.writeFileSync('cookie.txt', cookies);
//for (var i = 0; i < cookies.length; i++) {
// steamTrade.setCookie(cookies[i]);
//util.log(i+" | "+cookies[i]);
//}
});*/
//};
// Login, only passing authCode if it exists
var logOnDetails = {
"accountName": config.steam_user,
"password": config.steam_pass
};
if (config.steam_guard_code) logOnDetails.authCode = config.steam_guard_code;
var sentry = fs.readFileSync('sentry');
if (sentry.length) logOnDetails.shaSentryfile = sentry;
bot.logOn(logOnDetails);
bot.on("loggedOn", onSteamLogOn)
.on('sentry', onSteamSentry)
.on('servers', onSteamServers);
// .on('webSessionID', onWebSessionID);