-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
72 lines (67 loc) · 1.93 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
const Discord = require('discord.js')
const client = new Discord.Client()
const { prefix, token } = require('./config.json')
const models = require('./models')
const commands = require('./commands')
const mqtt = require('./services/mqtt')
client.once('ready', () => {
client.user.setActivity('!help')
console.log('Ready!')
});
client.on('message', async (message) => {
if (!message.content.startsWith(prefix) || message.author.bot) return;
const args = message.content.slice(prefix.length).split(' ');
const command = args.shift().toLowerCase();
// If the command was sent directly to the bot
if (message.channel.type === 'dm') {
if (command === `balance` || command === `bal`) {
commands.balance(args, message)
} else if (command === `deposit`) {
commands.deposit(args, message)
} else if (command === `withdraw`) {
commands.withdraw(args, message)
} else if (command === `help`) {
commands.help(args, message)
}
} else {
// The command was sent to the bot's channel
if (command === `tip`) {
commands.tip(args, message)
} else if (command === `tps`) {
commands.tps(args, message)
} else if (command === `tipsplit`) {
commands.tipsplit(args, message)
} else if (command === `tr` || command === `tiprandom`) {
commands.tipRandom(args, message)
}
}
})
const handleAppExit = (options, err) => {
if (err) {
console.log(err.stack)
}
if (options.cleanup) {
console.log('Cleaning up...')
mqtt.endClient()
}
if (options.exit) {
console.log('Calling exit...')
process.exit()
}
}
const configureSignals = () => {
process.on('exit', handleAppExit.bind(null, {
cleanup: true
}))
process.on('SIGINT', handleAppExit.bind(null, {
exit: true
}))
process.on('uncaughtException', handleAppExit.bind(null, {
exit: true
}))
}
models.sequelize.sync().then(() => {
configureSignals()
mqtt.connectMQTT()
client.login(token)
})