-
-
Notifications
You must be signed in to change notification settings - Fork 13
/
AllRunGame.js
105 lines (99 loc) · 3.78 KB
/
AllRunGame.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
const config = require('./config');
const Steam = require('steam');
const SteamTotp = require('steam-totp');
const SteamWebLogOn = require('steam-weblogon');
const request = require('./request');
const cheerio = require('cheerio');
Steam.servers = require('./steamServer');
var promiseList = [];
var appidToGame = 730;
for (let i = 0; i < config.length; i++) {
promiseList.push(startBot(i, appidToGame));
}
Promise.all(promiseList).then(() => {
console.log("all are running");
});
function startBot(index, appid)
{
return new Promise(function (resolve) {
var auth = config[index];
var steamClient = new Steam.SteamClient(),
steamUser = new Steam.SteamUser(steamClient),
steamFriends = new Steam.SteamFriends(steamClient),
steamWebLogOn = new SteamWebLogOn(steamClient, steamUser);
steamClient.connect();
steamClient.on('servers', function(server) {
});
console.log(auth.username);
steamClient.on('connected', function() {
steamUser.logOn({
account_name: auth.username,
password: auth.password,
two_factor_code: SteamTotp.getAuthCode(auth.sharedSecret)
});
});
steamClient.on('logOnResponse', function onSteamLogOn(logonResp) {
if (logonResp.eresult == Steam.EResult.OK) {
steamFriends.setPersonaState(Steam.EPersonaState.Busy);
steamUser.gamesPlayed([{ game_id: appid }]);
var interval = null;
websession(steamWebLogOn, steamClient, steamUser, function (_requestCommunity, _requestStore, sessionID) {
interval = setInterval(async function () {
try {
await EnsureWeAreDone(_requestStore);
//we are done.. and just exist account
SayBotIsDone();
clearInterval(interval);
steamClient.disconnect();
} catch (error) {
//keep goind
}
}, 1000 * 30) // check each 30 sec
});
SayBotIsLive();
resolve(steamClient);
}
});
steamClient.on('loggedOff', function onSteamLogOff(eresult) {
});
steamClient.on('error', function onSteamError(error) {
steamClient.connect();
});
});
}
var liveBots = 0;
function SayBotIsLive() {
liveBots = liveBots + 1;
console.log("running bots :" + liveBots + "/" + promiseList.length);
}
var botsDone = 0;
function SayBotIsDone() {
botsDone = botsDone + 1;
console.log("bots Done :" + botsDone + "/" + promiseList.length);
}
function websession(steamWebLogOn, steamClient, steamUser, callback) {
steamWebLogOn.webLogOn(function(sessionID, newCookie) {
var _requestCommunity = new request('https://steamcommunity.com');
var _requestStore = new request('https://store.steampowered.com');
newCookie.forEach(function(name) {
_requestCommunity.setCookie(name);
_requestStore.setCookie(name);
});
callback(_requestCommunity, _requestStore, sessionID);
});
}
function EnsureWeAreDone(_requestStore) {
return new Promise(function (resolve, reject) {
_requestStore.get('https://store.steampowered.com/steamawards/nominations', function (error, response, body) {
var $ = cheerio.load(body);
var onlyLookAtPlayGameAndReviewTaskStatus = $($(".badge_tasks_right")[0]).find(".badge_task");
if(onlyLookAtPlayGameAndReviewTaskStatus[0] && $(onlyLookAtPlayGameAndReviewTaskStatus[0]).find(".nominate_check").length){
resolve();
return;
}else{
reject();
return;
}
});
});
}