Skip to content

Commit

Permalink
Add initial announcement command implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
maxwofford committed Sep 28, 2019
1 parent 3b331b6 commit 42a1919
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import interactionMeetingTime from './interactions/meetingTime'
import interactionMeetingTutorial from './interactions/meetingTutorial'
import interactionCatchall from './interactions/catchall'
import interactionPromo from './interactions/promo'
import interactionAnnouncement from './interactions/announcement'

export const bugsnagClient = bugsnag(process.env.BUGSNAG_API_KEY)

Expand Down Expand Up @@ -228,6 +229,10 @@ controller.on('slash_command', (bot, message) => {
interactionStats(bot, message)
break

case '/announcement':
interactionAnnouncement(bot, message)
break

case '/promo':
interactionPromo(bot, message)
break
Expand Down
44 changes: 44 additions & 0 deletions src/interactions/announcement.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { text as transcript, getInfoForUser, userRecord } from '../utils'

const interactionAnnouncement = (bot, message) => {
const { text, user } = message

const verb = text.split(' ')[0]

if (verb == 'help') {
bot.replyPrivateDelayed(message, transcript('announcement.help'))
}
if (!'record address status send'.split(' ').includes(verb)) {
bot.replyPrivateDelayed(
message,
transcript('announcement.unrecognizedCommand')
)
}

getInfoForUser(user).then(({ slackUser, userRecord }) => {
if (!slackUser.is_owner) {
throw new Error('This command can only be run by Slack Owner accounts')
}

const announcementData = userRecord.fields.announcement
if (verb == 'record') {
const content = text
userRecord.patch({ announcement: { content } }).catch(err => {
throw err
})
} else if (verb == 'address') {
const target = text
userRecord.patch({ announcement: { target } }).catch(err => {
throw err
})
} else if (verb == 'status') {
bot.replyPrivateDelayed(message, transcript('announcement.status'), {
announcementData,
})
} else if (verb == 'send') {
console.log('got Send command')
}
})
}

export default interactionAnnouncement
10 changes: 10 additions & 0 deletions src/text.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@ hello:
- hllo
- ehllo
- heoll
announcement:
help: |
Send an announcement to selected clubs. Usage below.
\- `/announcement record` Records a message to your user account
\- `/announcement address` Sets who the message is delivered to
\- `/announcement send` Sends the message
status: |
The following information is stored in the announcement command's memory
\ > ${this.announcementData}
unrecognizedCommand: I couldn't figure out what action you're trying to take. Here's the help text. ${this.text('announcement.help')}
whatAreYouDoing:
- my best...
- ¯\\_(ツ)_/¯
Expand Down

0 comments on commit 42a1919

Please sign in to comment.