Skip to content

Commit

Permalink
modify poll command to use letters instead of numbers as answer indices
Browse files Browse the repository at this point in the history
  • Loading branch information
halbrd committed Sep 7, 2018
1 parent 05b5b17 commit 67ca5c7
Showing 1 changed file with 6 additions and 35 deletions.
41 changes: 6 additions & 35 deletions plugins/poll/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ const help = {
usage: 'poll -q \'[question]\' -a \'[answer]\' -a \'[answer]\''
};

let getLetter = index => String.fromCodePoint(127462 + index); // 127462 is the decimal code of :regional_indicator_a:

class Poll extends BasePlugin {
constructor() {
super();
Expand All @@ -25,32 +27,6 @@ class Poll extends BasePlugin {
async handler(msg) {
super.handler(msg);

const numToString = {
0: ':zero:',
1: ':one:',
2: ':two:',
3: ':three:',
4: ':four:',
5: ':five:',
6: ':six:',
7: ':seven:',
8: ':eight:',
9: ':nine:'
};

const numToEmoji = {
0: '0⃣',
1: '1⃣',
2: '2⃣',
3: '3⃣',
4: '4⃣',
5: '5⃣',
6: '6⃣',
7: '7⃣',
8: '8⃣',
9: '9⃣'
};

const m = minimist(this.args.join(' '), {
string: ['q', 'question', 'a', 'answer']
});
Expand All @@ -61,17 +37,12 @@ class Poll extends BasePlugin {
if (!question || Array.isArray(question)) {
return msg.reply('🚫 You must supply 1 question.');
}
if (
!answers ||
answers.length < 2 ||
!Array.isArray(answers) ||
answers.length > 10
) {
return msg.reply('🚫 You must supply between 2 and 10 answers.');
if (!Array.isArray(answers) || answers.length < 2 || answers.length > 26) {
return msg.reply('🚫 You must supply between 2 and 26 answers.');
}
let answerMsg = '';
for (let i = 0; i < answers.length; i++) {
answerMsg += `${numToString[i]} ${answers[i]}\n`;
answerMsg += `${getLetter(i)} ${answers[i]}\n`;
}
const embed = {
title: question,
Expand All @@ -98,7 +69,7 @@ class Poll extends BasePlugin {
console.log(e);
const response = await msg.channel.sendEmbed(new RichEmbed(embed));
for (let i = 0; i < answers.length; i++) {
await response.react(numToEmoji[i]);
await response.react(getLetter(i));
}
} catch (err) {
console.error(err);
Expand Down

0 comments on commit 67ca5c7

Please sign in to comment.