-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
68 lines (60 loc) · 1.75 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
const { Client } = require('discord.js')
const { RecurrenceRule, scheduleJob } = require('node-schedule')
const dotenv = require('dotenv')
dotenv.config()
const commandHandler = require('./handlers/commandHandler')
const reactionHandler = require('./handlers/reactionHandler')
const eventCleanup = require('./helpers/eventCleanup')
const everyMidnight = new RecurrenceRule()
everyMidnight.hour = 5
everyMidnight.minute = 1
const bot = new Client({ partials: ['MESSAGE', 'CHANNEL', 'REACTION'] })
require('http')
.createServer(async (req, res) => {
console.log('Received request')
res.statusCode = 200
res.write('ok')
res.end()
})
.listen(3000, () => console.log('Now listening on port 3000'))
bot.once('ready', () => {
bot.user.setPresence({
activity: {
name: 'user input',
type: 'LISTENING',
},
status: 'online',
})
scheduleJob(everyMidnight, async () => {
await eventCleanup.clearOldEvents()
})
})
bot.on('message', async (message) => {
if (message.author.bot || message.channel.type === 'dm') return
if (message.member.roles.cache.has(process.env.OFFICER_ROLE)) {
if (!message.content.startsWith('!') || message.author.bot) return
await commandHandler(message)
}
})
bot.on('messageReactionAdd', async (reaction, user) => {
if (user.bot) return
const startPattern = /^`(\w|\d)+_\d\d-\d\d-\d\d\d\d/
if (reaction.partial) {
try {
await reaction.fetch()
} catch (err) {
console.log('Could not fetch: ', err)
return
}
if (startPattern.test(reaction.message.content)) {
await reactionHandler(reaction, user)
reaction.users.remove(user.id)
}
} else {
if (startPattern.test(reaction.message.content)) {
await reactionHandler(reaction, user)
reaction.users.remove(user.id)
}
}
})
bot.login(process.env.TOKEN)