-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathleaderAdd.js
54 lines (48 loc) · 1.58 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
42
43
44
45
46
47
48
49
50
51
52
53
54
import { getInfoForUser, airFind } from '../utils'
const interactionLeaderAdd = (bot, message) => {
const { user, text } = message
if (text === '' || text === 'help') {
bot.whisper(message, transcript('leaderAdd.help'))
return
}
getInfoForUser(user).then(commandUser => {
if (!commandUser.leader) {
console.log(
`${commandUser.user} isn't a leader, so I told them this was restricted`
)
bot.whisper(message, transcript('leaderAdd.invalidUser'))
return
}
if (!commandUser.club) {
console.log(`${commandUser.user} doesn't have a club`)
bot.whisper(message, transcript('leaderAdd.invalidClub'))
return
}
const taggedUserID = message.text.match(/\<@(.*)\|/)[1]
getInfoForUser(taggedUserID)
.then(taggedUser => {
// if user doesn't exist
if (!taggedUser.leader) {
const profile = taggedUser.slackUser.profile
const fields = {
Email: taggedUser.slackUser.profile.email,
'Slack ID': taggedUser.slackUser.id,
'Full Name': profile.real_name || profile.display_name,
}
return airCreate('Leaders', fields).catch(err => {
console.error('Ran into issue creating new leader airtable record')
throw err
})
}
return taggedUser
})
.then(taggedUser => {
// ensure we can assign the leader to this club
console.log('TODO: validate leader can be assigned to club')
})
.catch(err => {
throw err
})
})
}
export default interactionLeaderAdd