-
Notifications
You must be signed in to change notification settings - Fork 9
/
leaderList.js
52 lines (47 loc) · 1.37 KB
/
leaderList.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
import { getInfoForUser, airGet, transcript } from '../utils'
const interactionLeaderList = (bot, message) => {
const { channel, user } = message
getInfoForUser(user)
.then(({ leader, club }) => {
if (!leader) {
console.log(
`${user} isn't a leader, so I told them this was restricted`
)
bot.replyPrivateDelayed(message, transcript('leaderList.invalidUser'))
return
}
if (!club) {
console.log(`${user} doesn't have a club`)
bot.replyPrivateDelayed(message, transcript('leaderList.invalidClub'))
return
}
if (club.fields['Slack Channel ID'] != channel) {
console.log(`${user} doesn't own channel ${channel}`)
bot.replyPrivateDelayed(
message,
transcript('leaderList.invalidChannel')
)
return
}
console.log(club.fields)
airGet(
'People',
`OR(${club.fields['Leaders'].map(l => `RECORD_ID()='${l}'`).join(',')})`
)
.then(leaders => {
console.log(leaders)
bot.replyPrivateDelayed(
message,
transcript('leaderList.list', { leaders, channel })
)
})
.catch(err => {
throw err
})
})
.catch(err => {
bot.replyPrivateDelayed(err)
console.error(err)
})
}
export default interactionLeaderList