-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathleaderAdd.js
41 lines (32 loc) · 1.23 KB
/
leaderAdd.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
import { getInfoForUser, airPatch, transcript, airFind } from '../utils'
const interactionLeaderAdd = async (bot, message) => {
const { user, text, channel } = message
const taggedUserID = (text.match(/\<@(.*)\|/) || [])[1]
if (!taggedUserID) {
bot.replyPrivateDelayed(message, transcript('leaderAdd.help'))
return
}
const taggedUser = await getInfoForUser(taggedUserID)
const commandUser = await getInfoForUser(user)
const recipientClub = await airFind('Clubs', 'Slack Channel ID', channel)
if (!commandUser.club && !commandUser.permissionedAmbassador) {
throw transcript('leaderAdd.invalidClub')
}
if (commandUser.club && commandUser.club.id != recipientClub.id) {
// A leader is trying to permission someone to a channel that's not their
// club channel
throw transcript('leaderAdd.invalidChannel')
}
const taggedUserClubs = taggedUser.fields['Clubs'] || []
if (taggedUserClubs.includes(recipientClub)) {
throw transcript('leaderAdd.alreadyLeader')
}
await airPatch('People', taggedUser.id, {
Clubs: [...taggedUserClubs, recipientClub],
})
bot.replyPrivateDelayed(
message,
transcript('leaderAdd.success', { taggedUserID, channel })
)
}
export default interactionLeaderAdd