This repository has been archived by the owner on Aug 20, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
/
index.js
75 lines (67 loc) · 1.86 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
/*
* Gabe Dunn 2018
* Main file that calls all other files and specifies actions.
*/
import { AkairoClient } from 'discord-akairo'
import { join } from 'path'
import { botToken, ownerID, prefix, statusInterval } from './src/config'
import activities from './src/activities'
import { roleAdd, roleRm } from './src/reactionRoles'
import { migrate } from './src/utils'
const client = new AkairoClient({
ownerID,
prefix,
allowMention: true,
handleEdits: true,
commandUtil: true,
commandUtilLifetime: 600000,
commandDirectory: join(__dirname, 'src', 'commands')
})
const run = async () => {
try {
await client.login(botToken)
console.log(`Logged in as ${client.user.tag}.`)
client.user.setActivity('.help')
setInterval(async () => {
const activity = activities[Math.floor(Math.random() * activities.length)]
const newActivity = await client.user.setActivity(activity)
setTimeout(async () => {
await client.user.setActivity('.help')
}, 60000)
}, statusInterval * 60000)
client.on('raw', async event => {
try {
const { d: data } = event
if (event.t === 'MESSAGE_REACTION_ADD') {
roleAdd(
client,
data.guild_id,
data.message_id,
data.user_id,
data.emoji.name
)
} else if (event.t === 'MESSAGE_REACTION_REMOVE') {
roleRm(
client,
data.guild_id,
data.message_id,
data.user_id,
data.emoji.name
)
}
} catch (e) {
console.log(`Error handling reaction: ${e}`)
}
})
// Create schema
await migrate()
} catch (e) {
console.log(`Error running bot: ${e}`)
}
}
run()
process.on('uncaughtException', (e, p) => {
console.log(`Uncaught Exception: ${e} && ${p}`)
client.destroy()
process.exit(1)
})