-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
59 lines (48 loc) · 1.62 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
const Discord = require('discord.js')
const Enmap = require('enmap')
const path = require('path')
const fs = require('fs')
const client = new Discord.Client()
const { BOT_TOKEN: token, BOT_OWNERID: owner } = process.env
const defaultSettings = require('./default-settings.json')
const defaultCmdMeta = require('./default-command.json')
client.logger = require('./logger')
client.config = { token, owner, defaultSettings }
client.settings = new Enmap({ name: 'settings' })
client.commands = new Enmap()
client.aliases = new Enmap()
const evtFiles = fs.readdirSync(path.resolve(__dirname, 'events/'))
for (let file of evtFiles) {
if (!file.endsWith('.js')) continue
const evtCall = require(`./events/${file}`)
const evtName = file.split('.')[0]
client.logger.log(`registering event : ${evtName}`)
client.on(evtName, evtCall.bind(null, client))
}
const cmdFiles = fs.readdirSync(path.resolve(__dirname, 'commands/'))
for (let file of cmdFiles) {
if (!file.endsWith('.js')) continue
let cmdData = require(`./commands/${file}`)
cmdData.meta = {
...defaultCmdMeta,
name: file.split('.')[0],
...cmdData.meta
}
let cmdName = cmdData.meta.name
cmdData.meta.aliases.forEach((alias) => {
client.aliases.set(alias, cmdName)
})
client.logger.log(`loading command : ${cmdName}`)
client.commands.set(cmdName, cmdData)
}
require('./chatter')(client, (err) => {
if (err) return client.logger.err(err.message || err)
client.login(client.config.token)
})
process.once('SIGINT', () => {
client.logger.log('killing', 'sigint')
client.destroy()
if (client.chatter) {
client.chatter.dataStream.close()
}
})