-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.mjs
111 lines (95 loc) · 2.14 KB
/
index.mjs
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
#!/usr/bin/env node
import inquirer from "inquirer";
import SteamUser from "steam-user";
class SimpleSteamApp {
constructor() {
this.client = new SteamUser();
this.client.on("loggedOn", () => console.log("Logged into Steam!"));
this.client.on("error", this.onError.bind(this));
this.client.on("disconnected", this.onDisconnected.bind(this));
this.client.on("accountInfo", this.onAccountInfo.bind(this));
this.client.on("steamGuard", this.onSteamGuard.bind(this));
}
logOn(accountName, password) {
this.client.logOn({
accountName,
password,
rememberPassword: true,
});
}
onError(e) {
console.log(e);
}
onDisconnected(eResult, msg) {
console.log(`Disconnected: ${msg}`);
}
onAccountInfo() {
console.log();
inquirer
.prompt([
{
type: "input",
name: "appid",
message: "AppID to get players for:",
validate: (input) => input.length > 0,
},
])
.then((result) => {
this.client.getPlayerCount(result.appid, (err, players) => {
if (err) {
console.error("Error:", err.message);
} else {
console.log("Players:", players);
}
this.onAccountInfo();
});
});
}
onSteamGuard(domain, callback) {
inquirer
.prompt([
{
type: "input",
name: "code",
message: domain ? `Steam guard code sent to ${domain}:` : "Steam app code:",
validate: (input) => input.length === 5,
},
])
.then((result) => callback(result.code));
}
init() {
process.on("SIGINT", () => {
this.shutdown(0);
});
const validate = (input) => input.length > 0;
inquirer
.prompt([
{
type: "input",
name: "username",
message: "Steam username:",
validate,
},
{
type: "password",
name: "password",
message: "Steam password:",
mask: "*",
validate,
},
])
.then((result) => this.logOn(result.username, result.password));
}
shutdown(code) {
console.log("Logging off and shutting down...");
this.client.logOff();
this.client.once("disconnected", () => {
process.exit(code);
});
setTimeout(() => {
process.exit(code);
}, 500);
}
}
const app = new SimpleSteamApp();
app.init();