-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
92 lines (83 loc) · 2.79 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
console.log('starting...')
require('./statics/uptimer')
const { Client, GatewayIntentBits } = require('discord.js');
const { exec } = require("child_process")
require('dotenv').config();
let process = require('process');
const config = require('./statics/config.json')
const syncSlash = require('@frostzzone/discord-sync-commands');
globalThis.imports = {
exec,
process,
Discord: require('discord.js'),
path: require('path'),
fs: require('fs'),
db: require('./statics/databaseClass.js'),
locateCategory(name, fields) {
for (let field = 0; field < fields.length; field++) {
if (fields[field].name == name) {
return field
}
}
},
getAllArgs: require('./statics/arguments parser'),
getRandomPost: require('musakui'),
client: new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildMessages
]
})
}
globalThis.dbs = { // databases
config: config,
database: imports.db,
commands: {},
commandConfig: config.commands
}
let slashCommands = []
console.log('\n')
imports.fs.readdir('./commands', async (err, files) => { // read commands folder into a list of commands
console.log(err ? err : 'reading commands with no error')
files.forEach(async file => {
let command = require('./commands/' + file)
if (command.slashCmd) {
console.log(`pushed ${command.comData.name} to slash command sync list`)
slashCommands.push(command.comData)
dbs.commands[command.comData.name] = {
description: command.comData.description,
path: '../commands/' + file,
isSlash: true
}
return
}
console.log(`loading command ${command.name}`)
dbs.commands[command.name] = {
description: command.sDesc,
category: command.category,
path: './commands/' + file
}
});
});
console.log('\n')
syncSlash(imports.client, slashCommands, { debug: true })
console.log('\n')
const eventsPath = imports.path.join(__dirname, 'events');
const eventFiles = imports.fs.readdirSync(eventsPath).filter(file => file.endsWith('.js'));
for (const file of eventFiles) { // add events via files
console.log(`applying event ${file}`)
const filePath = imports.path.join(eventsPath, file);
const event = require(filePath);
if (event.once) {
imports.client.once(event.name, async (...args) => event.execute(...args))
} else {
imports.client.on(event.name, async (...args) => event.execute(...args))
}
}
/* login */
imports.client.login(process.env.token);
globalThis.stop = () => {
imports.client.destroy();
imports.exec('kill 1');
}