-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.js
83 lines (71 loc) · 2.12 KB
/
bot.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
const Eris = require('eris')
const Knex = require('knex')
const {
Agent
} = require('cyclone-engine')
const DBL = require('dblapi.js')
const knexConfig = require('./knexfile.js')
const commands = require('./src/data/commands/')
const {
routines
} = require('./src/data/util/')
const {
onMessage,
onGuildUpdate,
onGuildDelete,
onChannelUnavailable,
statusMessage
} = require('./src/data/listeners/')
const {
TOKEN,
DBL_TOKEN,
PREFIX
} = process.env
const knex = new Knex(knexConfig)
const permissionQuery = knex('guilds')
.select('id', 'adminrole')
.then((data) => data.reduce((acc, { id, adminrole }) => {
if (adminrole) {
acc[id] = {
permissions: {
[adminrole]: 1
}
}
}
return acc
}, {}))
const agent = new Agent({
Eris,
token: TOKEN,
handlerData: {
commands,
reactCommands: [],
options: {
prefix: PREFIX,
replacerBraces: {
open: '[',
close: ']'
}
}
},
options: {
intents: ['guildPresences'],
guildOptions: permissionQuery,
postEventFunctions: {
message: async (msg, res) => onMessage(agent.client, knex, msg, res, await agent.getTopPermissionLevel(msg.member))
},
statusMessage
}
})
const dbl = new DBL(DBL_TOKEN)
agent.attach('db', knex)
agent.attach('dbl', dbl)
for (const routine in routines) agent.attach(routine, routines[routine])
agent.client.on('guildUpdate', (guild, oldGuild) => onGuildUpdate(knex, guild, oldGuild))
agent.client.on('guildDelete', (guild) => onGuildDelete(agent.client, knex, guild))
agent.client.on('guildRoleUpdate', (guild) => onChannelUnavailable(agent.client, knex, guild))
agent.client.on('guildRoleCreate', (guild) => onChannelUnavailable(agent.client, knex, guild))
agent.client.on('guildRoleDelete', (guild) => onChannelUnavailable(agent.client, knex, guild))
agent.client.on('channelUpdate', (channel) => onChannelUnavailable(agent.client, knex, channel.guild))
agent.client.on('channelDelete', (channel) => onChannelUnavailable(agent.client, knex, channel.guild))
agent.connect().then(() => setTimeout(() => dbl.postStats(agent.client.guilds.size), 10000))