Skip to content

Commit

Permalink
Fix /leader-add usage in uninvited channels
Browse files Browse the repository at this point in the history
  • Loading branch information
maxwofford committed Sep 24, 2019
1 parent a6a0028 commit e90ecbe
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/interactions/leaderAdd.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const interactionLeaderAdd = (bot, message) => {
const { user, text, channel } = message

if (text === '' || text === 'help') {
bot.whisper(message, transcript('leaderAdd.help'))
bot.replyPrivateDelayed(message, transcript('leaderAdd.help'))
return
}

Expand All @@ -19,19 +19,19 @@ const interactionLeaderAdd = (bot, message) => {
console.log(
`${commandUser.user} isn't a leader, so I told them this was restricted`
)
bot.whisper(message, transcript('leaderAdd.invalidUser'))
bot.replyPrivateDelayed(message, transcript('leaderAdd.invalidUser'))
return
}

if (!commandUser.club) {
console.log(`${commandUser.user} doesn't have a club`)
bot.whisper(message, transcript('leaderAdd.invalidClub'))
bot.replyPrivateDelayed(message, transcript('leaderAdd.invalidClub'))
return
}

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

Expand Down Expand Up @@ -68,14 +68,17 @@ const interactionLeaderAdd = (bot, message) => {
// ensure we can assign the leader to this club
const clubs = taggedUser.leader.fields['Clubs'] || []
if (clubs.includes(commandUser.club.id)) {
bot.whisper(message, transcript('leaderAdd.alreadyLeader'))
bot.replyPrivateDelayed(
message,
transcript('leaderAdd.alreadyLeader')
)
return
}
clubs.push(commandUser.club.id)
return airPatch('Leaders', taggedUser.leader.id, {
Clubs: clubs,
}).then(() => {
bot.whisper(
bot.replyPrivateDelayed(
message,
transcript('leaderAdd.success', { taggedUserID, channel })
)
Expand All @@ -84,7 +87,7 @@ const interactionLeaderAdd = (bot, message) => {
})
.catch(err => {
console.error(err)
bot.whisper(message, transcript('errors.general', { err }))
bot.replyPrivateDelayed(message, transcript('errors.general', { err }))
})
}

Expand Down

0 comments on commit e90ecbe

Please sign in to comment.