-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
45 lines (39 loc) · 1.34 KB
/
index.js
File metadata and controls
45 lines (39 loc) · 1.34 KB
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
require('dotenv').config();
require('./keep_alive.js');
const { WebhookClient } = require('discord.js');
const mongoose = require('mongoose');
const path = require('path');
const utils = require(path.join(__dirname, 'utils'));
const steamclient = require(path.join(__dirname, 'steamclient')).buildBot;
mongoose.connect(process.env.mongodbUri);
const webhookClient = new WebhookClient({ url: process.env.webhook });
const max = parseInt(process.env.max, 10);
const games = JSON.parse(process.env.games);
const bots = [];
const account = mongoose.model('settings', {
refreshToken: String,
steamID: String,
accountName: String
});
const files = mongoose.model('files', {
filename: String,
content: String
});
(async () => {
const acc = await account.find({});
webhookClient.send({
content: 'Загружаю настроенных конфигураций: ' + Math.max(acc.length, max)
});
for (let i = 0; i < Math.max(acc.length, max); i++) {
if (acc[i]?.refreshToken && !utils.getExpiration(acc[i].refreshToken).expired) {
bots.push(await steamclient(acc[i], games[i], files, webhookClient));
} else {
newAcc = await utils.startWithQR(webhookClient);
acc[i] = await account.findOneAndUpdate({ accountName: newAcc.accountName }, newAcc, {
new: true,
upsert: true
});
i--;
}
}
})();