-
Notifications
You must be signed in to change notification settings - Fork 5
/
startup.js
96 lines (93 loc) · 3.64 KB
/
startup.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
const fs = require('fs');
const { Collection } = require('discord.js');
const db = require('quick.db');
const chalk = require('chalk');
const start_giveaway = require('./giveaway.js');
module.exports = async (client) => {
// Start custom functions
console.stdlog = console.log.bind(console);
console.logs = [];
console.log = function() {
console.logs.push(Array.from(arguments));
console.stdlog.apply(console, arguments);
fs.writeFile('bot.log', console.logs.join('\n'), (err) => {
// In case of a error throw err.
if (err) throw err;
});
};
Collection.prototype.array = function() {
return [...this.values()];
};
client.queue = new Collection();
const commandFolders = fs.readdirSync('./commands');
const events = fs.readdirSync('./events');
const categories = new Collection();
const startCommandsMS = new Date().getTime();
let commandColor;
let eventColor;
let slashCommandsColor;
let totalColor;
for (const categoryName of commandFolders) {
const categoryCmds = new Collection();
const commandFiles = fs.readdirSync(`./commands/${categoryName}`).filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
console.log('Loading command %s (%s)', file, categoryName);
const command = require(`./commands/${categoryName}/${file}`);
client.commands.set(command.name, command);
categoryCmds.set(command.name, command);
}
categories.set(categoryName, categoryCmds);
}
const endCommandsMS = new Date().getTime();
const timeCommandsMS = endCommandsMS - startCommandsMS;
const startEventsMS = new Date().getTime();
for (const eventName of events) {
console.log('Loading event %s', eventName, '(event)');
}
const endEventsMS = new Date().getTime();
const timeEventsMS = endEventsMS - startEventsMS;
const timeSlashCommandsMS = db.get('_slashCommandsMS');
const totalBootTime = (timeSlashCommandsMS + timeCommandsMS + timeEventsMS);
if (timeCommandsMS <= 10000) {
commandColor = chalk.greenBright;
} else if (timeCommandsMS >= 10000 && timeCommandsMS <= 30000) {
commandColor = chalk.yellowBright;
} else if (timeCommandsMS >= 30000) {
commandColor = chalk.redBright;
}
if (timeEventsMS <= 10000) {
eventColor = chalk.greenBright;
} else if (timeEventsMS >= 10000 && timeEventsMS <= 30000) {
eventColor = chalk.yellowBright;
} else if (timeEventsMS >= 30000) {
eventColor = chalk.redBright;
}
if (timeSlashCommandsMS <= 10000) {
slashCommandsColor = chalk.greenBright;
} else if (timeSlashCommandsMS >= 10000 && timeSlashCommandsMS <= 30000) {
slashCommandsColor = chalk.yellowBright;
} else if (timeSlashCommandsMS >= 30000) {
slashCommandsColor = chalk.redBright;
}
if (totalBootTime <= 20500) {
totalColor = chalk.greenBright;
} else if (totalBootTime >= 20500 && totalBootTime <= 40000) {
totalColor = chalk.yellowBright;
} else if (totalBootTime >= 40000) {
totalColor = chalk.redBright;
}
client.commands.forEach(command => {
const category = categories.get(command.category) ?? new Collection();
if (category) {
category.set(command.name, command);
} else {
categories.set(command.category, new Collection().set(command.name, command));
}
});
start_giveaway(client);
console.log(chalk.blue('Startup Measurement Results\n-------------------------------'));
console.log(timeSlashCommandsMS ? slashCommandsColor('(/) Command deploying time:', timeSlashCommandsMS + 'ms') : chalk.grey('Could not get (/) command loading time.'));
console.log(commandColor('Command loading time:', timeCommandsMS + 'ms'));
console.log(eventColor('Event loading time:', timeEventsMS + 'ms'));
console.log(totalColor('Total boot time:', (timeCommandsMS + timeEventsMS + timeSlashCommandsMS) + 'ms'));
};