-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathindex.js
106 lines (91 loc) · 4.98 KB
/
index.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
const { Util: { mergeDefault } } = require('discord.js');
const JSON5 = require('json5');
async function init() {
// Requires
const Constants = require('./lib/Constants');
const Dashboard = require('./lib/Dashboard');
const Webhook = require('./lib/Webhook');
const Logger = require('./lib/Logger');
const modes = require('./modes/index');
const Util = require('./lib/Util');
const chalk = require('chalk');
const phin = require('phin');
// Call dotenv to recognize env vars
require('dotenv').config({
multiline: 'line-breaks',
path: 'settings.env'
});
console.log(chalk.green(`
╓╖,
g▄▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▄╬╣╣╣╢╬N╖
▐▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓╣╣╣╣╣╣╣╣╣╢╣╣@,
▀▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓╣╣╣╣╣╣╣╢╢╣╣╣╣╣@,
╙▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓╣╣╣╣╣╣╢╣╣╣╣╣╣╣╣╣╣W
g▓▓▓▓▓▓╢▓▓▓▓╩╨╨╩╬╣╢╣╢╣▒╣╣╣╣╣╣╣╣╣╣╣╣
Æ▓▓▓▓⌐ ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓╢▓▓╝⌠░░░░░░░░░░╙╨╣╣╣╣╣╣╣╣╣╣╣╣╣╣╣
╙▀▓▓▀ ╙▀▓▓▓▓▓▓▓▓▓▓▓▓▓▓╢▓▓╩░░░░░░░░░░░░░░░░╙╣╣╣╣╣╣╣╣╣╣╣╣╣@
▓▓▓▓╢▓▓░░░░░╓╢▒▒▒▒▒▒╢░░░░░╙╣╣╣╣╣╣╣╣╣╣╣╣╢
g▄▄▄▄▄▓▓▓▓▓▓Ñ░░░░║▒▒▒▒▒▒▒▒▒▒╖░░░░║╣╣╣╣╣╣╣╣╣╣╣╣⌐
▓▓▓▓▓▓▓▓▓▓▓▓▓░░░░║▒▒▒▒▒▒▒▒▒▒▒▒▒░░░]╣╣╣╣╣╣╣╣╣╣╣╣⌐
╙╙▐▓▓▓▓▓▓▓▓▓@░░░░╙▒▒▒▒▒▒▒▒▒▒╜░░░░║╣╣╣╣╣╣╣╣╣╣╣╣
▓▓▓▓▓▓▓╣▓▓░░░░░╙▒▒▒▒▒▒▒▒░░░░░╓╣╣╣╣╣╣╣╣╣╣╣╣Ñ
╚▓▓▓▓▓▓▓▓▓▓@░░░░░░░░░░░░░░░░░░░╢╣╣╣╣╣╣╣╣╣╣
▐▓▓▓▓▓▓▓▓╢▓▓@µ░░░░░░░░░░╓@░░░░░░╙╣╣╣╣╣╣╢\`
╙▓▓▓▓▓▓▓▓▓▓╢▓▓▓▓@@@@▓▓▓▓╢▓▄░░░░░░░╜╨╣╢░
▀▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▄░░░░░░░▒
▀▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓╜\"░▒░\"
▀▀▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▀╩
╙╙▀▀▀▓▓▓▓▀▀▀╙╙
`));
// Define globals
global.active = [];
global.webhook = null;
global.constants = Constants;
global.util = Util;
global.logger = new Logger({ debug: false });
global.dashboard = new Dashboard();
global.paymentSourceId = null;
// Try to parse settings
try {
global.settings = JSON5.parse(process.env.settings);
} catch {
return logger.critical(constants.invalidConfig);
}
// Define settings with defaults
global.settings = mergeDefault(constants.defaultSettings, settings);
if (!settings.mode) return logger.critical(constants.noMode);
if (!Object.keys(modes).includes(settings.mode)) return logger.critical(constants.invalidMode);
// Init selected mode
await modes[settings.mode]();
if (!active.length) return logger.critical(constants.invalidTokens);
// Counters
const guildCount = active
.map((s) => s.guilds.cache.size)
.reduce((a, b) => a + b, 0);
// Get payment method
const res = await phin({
url: constants.paymentSourceURL,
method: 'GET',
parse: 'json',
headers: {
'Authorization': settings.tokens.main,
'User-Agent': constants.userAgent
}
});
if (!res.body?.length) {
logger.warn(constants.noPaymentMethod);
} else if (res.body[0]) {
const method = res.body.find?.(p => p.default)?.id;
global.paymentSourceId = method;
} else {
logger.warn(constants.paymentMethodFail(res.body));
}
// Init webhook
if (settings.webhook?.url) {
const webhookToken = /[^/]*$/.exec(settings.webhook.url)[0];
const webhookId = settings.webhook.url.replace(/^.*\/(?=[^\/]*\/[^\/]*$)|\/[^\/]*$/g, '');
global.webhook = new Webhook(webhookId, webhookToken);
}
return logger.success(constants.ready(active.length, guildCount));
}
init();