-
Notifications
You must be signed in to change notification settings - Fork 0
/
steam_test.js
182 lines (163 loc) · 8.28 KB
/
steam_test.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
176
177
178
179
180
181
182
const steamUser = require("steam-user");
const axios = require("axios");
const {Client, Intents, MessageEmbed} = require("discord.js")
const fs = require('fs');
const path = require('path');
let client = new steamUser();
const discClient = new Client({
intents: [Intents.FLAGS.GUILD_MESSAGES, Intents.FLAGS.GUILD_MESSAGE_TYPING]
})
client.setOptions({enablePicsCache: true, picsCacheAll: true, changelistUpdateInterval: 10000});
let config;
let configPath = path.join(__dirname, 'config.json');
fs.readFile(configPath, 'utf8', function (err, data) {
if (err) {
return console.log(err);
}
config = JSON.parse(data);
let steamCredentials;
if (config.steamKey) {
steamCredentials = {
accountName: config.steamUser, password: config.steamPass, loginKey: config.steamKey, rememberPassword: true
}
} else {
steamCredentials = {
accountName: config.steamUser, password: config.steamPass, rememberPassword: true
}
}
client.logOn(steamCredentials);
discClient.login(config.discord)
.then(() => {
console.info('[DISCORD] -> logged in as ' + discClient.user.tag);
})
}
)
;
discClient.on('ready', () => discClient.channels.fetch('954115013503750194').then(c => c.send('Bot online')))
let g_sessionID;
client.on('webSession', function (sessionID, cookies) {
g_sessionID = sessionID;
axios.defaults.headers.Cookie = cookies
console.log("Session: ", sessionID);
});
client.on('loggedOn', () => {
console.log(`[STEAM] -> ${client.vanityURL} (${client.steamID.getSteamID64()}, ${client.steamID.getSteam2RenderedID()}, ${client.steamID.getSteam3RenderedID()})`);
});
client.on('loginKey', function (key) {
console.log("loginKey: ", key);
config.steamKey = key;
fs.writeFile('config.json', JSON.stringify(config), {flag: 'w'}, err => {
})
});
client.once('changelist', function (changeNumber) {
let lastChangeNumber;
fs.readFile('config.json', 'utf8', function (err, data) {
if (err) {
return console.log(err);
} else {
lastChangeNumber = parseInt(JSON.parse(data).changeNumber);
console.log(lastChangeNumber)
lastChangeNumber = Math.max(lastChangeNumber, changeNumber - 5000)
console.log(lastChangeNumber)
}
client.getProductChanges(lastChangeNumber).then((result) => {
fetchChanges(result.currentChangeNumber, result.appChanges, result.packageChanges)
})
})
})
client.on('changelist', function (changeNumber, changeApps, changePackages) {
config.changeNumber = changeNumber;
fs.writeFile('config.json', JSON.stringify(config), err => {
})
console.log(`-- Change - NEW: ${changeNumber}`);
fetchChanges(changeNumber, changeApps, changePackages)
});
function fetchChanges(changeNumber, changeApps, changePackages) {
client.getProductInfo(changeApps, changePackages).then(result => {
let apps = result.apps;
//let out = [`*Changelist - <https://steamdb.info/changelist/${changeNumber}> (${changeApps.length} apps and ${changePackages.length} packages)`];
console.log(`*Changelist - <https://steamdb.info/changelist/${changeNumber}> (${changeApps.length} apps and ${changePackages.length} packages)`);
let beta = []
if (apps && Object.keys(apps).length) {
for (let app of Object.keys(apps)) {
let title = apps[app].appinfo.common ? (apps[app].appinfo.common.name || 'Unknown') : 'Unknown App';
//out.push(` - App: <https://steamdb.info/app/${app}> - ${title}`);
if (!(apps[app].appinfo === undefined) && !(apps[app].appinfo.extended === undefined) && !(apps[app].appinfo.extended.betaforappid === undefined)) {
let parent = apps[app].appinfo.extended.betaforappid;
beta.push(`${app}, ${title} - beta for ${parent}`);
const embed = new MessageEmbed()
.addFields(
{
name: `${title} (${app})`,
value: `Parent: ${parent}\nRelease Date: <t:${apps[app].appinfo.common.steam_release_date}:D>`
})
axios.get(`https://store.steampowered.com/app/${parent}`).then(resp => {
let active = resp.data.indexOf('RequestPlaytestAccess') > 0;
embed.addField('Store Button: ', `${"Yes" ? active : "No"}`)
console.log(client.ownsApp(app), app in client.picsCache.apps)
if (active && !client.ownsApp(app)) {
requestPlaytest(app, parent, title, embed);
} else if (client.ownsApp(app)) {
embed.addField('Owned', '\u200B', true)
}
let image;
if (apps[app].appinfo.common.small_capsule) {
image = `http://cdn.akamai.steamstatic.com/steam/apps/${app}/${apps[app].appinfo.common.small_capsule.english}`
} else {
image = `https://cdn.cloudflare.steamstatic.com/steamcommunity/public/images/apps/${app}/${apps[app].appinfo.common.logo}.jpg`
}
let icon = `https://cdn.cloudflare.steamstatic.com/steamcommunity/public/images/apps/${app}/${apps[app].appinfo.common.icon}.jpg`
embed.setThumbnail(image)
embed.addField('Links: ', `[Store](https://store.steampowered.com/app/${app}) | [SteamDB - parent](https://steamdb.info/app/${parent}) | [SteamDB - app](https://steamdb.info/app/${app})`)
discClient.channels.cache.get('954115013503750194').fetchWebhooks()
.then(webhook => webhook.first().send({
username: title,
avatarURL: icon,
embeds: [embed],
}))
});
}
}
}
// if (result.packages && Object.keys(result.packages).length) {
// for (let pack of Object.keys(result.packages)) {
// out.push(` - package: <https://steamdb.info/sub/${pack}> - ${result.packages[pack].packageinfo ? (result.packages[pack].packageinfo.name || 'Unknown') : 'Unknown App'}`);
// }
// }
//
// if ((result.unknownApps && result.unknownApps.length) || (result.unknownPackages && result.unknownPackages.length)) {
// out.push(`${result.unknownApps.length} Unknown Apps and ${result.unknownPackages.length} Unknown Packages`);
// }
//console.log(out.join('\n'));
console.log(beta.join('\n'));
});
}
function requestPlaytest(app, parent, title, embed) {
console.log('Store Button: ', 'Active')
axios.post('https://store.steampowered.com/ajaxrequestplaytestaccess/' + parent, `sessionid=${g_sessionID}`, {
validateStatus: (status) => {
return (status >= 200 && status < 400 || status === 401);
}
})
.then(function (response) {
let responseText = response.data
let granted;
let success;
if (!responseText === false) {
granted = responseText.granted;
success = responseText.success;
}
if (granted === 1) {
console.log(`New playtest requested (${app}) : \n\t${title} \n\tparent: ${parent}\n\t=> Instant Access`);
embed.addField('New playtest requested', 'Instant Access', true)
} else if (granted === null) {
console.log(`New playtest requested (${app}): \n\t${title} \n\tparent: ${parent}\n\t=> Requested Access`);
embed.addField('New playtest requested', 'Requested Access', true)
} else if (!success || success !== 1) {
console.warn(`FAILED playtest request (${app}): \n\t${title} \n\tparent: ${parent}\n\t=> response : ${responseText} - (${response.status}: ${response.statusText})`);
}
})
.catch(function (error) {
console.warn(error);
});
}