-
Notifications
You must be signed in to change notification settings - Fork 9
/
index.js
47 lines (41 loc) · 1.32 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
import dinoBadge from './dinoBadge'
import scheduleCheckin from './scheduleCheckin'
import updateBreakouts from './updateBreakouts'
import { initBot, reaction } from '../../utils'
const getAdmin = (bot, user) =>
new Promise((resolve, reject) => {
bot.api.users.info({ user }, (err, res) => {
if (err) {
console.error(err)
reject(err)
}
resolve(res.user.is_admin)
})
})
const triggerInteraction = (bot = initBot(), message) => {
const { ts, channel, user, text } = message
const dryRun = !text.includes('thump thump')
getAdmin(bot, user)
.then(admin => {
if (!admin) {
reaction(bot, 'add', channel, ts, 'broken_heart')
throw new Error('user_not_leader')
}
console.log(
'I can hear my heart beat in my chest... it fills me with determination'
)
reaction(bot,'add', channel, ts, 'heartbeat')
return Promise.all([
// We're forcing dryrun to true on schedule checkin while the pandemic
// is closing clubs
// scheduleCheckin(bot, message, /*dryRun*/ true),
// dinoBadge(bot, message, /*dryRun*/ true),
updateBreakouts(bot, message, dryRun),
])
})
.catch(err => {
console.error(err)
bot.whisper(message, `Got error: \`${err}\``)
})
}
export default triggerInteraction