-
Notifications
You must be signed in to change notification settings - Fork 6
/
index.js
70 lines (61 loc) · 2.35 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
require('dotenv').config();
const Race = require('./models/race');
const AudioPlayer = require('./models/audioPlayer');
const fs = require('fs');
const config = require('./config.json');
const { Client, Events, Collection, GatewayIntentBits } = require('discord.js');
const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.GuildVoiceStates]});
client.commands = new Collection();
client.buttons = new Collection();
const readline = require('readline');
var race = null;
var audioPlayer = null;
const eventFiles = fs.readdirSync('./events').filter(file => file.endsWith('.js'));
for (const file of eventFiles) {
const event = require(`./events/${file}`);
if (event.once) {
client.once(event.name, (...args) => event.execute(...args, client, race));
} else {
client.on(event.name, (...args) => event.execute(...args, client, race));
}
}
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const command = require(`./commands/${file}`);
client.commands.set(command.data.name, command);
}
const buttonFiles = fs.readdirSync('./buttons').filter(file => file.endsWith('.js'));
for (const file of buttonFiles) {
const button = require(`./buttons/${file}`);
client.buttons.set(button.name, button);
}
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
const cliFiles = fs.readdirSync('./cli').filter(file => file.endsWith('.js'));
rl.on('line', (input) => {
for (const file of cliFiles) {
const command = require(`./cli/${file}`);
if (input.startsWith(command.name)) {
if (input.includes("-h") || input.includes("-help")) {
console.log(command.description);
} else {
command.execute(client, race, input);
break;
}
}
}
});
client.once(Events.ClientReady, c => {
console.log(`Ready! Logged in as ${c.user.tag} \n`);
audioPlayer = new AudioPlayer(client);
race = new Race(client, audioPlayer);
console.log('CLI commands:');
for (const file of cliFiles) {
const command = require(`./cli/${file}`);
console.log(command.name);
console.log('\x1b[36m%s\x1b[0m', " " + command.description);
}
});
client.login(process.env.BOT_TOKEN);