Skip to content

Commit

Permalink
Add initial leaderList slash command
Browse files Browse the repository at this point in the history
  • Loading branch information
maxwofford committed Sep 18, 2019
1 parent 13c9a46 commit 7cd873c
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 4 deletions.
5 changes: 5 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions src/interactions/leaderAdd.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
41 changes: 41 additions & 0 deletions src/interactions/leaderList.js
Original file line number Diff line number Diff line change
@@ -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
9 changes: 8 additions & 1 deletion src/text.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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}>.
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'

0 comments on commit 7cd873c

Please sign in to comment.