From 7cd873c866385dc71a7f04e2dd4366cc9f1cc8ca Mon Sep 17 00:00:00 2001 From: Max Wofford Date: Wed, 18 Sep 2019 14:37:08 -0400 Subject: [PATCH] Add initial leaderList slash command --- src/index.js | 5 +++++ src/interactions/leaderAdd.js | 7 +++--- src/interactions/leaderList.js | 41 ++++++++++++++++++++++++++++++++++ src/text.yml | 9 +++++++- 4 files changed, 58 insertions(+), 4 deletions(-) create mode 100644 src/interactions/leaderList.js diff --git a/src/index.js b/src/index.js index dde87a50..ffc16426 100644 --- a/src/index.js +++ b/src/index.js @@ -13,6 +13,7 @@ import interactionHello from './interactions/hello' import interactionTrigger from './interactions/trigger' import interactionRename from './interactions/rename' import interactionLeaderAdd from './interactions/leaderAdd' +import interactionLeaderList from './interactions/leaderList' import interactionMeetingList from './interactions/meetingList' import interactionMeetingAdd from './interactions/meetingAdd' import interactionMeetingTime from './interactions/meetingTime' @@ -243,6 +244,10 @@ controller.on('slash_command', (bot, message) => { interactionLeaderAdd(bot, message) break + case '/leader-list': + interactionLeaderList(bot, message) + break + default: bot.whisper(message, "I don't know how to do that ¯\\_(ツ)_/¯") break diff --git a/src/interactions/leaderAdd.js b/src/interactions/leaderAdd.js index e4f54920..6d7abba0 100644 --- a/src/interactions/leaderAdd.js +++ b/src/interactions/leaderAdd.js @@ -56,11 +56,12 @@ const interactionLeaderAdd = (bot, message) => { }) .then(taggedUser => { // ensure we can assign the leader to this club - console.log(taggedUser.leader) - console.log(commandUser.club.id, taggedUser.leader.fields['Clubs']) const clubs = taggedUser.leader.fields['Clubs'] || [] + if (clubs.includes(commandUser.club.id)) { + bot.whisper(message, transcript('leaderAdd.alreadyLeader')) + return + } clubs.push(commandUser.club.id) - console.log(clubs) return airPatch('Leaders', taggedUser.leader.id, { Clubs: clubs }).then( () => { bot.whisper( diff --git a/src/interactions/leaderList.js b/src/interactions/leaderList.js new file mode 100644 index 00000000..517dd73b --- /dev/null +++ b/src/interactions/leaderList.js @@ -0,0 +1,41 @@ +import { getInfoForUser, airGet } from '../utils' + +const interactionLeaderList = (bot, message) => { + getInfoForUser(message.user) + .then(({ leader, club }) => { + if (!leader) { + console.log( + `${user} isn't a leader, so I told them this was restricted` + ) + bot.whisper(message, transcript('leaderList.invalidUser')) + return + } + + if (!club) { + console.log(`${user} doesn't have a club`) + bot.whisper(message, transcript('leaderList.invalidClub')) + return + } + + if (club.fields['Slack Channel ID'] != channel) { + console.log(`${user} doesn't own channel ${channel}`) + bot.whisper(message, transcript('leaderList.invalidChannel')) + return + } + + console.log(club.fields) + // airGet('Leaders', '') + // .then(leaders => { + // bot.whisper(message, transcript('leaderList.leaders', { leaders })) + // }) + // .catch(err => { + // throw err + // }) + }) + .catch(err => { + bot.whisper(err) + console.error(err) + }) +} + +export default interactionLeaderList diff --git a/src/text.yml b/src/text.yml index d190c663..d38147d4 100644 --- a/src/text.yml +++ b/src/text.yml @@ -91,4 +91,11 @@ leaderAdd: 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 + success: And... done! I've added <@${this.taggedUserID}> to the club in <#${this.channel}>. + alreadyLeader: They're already a leader in your club! +leaderList: + 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. + leaders: ${leaders.map(leader => this.text('leaderList.leader', { leader } ))} + leader: '- ${this.leader}\n' \ No newline at end of file