This repository has been archived by the owner on Aug 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathupdate.js
58 lines (51 loc) · 1.67 KB
/
update.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
process.emitWarning = function(warning, type) {
if (type !== 'DeprecationWarning') {
console.warn(warning);
}
};
require("./starter");
const fs = require('fs');
const EventEmitter = require('events');
const eventEmitter = new EventEmitter();
const bot = require('./handler/login.js');
let log = global.log;
const token = global.config.BOT['token'];
if (!token) {
eventEmitter.emit('critical_error', "Token Not Provided");
}
if (!global.cmds) global.cmds = new Map();
try {
require("./script/command_loader");
} catch (error) {
eventEmitter.emit('critical_error', "Failed to load Command Loader: " + error.message);
}
let commandFiles = [];
try {
commandFiles = fs.readdirSync("script/commands").filter(file => file.endsWith(".js"));
} catch (error) {
eventEmitter.emit('critical_error', "Failed to read command files: " + error.message);
}
const commandsArray = commandFiles.map(file => {
try {
const command = require(`./script/commands/${file}`);
if (global.cmds.has(file)) {
const { name, description } = command.config;
if (!name) return
return {
command: name,
description: description?.short || description?.long || (typeof description === 'string' ? description : 'Not Available')
};
} else {
log(`Command ${file} is not registered in global.cmds`, 'yellow', false);
return null;
}
} catch (error) {
log(`Exception while loading ${file} : ${error.message}`)
}
}).filter(cmd => cmd !== null);
bot.setMyCommands(commandsArray).then(() => {
log("Updated", "green", true);
process.exit(0)
}).catch(error => {
eventEmitter.emit('critical_error', "Failed to set Commands: " + error.message);
});