-
Notifications
You must be signed in to change notification settings - Fork 12
!question & !poll Commands #166
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| const BaseController = require('../baseController.js'); | ||
| const Command = require('../baseCommand.js'); | ||
| const util = require('apex-util'); | ||
|
|
||
| class PollController extends BaseController { | ||
| constructor(message) { | ||
| // Call BaseController constructor | ||
| super(message); | ||
|
|
||
| // Aliasing 'this' as controller to allow for binding in actions | ||
| const controller = this; | ||
|
|
||
| // Array of all commands, see baseCommand.js for prototype | ||
| this.commands = [ | ||
| new Command( | ||
| '!poll', | ||
| '!poll <ask-a-question> <option_1> <option_2> <option_3>', | ||
| 'Posts a Question users can vote on', | ||
| 'Posts a Question users can vote on, use "-" to separate words in your question', | ||
| this.pollAction.bind(controller), | ||
| ), | ||
| ]; | ||
| } | ||
|
|
||
| pollAction() { | ||
| const { message } = this; | ||
| const question = message.parsed[1]; | ||
| const questionSpaced = question.split('-').join(' '); | ||
| const content = message.content; | ||
| const count = content.split(' ').length; | ||
|
|
||
| let options = ''; | ||
|
|
||
| if (count >= 2 && count <= 11) { | ||
| for (let i = 2; i < count; i += 1) { | ||
| if (i === 2) { | ||
| options += `\r \u0031\u20E3${message.parsed[i]}`; | ||
| } else if (i === 3) { | ||
| options += `\r \u0032\u20E3${message.parsed[i]}`; | ||
| } else if (i === 4) { | ||
| options += `\r \u0033\u20E3${message.parsed[i]}`; | ||
| } else if (i === 5) { | ||
| options += `\r \u0034\u20E3${message.parsed[i]}`; | ||
| } else if (i === 6) { | ||
| options += `\r \u0035\u20E3${message.parsed[i]}`; | ||
| } else if (i === 7) { | ||
| options += `\r \u0036\u20E3${message.parsed[i]}`; | ||
| } else if (i === 8) { | ||
| options += `\r \u0037\u20E3${message.parsed[i]}`; | ||
| } else if (i === 9) { | ||
| options += `\r \u0038\u20E3${message.parsed[i]}`; | ||
| } else if (i === 10) { | ||
| options += `\r ️\u0039\u20E3${message.parsed[i]}`; | ||
| } | ||
| } | ||
| } else { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add a space between the special characters and the poll options for minor readability improvement |
||
| return 'The poll can not expect 0 or more than 9 options'; | ||
| } | ||
|
|
||
| const query = `"${questionSpaced}" \r ${options}`; | ||
| message.channel.send(query) | ||
| .then((message) => { | ||
| for (let i = 2; i < count; i += 1) { | ||
| if (i === 2) { | ||
| message.react('\u0031\u20E3'); | ||
| } else if (i === 3) { | ||
| message.react('\u0032\u20E3'); | ||
| } else if (i === 4) { | ||
| message.react('\u0033\u20E3'); | ||
| } else if (i === 5) { | ||
| message.react('\u0034\u20E3'); | ||
| } else if (i === 6) { | ||
| message.react('\u0035\u20E3'); | ||
| } else if (i === 7) { | ||
| message.react('\u0036\u20E3'); | ||
| } else if (i === 8) { | ||
| message.react('\u0037\u20E3'); | ||
| } else if (i === 9) { | ||
| message.react('\u0038\u20E3'); | ||
| } else if (i === 10) { | ||
| message.react('\u0039\u20E3'); | ||
| } | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If I'm reading this correctly, I believe that this can be improved without doing multiple checks? For example:
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While this is a better way to solve this, the Style Guide restricts incomplete unicode like |
||
| }).catch(() => { | ||
| util.error('pollAction reaction failed'); | ||
| }); | ||
| return ' wants to know.'; | ||
| } | ||
| } | ||
|
|
||
| module.exports = PollController; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| const BaseController = require('../baseController.js'); | ||
| const Command = require('../baseCommand.js'); | ||
| const util = require('apex-util'); | ||
|
|
||
| class QuestionController extends BaseController { | ||
| constructor(message) { | ||
| // Call BaseController constructor | ||
| super(message); | ||
|
|
||
| // Aliasing 'this' as controller to allow for binding in actions | ||
| const controller = this; | ||
|
|
||
| // Array of all commands, see baseCommand.js for prototype | ||
| this.commands = [ | ||
| new Command( | ||
| '!question', | ||
| '!question <ask-a-question>', | ||
| 'Posts a Question users can vote on', | ||
| 'Posts a Question users can vote on, use "-" to separate words in your question', | ||
| this.questionsAction.bind(controller), | ||
| ), | ||
| ]; | ||
| } | ||
|
|
||
| questionsAction() { | ||
| const { message } = this; | ||
| const question = message.parsed[1]; | ||
| const query = `"${question.split('-').join(' ')}?"`; | ||
| message.channel.send(query) | ||
| .then((message) => { | ||
| message.react('👍'); | ||
| message.react('🤔'); | ||
| message.react('👎'); | ||
| }).catch(() => { | ||
| util.error('questionAction reaction failed'); | ||
| }); | ||
| return ' wants to know.'; | ||
| } | ||
| } | ||
|
|
||
| module.exports = QuestionController; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm picking up a linting issue here, even though it seems to have gone through the tests successfully. However, I do recommend de-structuring it:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure why you're getting that linting issue, I don't see it and like you said it does pass the CircleCI test. I'm using content to convert the message.content into a usable string, but still need to use
const {message} = message}so I get the initial information from Discord.