Skip to content

Commit

Permalink
add saving to leader-add slash command
Browse files Browse the repository at this point in the history
  • Loading branch information
maxwofford committed Sep 18, 2019
1 parent e99f0ed commit f9aaf12
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
22 changes: 20 additions & 2 deletions src/interactions/leaderAdd.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getInfoForUser, airCreate } from '../utils'
import { getInfoForUser, airCreate, airPatch } from '../utils'

const interactionLeaderAdd = (bot, message) => {
const { user, text } = message
Expand All @@ -23,6 +23,12 @@ const interactionLeaderAdd = (bot, message) => {
return
}

if (!commandUser.club.fields['Slack Channel ID'] != channel) {
console.log(`${commandUser.user} doesn't own this channel`)
bot.whisper(message, transcript('leaderAdd.invalidChannel'))
return
}

const taggedUserID = message.text.match(/\<@(.*)\|/)[1]
getInfoForUser(taggedUserID)
.then(taggedUser => {
Expand All @@ -45,7 +51,19 @@ const interactionLeaderAdd = (bot, message) => {
})
.then(taggedUser => {
// ensure we can assign the leader to this club
console.log('TODO: validate leader can be assigned to club')
console.log(taggedUser.leader)
const clubs = [
commandUser.club.id,
...taggedUser.leader.fields['Clubs'],
]
return airPatch('Leaders', taggedUser.leader.id, { Clubs: clubs }).then(
() => {
bot.whisper(
message,
transcript('leaderAdd.success', { taggedUserID, channel })
)
}
)
})
.catch(err => {
console.error(err)
Expand Down
6 changes: 4 additions & 2 deletions src/text.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,5 +88,7 @@ meetingTime:
success: Ok, I'll post a message in your club's channel around ${this.hour}:00 on ${this.day} UTC
parsingError: I couldn't figure out what day and time you meant
leaderAdd:
invalidUser: Only club leaders can use this command
invalidClub: I couldn't find a club channel owned by you
invalidUser: Only club leaders can use this command.
invalidClub: I couldn't find your club.
invalidChannel: This isn't your club channel. Please run this in a channel you lead.
success: And... done! I've added <@${this.taggedUserID}> to the club in <#${this.channel}>.

0 comments on commit f9aaf12

Please sign in to comment.