From d625147e7c3eb1ff5e524b0aa193c6fcf5e31e6c Mon Sep 17 00:00:00 2001 From: Zaporojan Victor Date: Fri, 31 Jan 2020 23:27:49 +0000 Subject: [PATCH 1/8] refactored code --- index.js | 4 +- package.json | 6 +- util/GetGameList.js | 157 ++++++++++++++------------------------------ 3 files changed, 58 insertions(+), 109 deletions(-) diff --git a/index.js b/index.js index 16ca8db..1d0bc3c 100644 --- a/index.js +++ b/index.js @@ -52,11 +52,11 @@ client.registry }) .registerCommandsIn(path.join(__dirname, 'commands')); -client.once('ready', () => { +client.once('ready', async () => { client.user.setUsername(BOT_NAME || 'RABot'); logger.info(`[READY] Logged in as ${client.user.tag}! (${client.user.id})`); client.user.setActivity('if you need help', { type: 'WATCHING' }); - getGameList(); + await getGameList(); }); client.on('guildMemberAdd', async (member) => { diff --git a/package.json b/package.json index 6b266a9..77e9957 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "retroachievements-discord-bot", "version": "1.1.0", - "description": "https://github.com/hydrabolt/discord.js/", + "description": "Retroachievements.org Discord Bot - www.retroachievements.org", "main": "index.js", "dependencies": { "cheerio": "^1.0.0-rc.3", @@ -39,6 +39,10 @@ "lint": "eslint --ignore-path .gitignore .", "lintfix": "eslint --ignore-path .gitignore . --fix" }, + "repository": { + "type": "git", + "url": "https://github.com/RetroAchievements/RABot" + }, "author": "luchaos", "license": "ISC" } diff --git a/util/GetGameList.js b/util/GetGameList.js index d5e2e94..49d9e83 100644 --- a/util/GetGameList.js +++ b/util/GetGameList.js @@ -1,156 +1,101 @@ -const { execFile } = require('child_process'); -const logger = require('pino')({ - useLevelLabels: true, - timestamp: () => `,"time":"${new Date()}"`, -}); +const fetch = require('node-fetch'); -const getGLScript = `${__dirname}/getgamelist.sh`; - -const glPath = `${__dirname}/../assets/json`; +// const glPath = `${__dirname}/../assets/json`; +// let fs = require('fs'); const gamelist = { index: {}, games: [], }; -const consoles = { - 1: 'megadrive', - 2: 'n64', - 3: 'snes', - 4: 'gb', - 5: 'gba', - 6: 'gbc', - 7: 'nes', - 8: 'pcengine', - 9: 'segacd', - 10: 'sega32x', - 11: 'mastersystem', - 12: 'psx', - 13: 'atarilynx', - 14: 'ngp', - 15: 'gamegear', +const getConsolesURL = 'https://retroachievements.org/dorequest.php?r=officialgameslist&c='; + +const consoles = [ + { id: 1, name: 'megadrive' }, + { id: 2, name: 'n64' }, + { id: 3, name: 'snes' }, + { id: 4, name: 'gb' }, + { id: 5, name: 'gba' }, + { id: 6, name: 'gbc' }, + { id: 7, name: 'nes' }, + { id: 8, name: 'pcengine' }, + { id: 9, name: 'segacd' }, + { id: 10, name: 'sega32x' }, + { id: 11, name: 'mastersystem' }, + { id: 12, name: 'psx' }, + { id: 13, name: 'atarilynx' }, + { id: 14, name: 'ngp' }, + { id: 15, name: 'gamegear' }, // 16: "gamecube", - 17: 'jaguar', - 18: 'nds', + { id: 17, name: 'jaguar' }, + { id: 18, name: 'nds' }, // 19: "wii", // 20: "wiiu", // 21: "ps2", // 22: "xbox", // 23: "skynet", - 24: 'pokemonmini', - 25: 'atari2600', + { id: 24, name: 'pokemonmini' }, + { id: 25, name: 'atari2600' }, // 26: "dos", - 27: 'arcade', - 28: 'virtualboy', + { id: 27, name: 'arcade' }, + { id: 28, name: 'virtualboy' }, // 29: "msx", // 30: "commodore64", // 31: "zx81", - 33: 'sg100', + { id: 33, name: 'sg100' }, // 34: // VIC-20 // 35: // Amiga // 36: // Atari ST // 37: // Amstrad CPC - 38: 'apple2', - 39: 'saturn', + { id: 38, name: 'apple2' }, + { id: 39, name: 'saturn' }, // 40: // Dreamcast // 41: // PlayStation Portable // 42: // Philips CD-i // 43: // 3DO Interactive Multiplayer - 44: 'coleco', + { id: 44, name: 'coleco' }, // 45: // Intellivision // 46: // Vectrex - 47: 'pc88', + { id: 47, name: 'pc88' }, // 48: // PC-9800 // 49: // PC-FX // 50: // Atari 5200 - 51: 'atari7800', + { id: 51, name: 'atari7800' }, // 52: // X68K - 53: 'wonderswan', + { id: 53, name: 'wonderswan' }, // 54: // Cassette Vision // 55: // Super Cassette Vision -}; +]; - -function loadGameLists() { - const consoleIDs = Object.keys(consoles); - let consoleID; - let json; - let entries; +async function getConsoles() { let tmpIndex = 0; - - for (let i = 0; i < consoleIDs.length; i += 1) { - consoleID = consoleIDs[i]; - json = require(`${glPath}/gl-${consoles[consoleID]}.json`); + let entries; + await Promise.all(consoles.map(async (c) => { + const res = await fetch(`${getConsolesURL}${c.id}`); + const json = await res.json(); if (json.Success) { - entries = Object.entries(json.Response); + // decomment below line to write the response into each .json file if still needed + // fs.writeFile(`${glPath}/gl-${c.name}.json`,jsonData, err => logger.error(err)); + // let jsonFile = require(`${glPath}/gl-${c.name}.json`); + + entries = Object.entries(json.Response); gamelist.games = gamelist.games.concat(entries); - gamelist.index[consoles[consoleID]] = [ + gamelist.index[c.name] = [ tmpIndex, entries.length, ]; tmpIndex += entries.length; } - } -} - - -function getAllGameLists() { - execFile('bash', [getGLScript], (err, stdout) => { - if (err) { - logger.error(err); - return 1; - } - logger.info(stdout); - loadGameLists(); - return true; - }); + })); } -function getGameList() { - loadGameLists(); - +async function getGameList() { + await getConsoles(); // update twice a day - setInterval(getAllGameLists, 1000 * 60 * 60 * 12); + setInterval(await getConsoles, 1000 * 60 * 60 * 12); } module.exports.gamelist = gamelist; -module.exports.consoles = Object.values(consoles); +module.exports.consoles = consoles.map(((c) => c.id)); module.exports.getGameList = getGameList; - - -/* - -// This is a failed attempt to get the list of games with pure JavaScript+Node -// I hate asynchronouse programming! >:( - -async function getGameListByConsole( consoleID ) { - const res = await fetch( encodeURI( gamelistURL + consoleID ) ); - const json = await res.json(); - - if( json.Success ) { - // loading the file into the memory again - const tmpJson = gamelists[ consoles[ consoleID ] ] = Object.entries( json.Response ); - globalGamelist = Object.assign( tmpJson, globalGamelist ); - - // writing the current file - fs.writeFile( - `${glPath}/gl-${consoles[consoleID]}.json`, - JSON.stringify(tmpJson, null, 1), - (err) => { - if( err ) { - console.error(err); - return; - } - console.log(`[LOG] successfully updated gamelist for console ID ${consoleID}`); - }); - } else { - console.warn(`[WARNING] failed to get gamelist for console ID ${consoleID}`); - } -} - - -function getAllGameLists() { - Object.keys( consoles ).forEach( consoleID => getGameListByConsole( consoleID ) ); -} -*/ From d6d4fbd42be9ea83cfa07e7be8cff25fda9478d5 Mon Sep 17 00:00:00 2001 From: Zaporojan Victor Date: Fri, 31 Jan 2020 23:28:49 +0000 Subject: [PATCH 2/8] refactored code --- package-lock.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 624d8d9..63b2290 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1767,9 +1767,9 @@ "integrity": "sha512-RZY5huIKCMRWDUqZlEi72f/lmXKMvuszcMBduliQ3nnWbx9X/ZBQO7DijMEYS9EhHBb2qacRUMtC7svLwe0lcw==" }, "inquirer": { - "version": "7.0.3", - "resolved": "https://registry.npmjs.org/inquirer/-/inquirer-7.0.3.tgz", - "integrity": "sha512-+OiOVeVydu4hnCGLCSX+wedovR/Yzskv9BFqUNNKq9uU2qg7LCcCo3R86S2E7WLo0y/x2pnEZfZe1CoYnORUAw==", + "version": "7.0.4", + "resolved": "https://registry.npmjs.org/inquirer/-/inquirer-7.0.4.tgz", + "integrity": "sha512-Bu5Td5+j11sCkqfqmUTiwv+tWisMtP0L7Q8WrqA2C/BbBhy1YTdFrvjjlrKq8oagA/tLQBski2Gcx/Sqyi2qSQ==", "dev": true, "requires": { "ansi-escapes": "^4.2.1", From 8fcab6f82e98821efd39def3d111b51bf8524d27 Mon Sep 17 00:00:00 2001 From: Zaporojan Victor Date: Fri, 31 Jan 2020 23:28:52 +0000 Subject: [PATCH 3/8] 1.1.1 --- package-lock.json | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index 63b2290..c12bcd9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "retroachievements-discord-bot", - "version": "1.1.0", + "version": "1.1.1", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 77e9957..4263d7e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "retroachievements-discord-bot", - "version": "1.1.0", + "version": "1.1.1", "description": "Retroachievements.org Discord Bot - www.retroachievements.org", "main": "index.js", "dependencies": { From 114d31e06d3b0cb0f4e9b2897c071ca7da8f555d Mon Sep 17 00:00:00 2001 From: Zaporojan Victor Date: Sat, 1 Feb 2020 00:10:17 +0000 Subject: [PATCH 4/8] linted and small fix on exports.console --- util/GetGameList.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/util/GetGameList.js b/util/GetGameList.js index 49d9e83..66ba428 100644 --- a/util/GetGameList.js +++ b/util/GetGameList.js @@ -74,7 +74,6 @@ async function getConsoles() { const res = await fetch(`${getConsolesURL}${c.id}`); const json = await res.json(); if (json.Success) { - // decomment below line to write the response into each .json file if still needed // fs.writeFile(`${glPath}/gl-${c.name}.json`,jsonData, err => logger.error(err)); // let jsonFile = require(`${glPath}/gl-${c.name}.json`); @@ -97,5 +96,11 @@ async function getGameList() { } module.exports.gamelist = gamelist; -module.exports.consoles = consoles.map(((c) => c.id)); +module.exports.consoles = (() => { + const consolesNames = []; + consoles.forEach((c) => { + consolesNames.push(c.name); + }); + return consolesNames; +})(); module.exports.getGameList = getGameList; From 60e1400215019ca0774bb21718809d836315b542 Mon Sep 17 00:00:00 2001 From: Zaporojan Victor Date: Sat, 1 Feb 2020 03:02:10 +0000 Subject: [PATCH 5/8] added contributors and homepage entries to package.json --- package.json | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/package.json b/package.json index 4263d7e..ad56e2b 100644 --- a/package.json +++ b/package.json @@ -2,6 +2,7 @@ "name": "retroachievements-discord-bot", "version": "1.1.1", "description": "Retroachievements.org Discord Bot - www.retroachievements.org", + "homepage": "http://retroachievements.org", "main": "index.js", "dependencies": { "cheerio": "^1.0.0-rc.3", @@ -44,5 +45,15 @@ "url": "https://github.com/RetroAchievements/RABot" }, "author": "luchaos", + "contributors": [ + { + "name": "zapo", + "url": "http://victorz.me" + }, + { + "name": "meleu", + "url": "http://meleu.sh/" + } + ], "license": "ISC" } From fefbd02b88b53c93ec54ccfa467f4fbc407ca54c Mon Sep 17 00:00:00 2001 From: Zaporojan Victor Date: Sat, 15 Feb 2020 05:03:42 +0000 Subject: [PATCH 6/8] added hidden vote concept to poll commands --- commands/poll/poll.js | 19 ++++++++++++------- commands/poll/tpoll.js | 34 +++++++++++++++++++++++++--------- 2 files changed, 37 insertions(+), 16 deletions(-) diff --git a/commands/poll/poll.js b/commands/poll/poll.js index 1e14439..f234ded 100644 --- a/commands/poll/poll.js +++ b/commands/poll/poll.js @@ -1,19 +1,22 @@ -const { Collection } = require('discord.js'); const Command = require('../../structures/Command.js'); -const allOptions = Object.values(require('../../assets/json/emoji-alphabet.json')); - module.exports = class PollCommand extends Command { constructor(client) { super(client, { name: 'poll', group: 'poll', memberName: 'poll', - description: 'Create a (useless) poll.', - examples: ['`poll \'Which option you choose?\' \'option one\' \'option 2\' \'option N\'`'], + description: 'Create a poll. Can be set hidden or not', + examples: ['`poll yes \'Which option you choose?\' \'option one\' \'option 2\' \'option N\'`', '`poll no \'Which option you choose?\' \'option one\' \'option 2\' \'option N\'`'], argsSingleQuotes: true, argsPromptLimit: 0, args: [ + { + key: 'hidden', + type: 'string', + prompt: '', + default: 'no', + }, { key: 'question', type: 'string', @@ -34,7 +37,9 @@ module.exports = class PollCommand extends Command { }); } - async run(msg, { question, opts }) { - return this.client.registry.resolveCommand('poll:tpoll').run(msg, { seconds: 0, question, opts }); + async run(msg, { hidden, question, opts }) { + return this.client.registry.resolveCommand('poll:tpoll').run(msg, { + seconds: 0, hidden, question, opts, + }); } }; diff --git a/commands/poll/tpoll.js b/commands/poll/tpoll.js index b3d383b..b9aa0d1 100644 --- a/commands/poll/tpoll.js +++ b/commands/poll/tpoll.js @@ -9,8 +9,8 @@ module.exports = class TimedPollCommand extends Command { name: 'tpoll', group: 'poll', memberName: 'tpoll', - description: 'Create a timed poll.', - examples: ['`tpoll 60 \'Which option you choose?\' \'option one\' \'option 2\' \'option N\'`'], + description: 'Create a timed poll. You can create a hidden time poll by adding hidden as a argument.', + examples: ['`tpoll 60 yes \'Which option you choose?\' \'option one\' \'option 2\' \'option N\'`', '`tpoll 60 no \'Which option you choose?\' \'option one\' \'option 2\' \'option N\'`'], throttling: { usages: 1, duration: 30, @@ -25,6 +25,12 @@ module.exports = class TimedPollCommand extends Command { min: 0, max: 604800, // 604,800 seconds = 1 week }, + { + key: 'hidden', + type: 'string', + prompt: '', + default: 'no', + }, { key: 'question', type: 'string', @@ -45,7 +51,9 @@ module.exports = class TimedPollCommand extends Command { }); } - async run(msg, { seconds, question, opts }) { + async run(msg, { + seconds, hidden, question, opts, + }) { if (opts.length < 2 || opts.length > 10) return msg.reply('The number of options must be greater than 2 and less than 10'); let options = ''; @@ -54,13 +62,14 @@ module.exports = class TimedPollCommand extends Command { const milliseconds = seconds <= 0 ? 0 : seconds * 1000; const voters = []; const pollResults = new Collection(); + const reactions = allOptions.slice(0, opts.length); - for (i = 0; i < opts.length; i++) { + for (i = 0; i < opts.length; i += 1) { options += `\n${reactions[i]} ${opts[i]}`; // let's check if there's a repetition in the options - for (let j = i + 1; j < opts.length; j++) if (opts[i] === opts[j]) return msg.reply(`**\`poll\` error**: repeated options found: \`${opts[i]}\``); + for (let j = i + 1; j < opts.length; j += 1) if (opts[i] === opts[j]) return msg.reply(`**\`poll\` error**: repeated options found: \`${opts[i]}\``); } pollMsg.push(`__*${msg.author} started a poll*__:`); @@ -78,11 +87,11 @@ module.exports = class TimedPollCommand extends Command { sentMsg.edit(pollMsg); } - for (i = 0; i < opts.length; i++) await sentMsg.react(reactions[i]); + for (i = 0; i < opts.length; i += 1) await sentMsg.react(reactions[i]); if (!milliseconds) return; - const filter = (reaction, user) => { + const filter = async (reaction, user) => { // ignore bot's reactions if (this.client.user.id === user.id) { return false; @@ -112,6 +121,13 @@ module.exports = class TimedPollCommand extends Command { // msg.channel.send(`\`${user.username}\`'s vote: ${reaction.emoji.name}`) // .then(m => m.delete(5000)); + + if (hidden === 'yes') { + sentMsg.channel.fetchMessage(sentMsg.id).then((message) => { + message.reactions.forEach((r) => r.remove(user.id)); + }); + } + return true; }; @@ -138,9 +154,9 @@ module.exports = class TimedPollCommand extends Command { pollEndedMsg.push(`<${sentMsg.url}>`); msg.reply(pollEndedMsg); }) - .catch((collected) => { + .catch((error) => { + logger.error(error); msg.reply('**`poll` error**: Something went wrong with your poll.'); - console.error(collected); }); } }; From 9c52eee855524e814ef1def2d74a2620b356a8bf Mon Sep 17 00:00:00 2001 From: Zaporojan Victor Date: Sat, 15 Feb 2020 05:05:16 +0000 Subject: [PATCH 7/8] added missing logger module --- commands/poll/tpoll.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/commands/poll/tpoll.js b/commands/poll/tpoll.js index b9aa0d1..8d10435 100644 --- a/commands/poll/tpoll.js +++ b/commands/poll/tpoll.js @@ -1,6 +1,9 @@ const { Collection } = require('discord.js'); const Command = require('../../structures/Command.js'); - +const logger = require('pino')({ + useLevelLabels: true, + timestamp: () => `,"time":"${new Date()}"`, +}); const allOptions = Object.values(require('../../assets/json/emoji-alphabet.json')); module.exports = class TimedPollCommand extends Command { From 87766f7e9ec1d9e45a421c7ddf42277a50ef74f8 Mon Sep 17 00:00:00 2001 From: Zaporojan Victor Date: Tue, 18 Feb 2020 00:25:23 +0000 Subject: [PATCH 8/8] - added hidden timed poll command --- commands/poll/htpoll.js | 158 ++++++++++++++++++++++++++++++++++++++++ commands/poll/poll.js | 5 +- commands/poll/tpoll.js | 15 ++-- 3 files changed, 166 insertions(+), 12 deletions(-) create mode 100644 commands/poll/htpoll.js diff --git a/commands/poll/htpoll.js b/commands/poll/htpoll.js new file mode 100644 index 0000000..868580f --- /dev/null +++ b/commands/poll/htpoll.js @@ -0,0 +1,158 @@ +const { Collection } = require('discord.js'); +const Command = require('../../structures/Command.js'); + +const allOptions = Object.values(require('../../assets/json/emoji-alphabet.json')); + +const logger = require('pino')({ + useLevelLabels: true, + timestamp: () => `,"time":"${new Date()}"`, +}); + +function removeReaction(sentMsg, user) { + sentMsg.channel.fetchMessage(sentMsg.id).then((message) => { + message.reactions.forEach((r) => r.remove(user.id)); + }); +} + +module.exports = class TimedPollCommand extends Command { + constructor(client) { + super(client, { + name: 'htpoll', + group: 'poll', + memberName: 'htpoll', + aliases: ['hiddentimedpoll'], + description: 'Create a timed poll. You can create a hidden time poll by adding hidden as a argument.', + examples: ['`tpoll 60 \'Which option you choose?\' \'option one\' \'option 2\' \'option N\'`'], + throttling: { + usages: 1, + duration: 30, + }, + argsSingleQuotes: true, + argsPromptLimit: 0, + args: [ + { + key: 'seconds', + type: 'integer', + prompt: '', + min: 0, + max: 604800, // 604,800 seconds = 1 week + }, + { + key: 'question', + type: 'string', + prompt: '', + validate: (question) => { + if (question.length > 0 && question.length < 200) return true; + return 'Invalid question'; + }, + }, + { + key: 'opts', + prompt: '', + type: 'string', + infinite: true, + default: '~NO~OPTS~', + }, + ], + }); + } + + async run(msg, { + seconds, question, opts, + }) { + if (opts.length < 2 || opts.length > 10) return msg.reply('The number of options must be greater than 2 and less than 10'); + + let options = ''; + let i; + const pollMsg = []; + const milliseconds = seconds <= 0 ? 0 : seconds * 1000; + const voters = []; + const pollResults = new Collection(); + + const reactions = allOptions.slice(0, opts.length); + + for (i = 0; i < opts.length; i += 1) { + options += `\n${reactions[i]} ${opts[i]}`; + + // let's check if there's a repetition in the options + for (let j = i + 1; j < opts.length; j += 1) if (opts[i] === opts[j]) return msg.reply(`**\`poll\` error**: repeated options found: \`${opts[i]}\``); + } + + pollMsg.push(`__*${msg.author} started a hidden poll*__:`); + pollMsg.push(`\n:bar_chart: **${question}**\n${options}`); + + if (milliseconds) pollMsg.push('\n`Notes:\n- only the first reaction is considered a vote\n- unlisted reactions void the vote`'); + + const sentMsg = await msg.channel.send(pollMsg); + + if (milliseconds) { + const endTime = sentMsg.createdAt; + endTime.setTime(endTime.getTime() + milliseconds); + + pollMsg.push(`:stopwatch: *This poll ends at ${endTime}*`); + sentMsg.edit(pollMsg); + } + + for (i = 0; i < opts.length; i += 1) await sentMsg.react(reactions[i]); + + if (!milliseconds) return; + + const filter = async (reaction, user) => { + // ignore bot's reactions + if (this.client.user.id === user.id) { + return false; + } + + // do not allow repeated votes + if (voters.indexOf(user.id) < 0) { + voters.push(user.id); + } else { + removeReaction(sentMsg, user); + return false; + } + + // do not count invalid reactions + if (!reactions.includes(reaction.emoji.name)) { + return false; + } + + // if the logic reaches here, then the reaction is accepted as a vote + let numVotes = pollResults.get(reaction.emoji.name); + numVotes = !numVotes ? 1 : numVotes + 1; + + pollResults.set(reaction.emoji.name, numVotes); + + removeReaction(sentMsg, user); + + return true; + }; + + sentMsg.awaitReactions(filter, { time: milliseconds }) + .then((collected) => { + const pollEndedMsg = []; + + pollMsg[0] = `~~${pollMsg[0]}~~\n:no_entry: **THIS POLL IS ALREADY CLOSED** :no_entry:`; + pollMsg.pop(); // removing the message saying when the poll ends + pollMsg.pop(); // removing the note about how to vote + pollMsg.push('\n`This poll is closed.`'); + pollMsg.push('__**RESULTS:**__\n'); + + if (collected.size === 0) { + pollMsg.push('No one voted'); + } else { + pollResults.sort((v1, v2) => v2 - v1); + pollResults.forEach((value, key) => pollMsg.push(`${key}: ${value}`)); + } + + sentMsg.edit(pollMsg); + + pollEndedMsg.push('**Your poll has ended.**\n**Click this link to see the results:**'); + pollEndedMsg.push(`<${sentMsg.url}>`); + msg.reply(pollEndedMsg); + }) + .catch((error) => { + logger.error(error); + msg.reply('**`poll` error**: Something went wrong with your poll.'); + }); + } +}; diff --git a/commands/poll/poll.js b/commands/poll/poll.js index 1e14439..7398384 100644 --- a/commands/poll/poll.js +++ b/commands/poll/poll.js @@ -1,15 +1,12 @@ -const { Collection } = require('discord.js'); const Command = require('../../structures/Command.js'); -const allOptions = Object.values(require('../../assets/json/emoji-alphabet.json')); - module.exports = class PollCommand extends Command { constructor(client) { super(client, { name: 'poll', group: 'poll', memberName: 'poll', - description: 'Create a (useless) poll.', + description: 'Create a poll.', examples: ['`poll \'Which option you choose?\' \'option one\' \'option 2\' \'option N\'`'], argsSingleQuotes: true, argsPromptLimit: 0, diff --git a/commands/poll/tpoll.js b/commands/poll/tpoll.js index b3d383b..0167250 100644 --- a/commands/poll/tpoll.js +++ b/commands/poll/tpoll.js @@ -3,6 +3,11 @@ const Command = require('../../structures/Command.js'); const allOptions = Object.values(require('../../assets/json/emoji-alphabet.json')); +const logger = require('pino')({ + useLevelLabels: true, + timestamp: () => `,"time":"${new Date()}"`, +}); + module.exports = class TimedPollCommand extends Command { constructor(client) { super(client, { @@ -92,15 +97,11 @@ module.exports = class TimedPollCommand extends Command { if (voters.indexOf(user.id) < 0) { voters.push(user.id); } else { - // msg.channel.send(`ignoring ${reaction.emoji.name} from \`${user.username}\`: user already voted`) - // .then(m => m.delete(5000)); return false; } // do not count invalid reactions if (!reactions.includes(reaction.emoji.name)) { - // msg.channel.send(`\`${user.username}\` voided the vote with an invalid reaction: ${reaction.emoji.name}`) - // .then(m => m.delete(5000)); return false; } @@ -110,8 +111,6 @@ module.exports = class TimedPollCommand extends Command { pollResults.set(reaction.emoji.name, numVotes); - // msg.channel.send(`\`${user.username}\`'s vote: ${reaction.emoji.name}`) - // .then(m => m.delete(5000)); return true; }; @@ -138,9 +137,9 @@ module.exports = class TimedPollCommand extends Command { pollEndedMsg.push(`<${sentMsg.url}>`); msg.reply(pollEndedMsg); }) - .catch((collected) => { + .catch((error) => { + logger.error(error); msg.reply('**`poll` error**: Something went wrong with your poll.'); - console.error(collected); }); } };