diff --git a/src/interactions/leaderAdd.js b/src/interactions/leaderAdd.js index 430f8dc4..685750ec 100644 --- a/src/interactions/leaderAdd.js +++ b/src/interactions/leaderAdd.js @@ -1,4 +1,4 @@ -import { getInfoForUser, airCreate } from '../utils' +import { getInfoForUser, airCreate, airPatch } from '../utils' const interactionLeaderAdd = (bot, message) => { const { user, text } = message @@ -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 => { @@ -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) diff --git a/src/text.yml b/src/text.yml index 9924175a..d190c663 100644 --- a/src/text.yml +++ b/src/text.yml @@ -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 \ No newline at end of file + 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}>. \ No newline at end of file