-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathsetup.js
175 lines (144 loc) · 4.78 KB
/
setup.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
163
164
165
166
167
168
169
170
171
172
173
174
175
// ============================================================
//
// Setup bot.
// Created on Thu Jun 14 22:00:00 2018
// Author: Prasun Roy (https://github.com/prasunroy)
// GitHub: https://github.com/prasunroy/steam-bot
//
// ============================================================
// strict mode
'use strict';
// initialize
var SteamCommunity = require('steamcommunity');
var ReadLine = require('readline');
var fs = require('fs');
// create steam community object
var community = new SteamCommunity();
// create input output interface
var readline = ReadLine.createInterface({
input: process.stdin,
output: process.stdout
});
console.log('\nstarting setup..........\n');
// input steam account credentials
readline.question('Steam Username.........: ', function(accountName) {
readline.question('Steam Password.........: ', function(password) {
steamLogin(accountName, password);
});
});
// steam login
function steamLogin(accountName, password, steamguard, authCode, twoFactorCode, captcha) {
console.log('\nconnecting to steam.....');
community.login({
accountName: accountName,
password: password,
steamguard: steamguard,
authCode: authCode,
twoFactorCode: twoFactorCode,
captcha: captcha
},
function(error, sessionID, cookies, steamguard, oAuthToken) {
// login error
if(error)
{
// Steam guard mobile authenticator is already enabled.
if(error.message === 'SteamGuardMobile')
{
console.log('\nSteam Guard status.....: Steam Guard Mobile Authenticator already enabled');
console.log('\nsetup aborted');
process.exit();
return;
}
// Steam guard authentication code is sent to registered email. Enter the
// code and retry login.
else if(error.message === 'SteamGuard')
{
console.log('\nSteam Guard status.....: authentication code sent to registered email');
readline.question('Authentication code....: ', function(authCode) {
steamLogin(accountName, password, steamguard, authCode);
});
return;
}
// Steam guard authentication requires a captcha. Enter the captcha and
// retry login.
else if(error.message === 'CAPTCHA')
{
console.log('\nSteam Guard status.....: captcha required for authentication');
readline.question('Enter CAPTCHA..........: ', function(captcha) {
steamLogin(accountName, password, steamguard, authCode, twoFactorCode, captcha);
});
return;
}
console.log('\nsetup aborted\n');
console.log(error);
process.exit();
return;
}
// login successful
console.log('connected');
// enable steam guard mobile authenticator
community.enableTwoFactor(function(error, response) {
// error sending confirmation code
if(error)
{
console.log('\nsetup aborted\n');
console.log(error);
process.exit();
return;
}
// success sending confirmation code
sgmaActivate(accountName, password, response);
});
});
}
// activate steam guard mobile authenticator
function sgmaActivate(accountName, password, response) {
console.log('\nSteam Guard status.....: confirmation code sent to registered phone');
readline.question('Enter SMS code.........: ', function(activationCode) {
community.finalizeTwoFactor(response.shared_secret, activationCode, function(error) {
// confirmation error
if(error)
{
if(error.message === 'Invalid activation code')
{
console.log('Steam Guard status.....: invalid SMS code');
sgmaActivate(accountName, password, response);
return;
}
console.log('\nsetup aborted\n');
console.log(error);
process.exit();
return;
}
// confirmation successful
else
{
console.log('Steam Guard status.....: Steam Guard Mobile Authenticator enabled\n');
response.accountName = accountName;
response.password = password;
readline.question('Admin SteamID64........: ', function(admin) {
response.admin = admin;
// save configurations
console.log('\nsaving configurations...');
fs.writeFile('config.json', JSON.stringify(response, null, ' '), function(error) {
// save error
if(error)
{
console.log('failed');
console.log('\nWARNING: FOLLOWING SETUP CONFIGURATIONS MUST BE RETAINED MANUALLY\n');
console.log(response);
}
// save successful
else
{
console.log('saved');
}
console.log('\nsetup finished');
process.exit();
return;
});
});
}
});
});
}