From 4e1f83a30fe866696ff1e0ba64b77ba774041200 Mon Sep 17 00:00:00 2001 From: Daniel Odendahl Jr Date: Thu, 1 Jun 2017 18:31:20 +0000 Subject: [PATCH] Fix Everything --- .eslintrc.json | 137 +++++++++++++++++++ Shard.js | 4 +- XiaoBot.js | 31 ++--- commands/avataredit/3000-years.js | 4 +- commands/avataredit/beautiful.js | 4 +- commands/avataredit/bob-ross.js | 4 +- commands/avataredit/card.js | 16 +-- commands/avataredit/challenger.js | 4 +- commands/avataredit/dexter.js | 4 +- commands/avataredit/greyscale.js | 4 +- commands/avataredit/invert.js | 4 +- commands/avataredit/rip.js | 4 +- commands/avataredit/simba.js | 4 +- commands/avataredit/steam-card.js | 6 +- commands/avataredit/triggered.js | 8 +- commands/avataredit/wanted.js | 4 +- commands/games/battle.js | 188 ++++++++++---------------- commands/games/lottery.js | 7 +- commands/games/math-game.js | 20 ++- commands/games/quiz.js | 7 +- commands/games/rock-paper-scissors.js | 39 ++---- commands/games/typing-game.js | 14 +- commands/guildinfo/emoji.js | 8 +- commands/moderation/ban.js | 74 +++++----- commands/moderation/kick.js | 72 +++++----- commands/moderation/lockdown.js | 9 +- commands/moderation/prune.js | 7 +- commands/moderation/softban.js | 76 +++++------ commands/moderation/unban.js | 52 +++---- commands/moderation/warn.js | 62 ++++----- commands/numedit/currency.js | 18 +-- commands/numedit/temperature.js | 41 ++---- commands/random/easter-egg.js | 7 +- commands/random/horoscope.js | 7 +- commands/random/meme.js | 7 +- commands/random/soundboard.js | 24 ++-- commands/random/star.js | 7 +- commands/random/strawpoll.js | 22 +-- commands/randomimg/xkcd.js | 7 +- commands/response/name.js | 9 +- commands/search/anime.js | 4 +- commands/search/bot-info.js | 4 +- commands/search/bulbapedia.js | 4 +- commands/search/danbooru.js | 10 +- commands/search/define.js | 4 +- commands/search/discrim.js | 9 +- commands/search/forecast.js | 49 +++++-- commands/search/gelbooru.js | 30 ++-- commands/search/giphy.js | 4 +- commands/search/google.js | 8 +- commands/search/konachan.js | 10 +- commands/search/manga.js | 4 +- commands/search/map.js | 7 +- commands/search/neopet.js | 4 +- commands/search/osu.js | 4 +- commands/search/rule34.js | 10 +- commands/search/soundcloud.js | 4 +- commands/search/urban.js | 8 +- commands/search/wattpad.js | 8 +- commands/search/weather.js | 6 +- commands/search/wikipedia.js | 4 +- commands/search/youtube.js | 4 +- commands/search/yu-gi-oh.js | 4 +- commands/settings/clear-setting.js | 7 +- commands/settings/member-message.js | 16 +-- commands/settings/setting-list.js | 20 +-- commands/textedit/binary.js | 13 +- commands/textedit/cow-say.js | 7 +- commands/textedit/mocking.js | 32 +++++ commands/textedit/morse.js | 13 +- commands/textedit/pirate.js | 13 +- commands/textedit/repeat.js | 6 +- commands/textedit/reverse.js | 6 +- commands/textedit/temmie.js | 49 ++++--- commands/textedit/translate.js | 14 +- commands/textedit/upside-down.js | 6 +- commands/textedit/zalgo.js | 13 +- commands/userinfo/user-info.js | 8 +- commands/util/help.js | 10 +- commands/util/info.js | 6 +- commands/util/shard-info.js | 11 +- commands/util/uptime.js | 2 +- providers/Sequelize.js | 51 ++----- structures/PostgreSQL.js | 28 ++-- structures/Stats.js | 12 +- 85 files changed, 721 insertions(+), 851 deletions(-) create mode 100644 .eslintrc.json create mode 100644 commands/textedit/mocking.js diff --git a/.eslintrc.json b/.eslintrc.json new file mode 100644 index 00000000..45524993 --- /dev/null +++ b/.eslintrc.json @@ -0,0 +1,137 @@ +{ + "extends": "eslint:recommended", + "env": { + "node": true, + "es6": true + }, + "parserOptions": { + "ecmaVersion": 2017 + }, + "rules": { + "no-compare-neg-zero": "error", + "no-extra-parens": ["warn", "all", { + "nestedBinaryExpressions": false + }], + "no-template-curly-in-string": "error", + "no-unsafe-negation": "error", + + "accessor-pairs": "warn", + "array-callback-return": "error", + "complexity": "warn", + "consistent-return": "error", + "curly": ["error", "multi-line", "consistent"], + "dot-location": ["error", "property"], + "dot-notation": "error", + "eqeqeq": "error", + "no-empty-function": "error", + "no-floating-decimal": "error", + "no-implied-eval": "error", + "no-invalid-this": "error", + "no-lone-blocks": "error", + "no-multi-spaces": "error", + "no-new-func": "error", + "no-new-wrappers": "error", + "no-new": "error", + "no-octal-escape": "error", + "no-return-assign": "error", + "no-return-await": "error", + "no-self-compare": "error", + "no-sequences": "error", + "no-throw-literal": "error", + "no-unmodified-loop-condition": "error", + "no-unused-expressions": "error", + "no-useless-call": "error", + "no-useless-concat": "error", + "no-useless-escape": "error", + "no-useless-return": "error", + "no-void": "error", + "no-warning-comments": "warn", + "prefer-promise-reject-errors": "error", + "require-await": "warn", + "wrap-iife": "error", + "yoda": "error", + + "no-label-var": "error", + "no-shadow": "error", + "no-undef-init": "error", + + "callback-return": "error", + "handle-callback-err": "error", + "no-mixed-requires": "error", + "no-new-require": "error", + "no-path-concat": "error", + "no-console": 0, + + "array-bracket-spacing": "error", + "block-spacing": "error", + "brace-style": ["error", "1tbs", { "allowSingleLine": true }], + "capitalized-comments": ["error", "always", { "ignoreConsecutiveComments": true }], + "comma-dangle": "error", + "comma-spacing": "error", + "comma-style": "error", + "computed-property-spacing": "error", + "consistent-this": "error", + "eol-last": "error", + "func-names": "error", + "func-style": ["error", "declaration", { "allowArrowFunctions": true }], + "indent": ["error", 4, { "SwitchCase": 1 }], + "key-spacing": "error", + "keyword-spacing": ["error", { + "overrides": { + "if": { "after": true }, + "for": { "after": true }, + "while": { "after": true }, + "catch": { "after": true }, + "switch": { "after": true } + } + }], + "max-depth": ["error", 6], + "max-len": ["error", 120, 2], + "max-nested-callbacks": ["error", { "max": 4 }], + "max-statements-per-line": ["error", { "max": 2 }], + "new-cap": "error", + "newline-per-chained-call": ["error", { "ignoreChainWithDepth": 5 }], + "no-array-constructor": "error", + "no-bitwise": "warn", + "no-inline-comments": "error", + "no-multiple-empty-lines": ["error", { "max": 2, "maxEOF": 1, "maxBOF": 0 }], + "no-new-object": "error", + "no-spaced-func": "error", + "no-trailing-spaces": "error", + "no-unneeded-ternary": "error", + "no-whitespace-before-property": "error", + "nonblock-statement-body-position": "error", + "object-curly-newline": "error", + "object-curly-spacing": ["error", "always"], + "operator-assignment": "error", + "operator-linebreak": ["error", "after"], + "padded-blocks": ["error", "never"], + "quote-props": ["error", "as-needed"], + "quotes": ["error", "single", { "avoidEscape": true, "allowTemplateLiterals": true }], + "semi-spacing": "error", + "semi": "error", + "space-before-blocks": "error", + "space-before-function-paren": ["error", "never"], + "space-in-parens": "error", + "space-infix-ops": "error", + "space-unary-ops": "error", + "spaced-comment": "error", + "template-tag-spacing": "error", + "unicode-bom": "error", + + "arrow-body-style": "error", + "arrow-parens": ["error", "always"], + "arrow-spacing": "error", + "no-duplicate-imports": "error", + "no-useless-computed-key": "error", + "no-useless-constructor": "error", + "prefer-arrow-callback": "error", + "prefer-const": "error", + "prefer-rest-params": "error", + "prefer-spread": "error", + "prefer-template": "error", + "rest-spread-spacing": "error", + "template-curly-spacing": "error", + "yield-star-spacing": "error" + } +} diff --git a/Shard.js b/Shard.js index 27f711c9..eaab8bef 100644 --- a/Shard.js +++ b/Shard.js @@ -1,6 +1,4 @@ const { ShardingManager } = require('discord.js'); const { TOKEN } = process.env; -const Manager = new ShardingManager('./XiaoBot.js', { - token: TOKEN -}); +const Manager = new ShardingManager('./XiaoBot.js', { token: TOKEN }); Manager.spawn(2); diff --git a/XiaoBot.js b/XiaoBot.js index 20764b0e..b732a08a 100644 --- a/XiaoBot.js +++ b/XiaoBot.js @@ -52,14 +52,10 @@ client.on('warn', console.warn); client.on('commandError', (command, err) => console.error(command.name, err)); -client.dispatcher.addInhibitor(msg => { - if (msg.channel.type === 'dm') { - return false; - } +client.dispatcher.addInhibitor((msg) => { + if (msg.channel.type === 'dm') return false; const role = msg.guild.settings.get('singleRole'); - if (!msg.guild.roles.has(role) || msg.member.hasPermission('ADMINISTRATOR')) { - return false; - } + if (!msg.guild.roles.has(role) || msg.member.hasPermission('ADMINISTRATOR')) return false; if (!msg.member.roles.has(role)) { return ['singleRole', msg.reply(`Only the ${msg.guild.roles.get(role).name} role may use commands.`)]; } else { @@ -71,10 +67,9 @@ client.on('message', (msg) => { if (!msg.guild || !msg.guild.settings.get('inviteGuard')) return; if (/(discord(\.gg\/|app\.com\/invite\/|\.me\/))/gi.test(msg.content)) { if (msg.author.bot || msg.member.hasPermission('ADMINISTRATOR')) return; - if (msg.channel.permissionsFor(client.user).has(['SEND_MESSAGES', 'MANAGE_MESSAGES'])) { - msg.delete(); - return msg.reply('Invites are prohibited from being posted here.'); - } + if (!msg.channel.permissionsFor(client.user).has(['SEND_MESSAGES', 'MANAGE_MESSAGES'])) return; + msg.delete(); + msg.reply('Invites are prohibited from being posted here.'); } }); @@ -83,13 +78,13 @@ client.on('messageReactionAdd', (reaction, user) => { const { message } = reaction; const channel = message.guild.channels.get(message.guild.settings.get('starboard')); if (!channel) return; + if (!message.channel.permissionsFor(client.user).has(['SEND_MESSAGES', 'MANAGE_MESSAGES'])) return; if (user.id === message.author.id) { - if (message.channel.permissionsFor(client.user).has(['SEND_MESSAGES', 'MANAGE_MESSAGES'])) { - reaction.remove(user); - return message.reply('You cannot star your own messages, baka.'); - } else return; + reaction.remove(user); + message.reply('You cannot star your own messages, baka.'); + return; } - return client.registry.resolveCommand('random:star').run(message, { id: message.id }, true); + client.registry.resolveCommand('random:star').run(message, { id: message.id }, true); }); client.on('guildMemberAdd', (member) => { @@ -103,7 +98,7 @@ client.on('guildMemberAdd', (member) => { .replace(/()/gi, member.user.username) .replace(/()/gi, member.guild.name) .replace(/()/gi, member); - return channel.send(msg); + channel.send(msg); }); client.on('guildMemberRemove', (member) => { @@ -113,7 +108,7 @@ client.on('guildMemberRemove', (member) => { .replace(/()/gi, member.user.username) .replace(/()/gi, member.guild.name) .replace(/()/gi, member); - return channel.send(msg); + channel.send(msg); }); client.on('guildCreate', async (guild) => { diff --git a/commands/avataredit/3000-years.js b/commands/avataredit/3000-years.js index 0c98385d..f566cb2f 100644 --- a/commands/avataredit/3000-years.js +++ b/commands/avataredit/3000-years.js @@ -32,9 +32,7 @@ module.exports = class YearsCommand extends Command { async run(msg, args) { const user = args.user || msg.author; const avatarURL = user.avatarURL('png', 256); - if (!avatarURL) { - return msg.say('The User Provided has No Avatar.'); - } + if (!avatarURL) return msg.say('The User Provided has No Avatar.'); const Image = Canvas.Image; const canvas = new Canvas(856, 569); const ctx = canvas.getContext('2d'); diff --git a/commands/avataredit/beautiful.js b/commands/avataredit/beautiful.js index 0e2545f0..fd30bbaa 100644 --- a/commands/avataredit/beautiful.js +++ b/commands/avataredit/beautiful.js @@ -32,9 +32,7 @@ module.exports = class BeautifulCommand extends Command { async run(msg, args) { const user = args.user || msg.author; const avatarURL = user.avatarURL('png', 256); - if (!avatarURL) { - return msg.say('The User Provided has No Avatar.'); - } + if (!avatarURL) return msg.say('The User Provided has No Avatar.'); const Image = Canvas.Image; const canvas = new Canvas(500, 532); const ctx = canvas.getContext('2d'); diff --git a/commands/avataredit/bob-ross.js b/commands/avataredit/bob-ross.js index dacc29c3..8dd12b85 100644 --- a/commands/avataredit/bob-ross.js +++ b/commands/avataredit/bob-ross.js @@ -32,9 +32,7 @@ module.exports = class BobRossCommand extends Command { async run(msg, args) { const user = args.user || msg.author; const avatarURL = user.avatarURL('png', 256); - if (!avatarURL) { - return msg.say('The User Provided has No Avatar.'); - } + if (!avatarURL) return msg.say('The User Provided has No Avatar.'); const Image = Canvas.Image; const canvas = new Canvas(600, 775); const ctx = canvas.getContext('2d'); diff --git a/commands/avataredit/card.js b/commands/avataredit/card.js index 4a0c8c4c..e0292df6 100644 --- a/commands/avataredit/card.js +++ b/commands/avataredit/card.js @@ -35,20 +35,14 @@ module.exports = class CardCommand extends Command { async run(msg, args) { const member = args.member || msg.member; const avatarURL = member.user.avatarURL('png', 256); - if (!avatarURL) { - return msg.say('The User Provided has No Avatar.'); - } + if (!avatarURL) return msg.say('The User Provided has No Avatar.'); const cardID = Math.floor(Math.random() * (9999 - 1000 + 1)) + 1000; let rarity; - if (cardID < 5000) { - rarity = 'C'; - } else if (cardID < 8000) { - rarity = 'U'; - } else { - rarity = 'R'; - } + if (cardID < 5000) rarity = 'C'; + else if (cardID < 8000) rarity = 'U'; + else rarity = 'R'; const Image = Canvas.Image; - Canvas.registerFont(path.join(__dirname, '..', '..', 'assets', 'fonts', 'OpenSans.ttf'), { family: 'Open Sans' }); + Canvas.registerFont(path.join(__dirname, '..', '..', 'assets', 'fonts', 'OpenSans.ttf'), { family: 'Open Sans' }); // eslint-disable-line max-len const canvas = new Canvas(390, 544); const ctx = canvas.getContext('2d'); const base = new Image(); diff --git a/commands/avataredit/challenger.js b/commands/avataredit/challenger.js index f953e28f..89698a34 100644 --- a/commands/avataredit/challenger.js +++ b/commands/avataredit/challenger.js @@ -31,9 +31,7 @@ module.exports = class ChallengerCommand extends Command { async run(msg, args) { const user = args.user || msg.author; const avatarURL = user.avatarURL('png', 256); - if (!avatarURL) { - return msg.say('The User Provided has No Avatar.'); - } + if (!avatarURL) return msg.say('The User Provided has No Avatar.'); const Image = Canvas.Image; const canvas = new Canvas(500, 500); const ctx = canvas.getContext('2d'); diff --git a/commands/avataredit/dexter.js b/commands/avataredit/dexter.js index 60fd5537..8c708678 100644 --- a/commands/avataredit/dexter.js +++ b/commands/avataredit/dexter.js @@ -31,9 +31,7 @@ module.exports = class DexterCommand extends Command { async run(msg, args) { const user = args.user || msg.author; const avatarURL = user.avatarURL('png', 256); - if (!avatarURL) { - return msg.say('The User Provided has No Avatar.'); - } + if (!avatarURL) return msg.say('The User Provided has No Avatar.'); const Image = Canvas.Image; const canvas = new Canvas(744, 554); const ctx = canvas.getContext('2d'); diff --git a/commands/avataredit/greyscale.js b/commands/avataredit/greyscale.js index 53320c02..449ef2c2 100644 --- a/commands/avataredit/greyscale.js +++ b/commands/avataredit/greyscale.js @@ -29,9 +29,7 @@ module.exports = class GreyscaleCommand extends Command { async run(msg, args) { const user = args.user || msg.author; const avatarURL = user.avatarURL('png', 256); - if (!avatarURL) { - return msg.say('The User Provided has No Avatar.'); - } + if (!avatarURL) return msg.say('The User Provided has No Avatar.'); const Image = Canvas.Image; const canvas = new Canvas(256, 256); const ctx = canvas.getContext('2d'); diff --git a/commands/avataredit/invert.js b/commands/avataredit/invert.js index 86d2d9be..63efb9e0 100644 --- a/commands/avataredit/invert.js +++ b/commands/avataredit/invert.js @@ -28,9 +28,7 @@ module.exports = class InvertCommand extends Command { async run(msg, args) { const user = args.user || msg.author; const avatarURL = user.avatarURL('png', 256); - if (!avatarURL) { - return msg.say('The User Provided has No Avatar.'); - } + if (!avatarURL) return msg.say('The User Provided has No Avatar.'); const Image = Canvas.Image; const canvas = new Canvas(256, 256); const ctx = canvas.getContext('2d'); diff --git a/commands/avataredit/rip.js b/commands/avataredit/rip.js index 47fd2d9d..22328ef9 100644 --- a/commands/avataredit/rip.js +++ b/commands/avataredit/rip.js @@ -32,9 +32,7 @@ module.exports = class RIPCommand extends Command { async run(msg, args) { const user = args.user || msg.author; const avatarURL = user.avatarURL('png', 256); - if (!avatarURL) { - return msg.say('The User Provided has No Avatar.'); - } + if (!avatarURL) return msg.say('The User Provided has No Avatar.'); const Image = Canvas.Image; const canvas = new Canvas(507, 338); const ctx = canvas.getContext('2d'); diff --git a/commands/avataredit/simba.js b/commands/avataredit/simba.js index d1520c6b..d813153c 100644 --- a/commands/avataredit/simba.js +++ b/commands/avataredit/simba.js @@ -31,9 +31,7 @@ module.exports = class SimbaCommand extends Command { async run(msg, args) { const user = args.user || msg.author; const avatarURL = user.avatarURL('png', 256); - if (!avatarURL) { - return msg.say('The User Provided has No Avatar.'); - } + if (!avatarURL) return msg.say('The User Provided has No Avatar.'); const Image = Canvas.Image; const canvas = new Canvas(500, 281); const ctx = canvas.getContext('2d'); diff --git a/commands/avataredit/steam-card.js b/commands/avataredit/steam-card.js index 6da5be6b..4e42a210 100644 --- a/commands/avataredit/steam-card.js +++ b/commands/avataredit/steam-card.js @@ -31,11 +31,9 @@ module.exports = class SteamCardCommand extends Command { async run(msg, args) { const user = args.user || msg.author; const avatarURL = user.avatarURL('png', 512); - if (!avatarURL) { - return msg.say('The User Provided has No Avatar.'); - } + if (!avatarURL) return msg.say('The User Provided has No Avatar.'); const Image = Canvas.Image; - Canvas.registerFont(path.join(__dirname, '..', '..', 'assets', 'fonts', 'OpenSans.ttf'), { family: 'Open Sans' }); + Canvas.registerFont(path.join(__dirname, '..', '..', 'assets', 'fonts', 'OpenSans.ttf'), { family: 'Open Sans' }); // eslint-disable-line max-len const canvas = new Canvas(494, 568); const ctx = canvas.getContext('2d'); const base = new Image(); diff --git a/commands/avataredit/triggered.js b/commands/avataredit/triggered.js index 5a478bbb..e3fe663c 100644 --- a/commands/avataredit/triggered.js +++ b/commands/avataredit/triggered.js @@ -31,9 +31,7 @@ module.exports = class TriggeredCommand extends Command { async run(msg, args) { const user = args.user || msg.author; const avatarURL = user.avatarURL('png', 512); - if (!avatarURL) { - return msg.say('The User Provided has No Avatar.'); - } + if (!avatarURL) return msg.say('The User Provided has No Avatar.'); const Image = Canvas.Image; const canvas = new Canvas(320, 371); const ctx = canvas.getContext('2d'); @@ -45,9 +43,7 @@ module.exports = class TriggeredCommand extends Command { ctx.drawImage(avatar, 0, 0, 320, 320); const imgData = ctx.getImageData(0, 0, 320, 320); const { data } = imgData; - for (let i = 0; i < data.length; i += 4) { - data[i] = Math.max(255, data[i]); - } + for (let i = 0; i < data.length; i += 4) data[i] = Math.max(255, data[i]); ctx.putImageData(imgData, 0, 0); ctx.drawImage(base, 0, 0); }; diff --git a/commands/avataredit/wanted.js b/commands/avataredit/wanted.js index 6113ab4a..c84f7128 100644 --- a/commands/avataredit/wanted.js +++ b/commands/avataredit/wanted.js @@ -31,9 +31,7 @@ module.exports = class WantedCommand extends Command { async run(msg, args) { const user = args.user || msg.author; const avatarURL = user.avatarURL('png', 512); - if (!avatarURL) { - return msg.say('The User Provided has No Avatar.'); - } + if (!avatarURL) return msg.say('The User Provided has No Avatar.'); const Image = Canvas.Image; const canvas = new Canvas(741, 1000); const ctx = canvas.getContext('2d'); diff --git a/commands/games/battle.js b/commands/games/battle.js index e8d0179f..c3fc3766 100644 --- a/commands/games/battle.js +++ b/commands/games/battle.js @@ -22,17 +22,11 @@ module.exports = class BattleCommand extends Command { this.fighting = new Set(); } - async run(msg, args) { + async run(msg, args) { // eslint-disable-line complexity const { opponent } = args; - if (opponent.bot) { - return msg.say('Bots cannot be fought.'); - } - if (opponent.id === msg.author.id) { - return msg.say('You may not fight yourself.'); - } - if (this.fighting.has(msg.guild.id)) { - return msg.say('Only one fight may be occurring per server.'); - } + if (opponent.bot) return msg.say('Bots cannot be fought.'); + if (opponent.id === msg.author.id) return msg.say('You may not fight yourself.'); + if (this.fighting.has(msg.guild.id)) return msg.say('Only one fight may be occurring per server.'); this.fighting.add(msg.guild.id); await msg.say(`**${opponent.username}**, do you accept this challenge? **__Y__es** or **No**?`); try { @@ -41,117 +35,75 @@ module.exports = class BattleCommand extends Command { time: 15000, errors: ['time'] }); - if (['yes', 'y'].includes(verify.first().content.toLowerCase())) { - let userHP = 500; - let oppoHP = 500; - let userTurn = true; - let guard = false; - let userCure = true; - let oppoCure = true; - while (userHP > 0 && oppoHP > 0) { - const username = userTurn ? msg.author.username : opponent.username; - await msg.say(stripIndents` - **${username}**, do you **fight**, **guard**, **special**, **cure**, or **run**? - **${msg.author.username}**: ${userHP}HP - **${opponent.username}**: ${oppoHP}HP - `); - try { - const turn = await msg.channel.awaitMessages((res) => res.author.id === (userTurn ? msg.author.id : opponent.id), { - max: 1, - time: 15000, - errors: ['time'] - }); - const choice = turn.first().content.toLowerCase(); - if (choice === 'fight') { - const damage = Math.floor(Math.random() * (guard ? 10 : 100)) + 1; - await msg.say(`**${username}** deals **${damage}** damage!`); - if (userTurn) { - oppoHP = oppoHP - damage; - userTurn = false; - } else { - userHP = userHP - damage; - userTurn = true; - } - if (guard) { - guard = false; - } - } else if (choice === 'guard') { - await msg.say(`**${username}** guards!`); - guard = true; - if (userTurn) { - userTurn = false; - } else { - userTurn = true; - } - } else if (choice === 'special') { - const hit = Math.floor(Math.random() * 4) + 1; - if (hit === 1) { - const damage = Math.floor(Math.random() * ((guard ? 300 : 150) - 100 + 1) + 100); - await msg.say(`**${username}** deals **${damage}** damage!`); - if (userTurn) { - oppoHP = oppoHP - damage; - userTurn = false; - } else { - userHP = userHP - damage; - userTurn = true; - } - if (guard) { - guard = false; - } - } else { - await msg.say(`**${username}**'s attack missed!`); - if (userTurn) { - userTurn = false; - } else { - userTurn = true; - } - if (guard) { - guard = false; - } - } - } else if (choice === 'cure') { - if (userTurn ? userCure : oppoCure) { - await msg.say(`**${username}** regains **250** health!`); - if (userTurn) { - userHP = userHP + 250; - userCure = false; - userTurn = false; - } else { - oppoHP = oppoHP + 250; - oppoCure = false; - userTurn = true; - } - if (guard) { - guard = false; - } - } else { - await msg.say('You have already cured!'); - } - } else if (choice === 'run') { - await msg.say(`**${username}** flees!`); - if (userTurn) { - userHP = 0; - } else { - oppoHP = 0; - } - } else { - await msg.say('I do not understand what you want to do.'); - } - } catch (err) { - await msg.say('Time!'); - break; - } - } - this.fighting.delete(msg.guild.id); - return msg.say(stripIndents` - The match is over! - **Winner: ${userHP > oppoHP ? `${msg.author.username}** (${userHP}HP)` : `${opponent.username}** (${oppoHP}HP)`} - **Loser: ${userHP > oppoHP ? `${opponent.username}** (${oppoHP}HP)` : `${msg.author.username}** (${userHP}HP)`} - `); - } else { + if (!['yes', 'y'].includes(verify.first().content.toLowerCase())) { this.fighting.delete(msg.guild.id); return msg.say('Guess that was a no then...'); } + let userHP = 500; + let oppoHP = 500; + let userTurn = false; + let guard = false; + const reset = () => { + if (userTurn) userTurn = false; + else userTurn = true; + if (guard) guard = false; + }; + const dealDamage = (damage) => { + if (userTurn) userHP += damage; + else oppoHP += damage; + }; + while (userHP > 0 && oppoHP > 0) { // eslint-disable-line no-unmodified-loop-condition + const username = userTurn ? msg.author.username : opponent.username; + const id = userTurn ? msg.author.id : opponent.id; + await msg.say(stripIndents` + **${username}**, do you **fight**, **guard**, **special**, or **run**? + **${msg.author.username}**: ${userHP}HP + **${opponent.username}**: ${oppoHP}HP + `); + try { + const turn = await msg.channel.awaitMessages((res) => res.author.id === id, { + max: 1, + time: 15000, + errors: ['time'] + }); + const choice = turn.first().content.toLowerCase(); + if (choice === 'fight') { + const damage = Math.floor(Math.random() * (guard ? 10 : 100)) + 1; + await msg.say(`**${username}** deals **${damage}** damage!`); + dealDamage(damage); + reset(); + } else if (choice === 'guard') { + await msg.say(`**${username}** guards!`); + reset(); + guard = true; + } else if (choice === 'special') { + const hit = Math.floor(Math.random() * 4) + 1; + if (hit === 1) { + const damage = Math.floor(Math.random() * ((guard ? 300 : 150) - 100 + 1) + 100); + await msg.say(`**${username}** deals **${damage}** damage!`); + dealDamage(damage); + reset(); + } else { + await msg.say(`**${username}**'s attack missed!`); + reset(); + } + } else if (choice === 'run') { + await msg.say(`**${username}** flees!`); + dealDamage(500 - (userTurn ? userHP : oppoHP)); + } else { + await msg.say('I do not understand what you want to do.'); + } + } catch (err) { + await msg.say('Time!'); + break; + } + } + this.fighting.delete(msg.guild.id); + return msg.say(stripIndents` + The match is over! + **Winner:** ${userHP > oppoHP ? msg.author.username : opponent.username} + **Loser:** ${userHP > oppoHP ? opponent.username : msg.author.username} + `); } catch (err) { this.fighting.delete(msg.guild.id); return msg.say('Looks like they declined...'); diff --git a/commands/games/lottery.js b/commands/games/lottery.js index 2786287a..1f9447a5 100644 --- a/commands/games/lottery.js +++ b/commands/games/lottery.js @@ -12,10 +12,7 @@ module.exports = class LotteryCommand extends Command { run(msg) { const lottery = Math.floor(Math.random() * 100) + 1; - if (lottery === 1) { - return msg.say(`Wow ${msg.author.username}! You actually won! Great job!`); - } else { - return msg.say(`Nope, sorry ${msg.author.username}, you lost.`); - } + if (lottery === 1) return msg.say(`Wow ${msg.author.username}! You actually won! Great job!`); + else return msg.say(`Nope, sorry ${msg.author.username}, you lost.`); } }; diff --git a/commands/games/math-game.js b/commands/games/math-game.js index b1683afe..47c7a0ee 100644 --- a/commands/games/math-game.js +++ b/commands/games/math-game.js @@ -17,11 +17,8 @@ module.exports = class MathGameCommand extends Command { prompt: `What should the difficulty of the game be? One of: ${difficulties.join(', ')}`, type: 'string', validate: (difficulty) => { - if (difficulties.includes(difficulty.toLowerCase())) { - return true; - } else { - return `The difficulty must be one of: ${difficulties.join(', ')}`; - } + if (difficulties.includes(difficulty.toLowerCase())) return true; + else return `The difficulty must be one of: ${difficulties.join(', ')}`; }, parse: (difficulty) => difficulty.toLowerCase() } @@ -32,8 +29,10 @@ module.exports = class MathGameCommand extends Command { async run(msg, args) { const { difficulty } = args; const operation = operations[Math.floor(Math.random() * operations.length)]; - const value = maxValues[difficulty]; - const expression = `${Math.floor(Math.random() * value) + 1} ${operation} ${Math.floor(Math.random() * value) + 1}`; + const maxValue = maxValues[difficulty]; + const value1 = Math.floor(Math.random() * maxValue) + 1; + const value2 = Math.floor(Math.random() * maxValue) + 1; + const expression = `${value1} ${operation} ${value2}`; const answer = math.eval(expression).toString(); const embed = new RichEmbed() .setTitle('You have 10 seconds to answer:') @@ -45,11 +44,8 @@ module.exports = class MathGameCommand extends Command { time: 10000, errors: ['time'] }); - if (collected.first().content !== answer) { - return msg.say(`Nope, sorry, it's ${answer}.`); - } else { - return msg.say('Nice job! 10/10! You deserve some cake!'); - } + if (collected.first().content !== answer) return msg.say(`Nope, sorry, it's ${answer}.`); + else return msg.say('Nice job! 10/10! You deserve some cake!'); } catch (err) { return msg.say(`Time! It was ${answer}, sorry!`); } diff --git a/commands/games/quiz.js b/commands/games/quiz.js index 9dcd9986..ca0a6f53 100644 --- a/commands/games/quiz.js +++ b/commands/games/quiz.js @@ -37,11 +37,8 @@ module.exports = class QuizCommand extends Command { time: 15000, errors: ['time'] }); - if (collected.first().content.toLowerCase() !== answer) { - return msg.say(`Nope, sorry, it's ${answer}.`); - } else { - return msg.say('Nice job! 10/10! You deserve some cake!'); - } + if (collected.first().content.toLowerCase() !== answer) return msg.say(`Nope, sorry, it's ${answer}.`); + else return msg.say('Nice job! 10/10! You deserve some cake!'); } catch (err) { return msg.say(`Time! It was ${answer}, sorry!`); } diff --git a/commands/games/rock-paper-scissors.js b/commands/games/rock-paper-scissors.js index 93ac185d..c479dc99 100644 --- a/commands/games/rock-paper-scissors.js +++ b/commands/games/rock-paper-scissors.js @@ -14,13 +14,6 @@ module.exports = class RockPaperScissorsCommand extends Command { key: 'choice', prompt: '`Rock`, `Paper`, or `Scissors`?', type: 'string', - validate: (choice) => { - if (choices.includes(choice.toLowerCase())) { - return true; - } else { - return 'Please enter either `rock`, `paper`, or `scissors`.'; - } - }, parse: (choice) => choice.toLowerCase() } ] @@ -31,29 +24,19 @@ module.exports = class RockPaperScissorsCommand extends Command { const { choice } = args; const response = choices[Math.floor(Math.random() * choices.length)]; if (choice === 'rock') { - if (response === 'rock') { - return msg.say('Rock! Aw... A tie...'); - } else if (response === 'paper') { - return msg.say('Paper! Yes! I win!'); - } else if (response === 'scissors') { - return msg.say('Scissors! Aw... I lose...'); - } + if (response === 'rock') return msg.say('Rock! Aw... A tie...'); + else if (response === 'paper') return msg.say('Paper! Yes! I win!'); + else return msg.say('Scissors! Aw... I lose...'); } else if (choice === 'paper') { - if (response === 'rock') { - return msg.say('Rock! Aw... I lose...'); - } else if (response === 'paper') { - return msg.say('Paper! Aw... A tie...'); - } else if (response === 'scissors') { - return msg.say('Scissors! Yes! I win!'); - } + if (response === 'rock') return msg.say('Rock! Aw... I lose...'); + else if (response === 'paper') return msg.say('Paper! Aw... A tie...'); + else return msg.say('Scissors! Yes! I win!'); } else if (choice === 'scissors') { - if (response === 'rock') { - return msg.say('Rock! Yes! I win!'); - } else if (response === 'paper') { - return msg.say('Paper! Aw... I lose...'); - } else if (response === 'scissors') { - return msg.say('Scissors! Aw... A tie...'); - } + if (response === 'rock') return msg.say('Rock! Yes! I win!'); + else if (response === 'paper') return msg.say('Paper! Aw... I lose...'); + else return msg.say('Scissors! Aw... A tie...'); + } else { + return msg.say('I win by default, you little cheater.'); } } }; diff --git a/commands/games/typing-game.js b/commands/games/typing-game.js index 26bdda75..77b29d67 100644 --- a/commands/games/typing-game.js +++ b/commands/games/typing-game.js @@ -16,11 +16,8 @@ module.exports = class TypingGameCommand extends Command { prompt: `What should the difficulty of the game be? One of: ${difficulties.join(', ')}`, type: 'string', validate: (difficulty) => { - if (difficulties.includes(difficulty.toLowerCase())) { - return true; - } else { - return `The difficulty must be one of: ${difficulties.join(', ')}`; - } + if (difficulties.includes(difficulty.toLowerCase())) return true; + else return `The difficulty must be one of: ${difficulties.join(', ')}`; }, parse: (difficulty) => difficulty.toLowerCase() } @@ -42,11 +39,8 @@ module.exports = class TypingGameCommand extends Command { time: time, errors: ['time'] }); - if (collected.first().content !== sentence) { - return msg.say('Nope, sorry!'); - } else { - return msg.say('Nice job! 10/10! You deserve some cake!'); - } + if (collected.first().content !== sentence) return msg.say('Nope, sorry!'); + else return msg.say('Nice job! 10/10! You deserve some cake!'); } catch (err) { return msg.say('Time! Sorry!'); } diff --git a/commands/guildinfo/emoji.js b/commands/guildinfo/emoji.js index abb7cac3..b31342c3 100644 --- a/commands/guildinfo/emoji.js +++ b/commands/guildinfo/emoji.js @@ -12,10 +12,8 @@ module.exports = class EmojiCommand extends Command { } run(msg) { - const emoji = msg.guild.emojis; - if (!emoji.size) { - return msg.say('You have no Custom Emoji.'); - } - return msg.say(emoji.map((e) => e).join('')); + const emojis = msg.guild.emojis; + if (!emojis.size) return msg.say('You have no Custom Emoji.'); + return msg.say(emojis.map((emoji) => emoji).join('')); } }; diff --git a/commands/moderation/ban.js b/commands/moderation/ban.js index 4013ffc6..8412705d 100644 --- a/commands/moderation/ban.js +++ b/commands/moderation/ban.js @@ -24,11 +24,8 @@ module.exports = class BanCommand extends Command { prompt: 'What do you want to set the reason as?', type: 'string', validate: (reason) => { - if (reason.length < 140) { - return true; - } else { - return 'Invalid Reason. Reason must be under 140 characters.'; - } + if (reason.length < 140) return true; + else return 'Reason must be under 140 characters.'; } } ] @@ -38,9 +35,7 @@ module.exports = class BanCommand extends Command { async run(msg, args) { const modlogs = msg.guild.channels.get(msg.guild.settings.get('modLog')); const { member, reason } = args; - if (!member.bannable) { - return msg.say('This member is not bannable. Perhaps they have a higher role than me?'); - } + if (!member.bannable) return msg.say('This member is not bannable. Perhaps they have a higher role than me?'); try { await msg.say(`Are you sure you want to ban ${member.user.tag} (${member.id})?`); const collected = await msg.channel.awaitMessages((res) => res.author.id === msg.author.id, { @@ -48,43 +43,40 @@ module.exports = class BanCommand extends Command { time: 15000, errors: ['time'] }); - if (['y', 'yes'].includes(collected.first().content.toLowerCase())) { - try { - await member.user.send(stripIndents` - You were banned from ${msg.guild.name}! - Reason: ${reason} - `); - } catch (err) { - await msg.say('Failed to Send DM.'); - } - await member.ban({ - days: 7, - reason: `${msg.author.tag}: ${reason}` - }); - await msg.say(`Successfully banned ${member.user.tag}.`); - if (!modlogs || !modlogs.permissionsFor(this.client.user.has('SEND_MESSAGES'))) { - return msg.say('Could not log the ban to the mod logs.'); - } else if (!modlogs.permissionsFor(this.client.user).has('EMBED_LINKS')) { - return modlogs.send(stripIndents` + if (!['y', 'yes'].includes(collected.first().content.toLowerCase())) return msg.say('Aborting Ban.'); + try { + await member.user.send(stripIndents` + You were banned from ${msg.guild.name}! + Reason: ${reason} + `); + } catch (err) { + await msg.say('Failed to Send DM.'); + } + await member.ban({ + days: 7, + reason: `${msg.author.tag}: ${reason}` + }); + await msg.say(`Successfully banned ${member.user.tag}.`); + if (!modlogs || !modlogs.permissionsFor(this.client.user.has('SEND_MESSAGES'))) { + return msg.say('Could not log the ban to the mod logs.'); + } else if (!modlogs.permissionsFor(this.client.user).has('EMBED_LINKS')) { + return modlogs.send(stripIndents` + **Member:** ${member.user.tag} (${member.id}) + **Action:** Ban + **Reason:** ${reason} + **Moderator:** ${msg.author.tag} + `); + } else { + const embed = new RichEmbed() + .setAuthor(msg.author.tag, msg.author.displayAvatarURL) + .setColor(0xFF0000) + .setTimestamp() + .setDescription(stripIndents` **Member:** ${member.user.tag} (${member.id}) **Action:** Ban **Reason:** ${reason} - **Moderator:** ${msg.author.tag} `); - } else { - const embed = new RichEmbed() - .setAuthor(msg.author.tag, msg.author.displayAvatarURL) - .setColor(0xFF0000) - .setTimestamp() - .setDescription(stripIndents` - **Member:** ${member.user.tag} (${member.id}) - **Action:** Ban - **Reason:** ${reason} - `); - return modlogs.send({ embed }); - } - } else { - return msg.say('Aborting Ban.'); + return modlogs.send({ embed }); } } catch (err) { return msg.say('Aborting Ban.'); diff --git a/commands/moderation/kick.js b/commands/moderation/kick.js index bbbbfd79..5adf1732 100644 --- a/commands/moderation/kick.js +++ b/commands/moderation/kick.js @@ -23,12 +23,9 @@ module.exports = class KickCommand extends Command { key: 'reason', prompt: 'What do you want to set the reason as?', type: 'string', - validate: reason => { - if (reason.length < 140) { - return true; - } else { - return 'Invalid Reason. Reason must be under 140 characters.'; - } + validate: (reason) => { + if (reason.length < 140) return true; + else return 'Reason must be under 140 characters.'; } } ] @@ -38,9 +35,7 @@ module.exports = class KickCommand extends Command { async run(msg, args) { const modlogs = msg.guild.channels.get(msg.guild.settings.get('modLog')); const { member, reason } = args; - if (!member.kickable) { - return msg.say('This member is not kickable. Perhaps they have a higher role than me?'); - } + if (!member.kickable) return msg.say('This member is not kickable. Perhaps they have a higher role than me?'); try { await msg.say(`Are you sure you want to kick ${member.user.tag} (${member.id})?`); const collected = await msg.channel.awaitMessages((res) => res.author.id === msg.author.id, { @@ -48,42 +43,37 @@ module.exports = class KickCommand extends Command { time: 15000, errors: ['time'] }); - if (['y', 'yes'].includes(collected.first().content.toLowerCase())) { - try { - await member.user.send(stripIndents` - You were kicked from ${msg.guild.name}! - Reason: ${reason} - `); - } catch (err) { - await msg.say('Failed to Send DM.'); - } - await member.kick({ - reason: `${msg.author.tag}: ${reason}` - }); - await msg.say(`Successfully kicked ${member.user.tag}.`); - if (!modlogs || !modlogs.permissionsFor(this.client.user.has('SEND_MESSAGES'))) { - return msg.say('Could not log the kick to the mod logs.'); - } else if (!modlogs.permissionsFor(this.client.user).has('EMBED_LINKS')) { - return modlogs.send(stripIndents` + if (!['y', 'yes'].includes(collected.first().content.toLowerCase())) return msg.say('Aborting Kick.'); + try { + await member.user.send(stripIndents` + You were kicked from ${msg.guild.name}! + Reason: ${reason} + `); + } catch (err) { + await msg.say('Failed to Send DM.'); + } + await member.kick({ reason: `${msg.author.tag}: ${reason}` }); + await msg.say(`Successfully kicked ${member.user.tag}.`); + if (!modlogs || !modlogs.permissionsFor(this.client.user.has('SEND_MESSAGES'))) { + return msg.say('Could not log the kick to the mod logs.'); + } else if (!modlogs.permissionsFor(this.client.user).has('EMBED_LINKS')) { + return modlogs.send(stripIndents` + **Member:** ${member.user.tag} (${member.id}) + **Action:** Kick + **Reason:** ${reason} + **Moderator:** ${msg.author.tag} + `); + } else { + const embed = new RichEmbed() + .setAuthor(msg.author.tag, msg.author.displayAvatarURL) + .setColor(0xFFA500) + .setTimestamp() + .setDescription(stripIndents` **Member:** ${member.user.tag} (${member.id}) **Action:** Kick **Reason:** ${reason} - **Moderator:** ${msg.author.tag} `); - } else { - const embed = new RichEmbed() - .setAuthor(msg.author.tag, msg.author.displayAvatarURL) - .setColor(0xFFA500) - .setTimestamp() - .setDescription(stripIndents` - **Member:** ${member.user.tag} (${member.id}) - **Action:** Kick - **Reason:** ${reason} - `); - return modlogs.send({ embed }); - } - } else { - return msg.say('Aborting Kick.'); + return modlogs.send({ embed }); } } catch (err) { return msg.say('Aborting Kick.'); diff --git a/commands/moderation/lockdown.js b/commands/moderation/lockdown.js index b635242f..ac9f43a4 100644 --- a/commands/moderation/lockdown.js +++ b/commands/moderation/lockdown.js @@ -18,11 +18,8 @@ module.exports = class LockdownCommand extends Command { type: 'string', default: 'start', validate: (type) => { - if (['start', 'stop'].includes(type.toLowerCase())) { - return true; - } else { - return 'Please enter either `start` or `stop`.'; - } + if (['start', 'stop'].includes(type.toLowerCase())) return true; + else return 'Please enter either `start` or `stop`.'; }, parse: (type) => type.toLowerCase() } @@ -38,7 +35,7 @@ module.exports = class LockdownCommand extends Command { Lockdown Started, users without Administrator can no longer post messages. Please use \`lockdown stop\` to end the lockdown. `); - } else if (type === 'stop') { + } else { await msg.channel.overwritePermissions(msg.guild.defaultRole, { SEND_MESSAGES: null }); return msg.say('Lockdown Ended.'); } diff --git a/commands/moderation/prune.js b/commands/moderation/prune.js index 2da4c312..d62785d3 100644 --- a/commands/moderation/prune.js +++ b/commands/moderation/prune.js @@ -21,11 +21,8 @@ module.exports = class PruneCommand extends Command { prompt: 'How many messages do you want to delete? Limit of up to 99.', type: 'integer', validate: (count) => { - if (count < 100 && count > 0) { - return true; - } else { - return 'Invalid Count. Count must be from 1-99.'; - } + if (count < 100 && count > 0) return true; + else return 'Count must be from 1-99.'; } } ] diff --git a/commands/moderation/softban.js b/commands/moderation/softban.js index 48c78b6c..8f79dcc8 100644 --- a/commands/moderation/softban.js +++ b/commands/moderation/softban.js @@ -24,11 +24,8 @@ module.exports = class SoftbanCommand extends Command { prompt: 'What do you want to set the reason as?', type: 'string', validate: (reason) => { - if (reason.length < 140) { - return true; - } else { - return 'Invalid Reason. Reason must be under 140 characters.'; - } + if (reason.length < 140) return true; + else return 'Reason must be under 140 characters.'; } } ] @@ -38,9 +35,7 @@ module.exports = class SoftbanCommand extends Command { async run(msg, args) { const modlogs = msg.guild.channels.get(msg.guild.settings.get('modLog')); const { member, reason } = args; - if (!member.bannable) { - return msg.say('This member is not softbannable. Perhaps they have a higher role than me?'); - } + if (!member.bannable) return msg.say('This member is not bannable. Perhaps they have a higher role than me?'); try { await msg.say(`Are you sure you want to softban ${member.user.tag} (${member.id})?`); const collected = await msg.channel.awaitMessages((res) => res.author.id === msg.author.id, { @@ -48,44 +43,41 @@ module.exports = class SoftbanCommand extends Command { time: 15000, errors: ['time'] }); - if (['y', 'yes'].includes(collected.first().content.toLowerCase())) { - try { - await member.user.send(stripIndents` - You were softbanned from ${msg.guild.name}! - Reason: ${reason} - `); - } catch (err) { - await msg.say('Failed to Send DM.'); - } - await member.ban({ - days: 7, - reason: `${msg.author.tag}: ${reason} (Softban)` - }); - await msg.guild.unban(member.user, 'Softban'); - await msg.say(`Successfully softbanned ${member.user.tag}.`); - if (!modlogs || !modlogs.permissionsFor(this.client.user.has('SEND_MESSAGES'))) { - return msg.say('Could not log the softban to the mod logs.'); - } else if (!modlogs.permissionsFor(this.client.user).has('EMBED_LINKS')) { - return modlogs.send(stripIndents` + if (!['y', 'yes'].includes(collected.first().content.toLowerCase())) return msg.say('Aborting Softban.'); + try { + await member.user.send(stripIndents` + You were softbanned from ${msg.guild.name}! + Reason: ${reason} + `); + } catch (err) { + await msg.say('Failed to Send DM.'); + } + await member.ban({ + days: 7, + reason: `${msg.author.tag}: ${reason} (Softban)` + }); + await msg.guild.unban(member.user, 'Softban'); + await msg.say(`Successfully softbanned ${member.user.tag}.`); + if (!modlogs || !modlogs.permissionsFor(this.client.user.has('SEND_MESSAGES'))) { + return msg.say('Could not log the softban to the mod logs.'); + } else if (!modlogs.permissionsFor(this.client.user).has('EMBED_LINKS')) { + return modlogs.send(stripIndents` + **Member:** ${member.user.tag} (${member.id}) + **Action:** Softban + **Reason:** ${reason} + **Moderator:** ${msg.author.tag} + `); + } else { + const embed = new RichEmbed() + .setAuthor(msg.author.tag, msg.author.displayAvatarURL) + .setColor(0xFF4500) + .setTimestamp() + .setDescription(stripIndents` **Member:** ${member.user.tag} (${member.id}) **Action:** Softban **Reason:** ${reason} - **Moderator:** ${msg.author.tag} `); - } else { - const embed = new RichEmbed() - .setAuthor(msg.author.tag, msg.author.displayAvatarURL) - .setColor(0xFF4500) - .setTimestamp() - .setDescription(stripIndents` - **Member:** ${member.user.tag} (${member.id}) - **Action:** Softban - **Reason:** ${reason} - `); - return modlogs.send({ embed }); - } - } else { - return msg.say('Aborting Softban.'); + return modlogs.send({ embed }); } } catch (err) { return msg.say('Aborting Softban.'); diff --git a/commands/moderation/unban.js b/commands/moderation/unban.js index 37086306..019efdc1 100644 --- a/commands/moderation/unban.js +++ b/commands/moderation/unban.js @@ -24,11 +24,8 @@ module.exports = class UnbanCommand extends Command { prompt: 'What do you want to set the reason as?', type: 'string', validate: (reason) => { - if (reason.length < 140) { - return true; - } else { - return 'Invalid Reason. Reason must be under 140 characters.'; - } + if (reason.length < 140) return true; + else return 'Reason must be under 140 characters.'; } } ] @@ -39,9 +36,7 @@ module.exports = class UnbanCommand extends Command { const modlogs = msg.guild.channels.get(msg.guild.settings.get('modLog')); const { id, reason } = args; const bans = await msg.guild.fetchBans(); - if (!bans.has(id)) { - return msg.say('This ID is not in the Guild Banlist.'); - } + if (!bans.has(id)) return msg.say('This ID is not in the Guild Banlist.'); const member = bans.get(id).user; try { await msg.say(`Are you sure you want to unban ${member.tag} (${member.id})?`); @@ -50,32 +45,29 @@ module.exports = class UnbanCommand extends Command { time: 15000, errors: ['time'] }); - if (['y', 'yes'].includes(collected.first().content.toLowerCase())) { - await msg.guild.unban(member, `${msg.author.tag}: ${reason}`); - await msg.say(`Successfully unbanned ${member.user.tag}.`); - if (!modlogs || !modlogs.permissionsFor(this.client.user.has('SEND_MESSAGES'))) { - return msg.say('Could not log the unban to the mod logs.'); - } else if (!modlogs.permissionsFor(this.client.user).has('EMBED_LINKS')) { - return modlogs.send(stripIndents` + if (!['y', 'yes'].includes(collected.first().content.toLowerCase())) return msg.say('Aborting Unban.'); + await msg.guild.unban(member, `${msg.author.tag}: ${reason}`); + await msg.say(`Successfully unbanned ${member.user.tag}.`); + if (!modlogs || !modlogs.permissionsFor(this.client.user.has('SEND_MESSAGES'))) { + return msg.say('Could not log the unban to the mod logs.'); + } else if (!modlogs.permissionsFor(this.client.user).has('EMBED_LINKS')) { + return modlogs.send(stripIndents` + **Member:** ${member.tag} (${member.id}) + **Action:** Unban + **Reason:** ${reason} + **Moderator:** ${msg.author.tag} + `); + } else { + const embed = new RichEmbed() + .setAuthor(msg.author.tag, msg.author.displayAvatarURL) + .setColor(0x00AE86) + .setTimestamp() + .setDescription(stripIndents` **Member:** ${member.tag} (${member.id}) **Action:** Unban **Reason:** ${reason} - **Moderator:** ${msg.author.tag} `); - } else { - const embed = new RichEmbed() - .setAuthor(msg.author.tag, msg.author.displayAvatarURL) - .setColor(0x00AE86) - .setTimestamp() - .setDescription(stripIndents` - **Member:** ${member.tag} (${member.id}) - **Action:** Unban - **Reason:** ${reason} - `); - return modlogs.send({ embed }); - } - } else { - return msg.say('Aborting Unban.'); + return modlogs.send({ embed }); } } catch (err) { return msg.say('Aborting Unban.'); diff --git a/commands/moderation/warn.js b/commands/moderation/warn.js index 35d3077b..fc89dce0 100644 --- a/commands/moderation/warn.js +++ b/commands/moderation/warn.js @@ -23,11 +23,8 @@ module.exports = class WarnCommand extends Command { prompt: 'What do you want to set the reason as?', type: 'string', validate: (reason) => { - if (reason.length < 140) { - return true; - } else { - return 'Invalid Reason. Reason must be under 140 characters.'; - } + if (reason.length < 140) return true; + else return 'Invalid Reason. Reason must be under 140 characters.'; } } ] @@ -44,39 +41,36 @@ module.exports = class WarnCommand extends Command { time: 15000, errors: ['time'] }); - if (['y', 'yes'].includes(collected.first().content.toLowerCase())) { - try { - await member.user.send(stripIndents` - You were warned in ${msg.guild.name}! - Reason: ${reason} - `); - } catch (err) { - await msg.say('Failed to Send DM.'); - } - await msg.say(`Successfully warned ${member.user.tag}.`); - if (!modlogs || !modlogs.permissionsFor(this.client.user.has('SEND_MESSAGES'))) { - return msg.say('Could not log the warn to the mod logs.'); - } else if (!modlogs.permissionsFor(this.client.user).has('EMBED_LINKS')) { - return modlogs.send(stripIndents` + if (!['y', 'yes'].includes(collected.first().content.toLowerCase())) return msg.say('Aborting Warn.'); + try { + await member.user.send(stripIndents` + You were warned in ${msg.guild.name}! + Reason: ${reason} + `); + } catch (err) { + await msg.say('Failed to Send DM.'); + } + await msg.say(`Successfully warned ${member.user.tag}.`); + if (!modlogs || !modlogs.permissionsFor(this.client.user.has('SEND_MESSAGES'))) { + return msg.say('Could not log the warn to the mod logs.'); + } else if (!modlogs.permissionsFor(this.client.user).has('EMBED_LINKS')) { + return modlogs.send(stripIndents` + **Member:** ${member.user.tag} (${member.id}) + **Action:** Warn + **Reason:** ${reason} + **Moderator:** ${msg.author.tag} + `); + } else { + const embed = new RichEmbed() + .setAuthor(msg.author.tag, msg.author.displayAvatarURL) + .setColor(0xFFFF00) + .setTimestamp() + .setDescription(stripIndents` **Member:** ${member.user.tag} (${member.id}) **Action:** Warn **Reason:** ${reason} - **Moderator:** ${msg.author.tag} `); - } else { - const embed = new RichEmbed() - .setAuthor(msg.author.tag, msg.author.displayAvatarURL) - .setColor(0xFFFF00) - .setTimestamp() - .setDescription(stripIndents` - **Member:** ${member.user.tag} (${member.id}) - **Action:** Warn - **Reason:** ${reason} - `); - return modlogs.send({ embed }); - } - } else { - return msg.say('Aborting Warn.'); + return modlogs.send({ embed }); } } catch (err) { return msg.say('Aborting Warn.'); diff --git a/commands/numedit/currency.js b/commands/numedit/currency.js index 8e88591c..e22701bb 100644 --- a/commands/numedit/currency.js +++ b/commands/numedit/currency.js @@ -16,11 +16,8 @@ module.exports = class CurrencyCommand extends Command { prompt: 'What currency code do you want to use as the base?', type: 'string', validate: (base) => { - if (codes.includes(base.toUpperCase())) { - return true; - } else { - return 'Invalid Currency Code. Use `help currency` to view a list of currency codes.'; - } + if (codes.includes(base.toUpperCase())) return true; + else return 'Invalid Currency Code. Use `help currency` to view a list of currency codes.'; }, parse: (base) => base.toUpperCase() }, @@ -29,11 +26,8 @@ module.exports = class CurrencyCommand extends Command { prompt: 'What currency code do you want to convert to?', type: 'string', validate: (to) => { - if (codes.includes(to.toUpperCase())) { - return true; - } else { - return 'Invalid Currency Code. Use `help currency` to view a list of currency codes.'; - } + if (codes.includes(to.toUpperCase())) return true; + else return 'Invalid Currency Code. Use `help currency` to view a list of currency codes.'; }, parse: (to) => to.toUpperCase() }, @@ -48,9 +42,7 @@ module.exports = class CurrencyCommand extends Command { async run(msg, args) { const { base, to, amount } = args; - if (base === to) { - return msg.say(`Converting ${base} to ${to} is the same value, dummy.`); - } + if (base === to) return msg.say(`Converting ${base} to ${to} is the same value, dummy.`); const { body } = await snekfetch .get('http://api.fixer.io/latest') .query({ diff --git a/commands/numedit/temperature.js b/commands/numedit/temperature.js index 94a29b7e..d8df8516 100644 --- a/commands/numedit/temperature.js +++ b/commands/numedit/temperature.js @@ -13,11 +13,8 @@ module.exports = class TemperatureCommand extends Command { prompt: 'What temperature unit do you want to use as the base?', type: 'string', validate: (base) => { - if (['celsius', 'fahrenheit', 'kelvin'].includes(base.toLowerCase())) { - return true; - } else { - return 'Please enter either `celsius`, `fahrenheit`, or `kelvin`.'; - } + if (['celsius', 'fahrenheit', 'kelvin'].includes(base.toLowerCase())) return true; + else return 'Please enter either `celsius`, `fahrenheit`, or `kelvin`.'; }, parse: (base) => base.toLowerCase() }, @@ -26,11 +23,8 @@ module.exports = class TemperatureCommand extends Command { prompt: 'What temperature unit do you want to convert to?', type: 'string', validate: (to) => { - if (['celsius', 'fahrenheit', 'kelvin'].includes(to.toLowerCase())) { - return true; - } else { - return 'Please enter either `celsius`, `fahrenheit`, or `kelvin`.'; - } + if (['celsius', 'fahrenheit', 'kelvin'].includes(to.toLowerCase())) return true; + else return 'Please enter either `celsius`, `fahrenheit`, or `kelvin`.'; }, parse: (to) => to.toLowerCase() }, @@ -45,27 +39,16 @@ module.exports = class TemperatureCommand extends Command { run(msg, args) { const { base, to, amount } = args; - if (base === to) { - return msg.say(`Converting ${base} to ${to} is the same value, dummy.`); - } + if (base === to) return msg.say(`Converting ${base} to ${to} is the same value, dummy.`); if (base === 'celsius') { - if (to === 'fahrenheit') { - return msg.say(`${amount}°C is ${(amount * 1.8) + 32}°F.`); - } else if (to === 'kelvin') { - return msg.say(`${amount}°C is ${amount + 273.15}°K.`); - } + if (to === 'fahrenheit') return msg.say(`${amount}°C is ${(amount * 1.8) + 32}°F.`); + else return msg.say(`${amount}°C is ${amount + 273.15}°K.`); } else if (base === 'fahrenheit') { - if (to === 'celsius') { - return msg.say(`${amount}°F is ${(amount - 32) / 1.8}°C.`); - } else if (to === 'kelvin') { - return msg.say(`${amount}°F is ${(amount + 459.67) * (5 / 9)}°K.`); - } - } else if (base === 'kelvin') { - if (to === 'celsius') { - return msg.say(`${amount}°K is ${amount - 273.15}°C.`); - } else if (to === 'fahrenheit') { - return msg.say(`${amount}°K is ${(amount * 1.8) - 459.67}°F.`); - } + if (to === 'celsius') return msg.say(`${amount}°F is ${(amount - 32) / 1.8}°C.`); + else return msg.say(`${amount}°F is ${(amount + 459.67) * (5 / 9)}°K.`); + } else { + if (to === 'celsius') return msg.say(`${amount}°K is ${amount - 273.15}°C.`); + else return msg.say(`${amount}°K is ${(amount * 1.8) - 459.67}°F.`); } } }; diff --git a/commands/random/easter-egg.js b/commands/random/easter-egg.js index 303dbe23..6ad580e3 100644 --- a/commands/random/easter-egg.js +++ b/commands/random/easter-egg.js @@ -15,11 +15,8 @@ module.exports = class EasterEggCommand extends Command { prompt: 'What easter egg do you want to view?', type: 'string', validate: (tag) => { - if (eastereggs[tag.toLowerCase()]) { - return true; - } else { - return 'Nope, that\'s not a valid easter egg. Try again!'; - } + if (eastereggs[tag.toLowerCase()]) return true; + else return 'Nope, that\'s not a valid easter egg. Try again!'; }, parse: (tag) => tag.toLowerCase() } diff --git a/commands/random/horoscope.js b/commands/random/horoscope.js index 19126eb3..29bce689 100644 --- a/commands/random/horoscope.js +++ b/commands/random/horoscope.js @@ -18,11 +18,8 @@ module.exports = class HoroscopeCommand extends Command { prompt: 'Which sign would you like to get the horoscope for?', type: 'string', validate: (sign) => { - if (signs.includes(sign.toLowerCase())) { - return true; - } else { - return 'Invalid sign. Use `help horoscope` for a list of signs.'; - } + if (signs.includes(sign.toLowerCase())) return true; + else return 'Invalid sign. Use `help horoscope` for a list of signs.'; }, parse: (sign) => sign.toLowerCase() } diff --git a/commands/random/meme.js b/commands/random/meme.js index dec69ac5..d034385c 100644 --- a/commands/random/meme.js +++ b/commands/random/meme.js @@ -16,11 +16,8 @@ module.exports = class MemeCommand extends Command { prompt: 'What meme type do you want to use?', type: 'string', validate: (type) => { - if (codes.includes(type.toLowerCase())) { - return true; - } else { - return 'Invalid meme type. Use `help meme` to view a list of meme types.'; - } + if (codes.includes(type.toLowerCase())) return true; + else return 'Invalid meme type. Use `help meme` to view a list of meme types.'; }, parse: (type) => type.toLowerCase() }, diff --git a/commands/random/soundboard.js b/commands/random/soundboard.js index 5df80545..1387df9f 100644 --- a/commands/random/soundboard.js +++ b/commands/random/soundboard.js @@ -23,11 +23,8 @@ module.exports = class SoundboardCommand extends Command { prompt: 'What sound would you like to play?', type: 'string', validate: (sound) => { - if (names.includes(sound.toLowerCase())) { - return true; - } else { - return 'Invalid Sound. Use `help soundboard` for a list of sounds.'; - } + if (names.includes(sound.toLowerCase())) return true; + else return 'Invalid Sound. Use `help soundboard` for a list of sounds.'; }, parse: (sound) => sound.toLowerCase() } @@ -37,17 +34,12 @@ module.exports = class SoundboardCommand extends Command { async run(msg, args) { const voiceChannel = msg.member.voiceChannel; - if (!voiceChannel) { - return msg.say('Please enter a Voice Channel first.'); - } else if (!voiceChannel.permissionsFor(this.client.user).has('CONNECT')) { - return msg.say('This Command requires the `CONNECT` Permission.'); - } else if (!voiceChannel.permissionsFor(this.client.user).has('SPEAK')) { - return msg.say('This Command requires the `SPEAK` Permission.'); - } else if (!voiceChannel.joinable) { - return msg.say('This Voice Channel is not joinable.'); - } else if (this.client.voiceConnections.get(voiceChannel.guild.id)) { - return msg.say('I am already playing a sound.'); + if (!voiceChannel) return msg.say('Please enter a Voice Channel first.'); + if (!voiceChannel.permissionsFor(this.client.user).has(['CONNECT', 'SPEAK'])) { + return msg.say('Missing the `CONNECT` or `SPEAK` Permission for the Voice Channel.'); } + if (!voiceChannel.joinable) return msg.say('This Voice Channel is not joinable.'); + if (this.client.voiceConnections.get(voiceChannel.guild.id)) return msg.say('I am already playing a sound.'); const { sound } = args; const connection = await voiceChannel.join(); msg.react('🔊'); @@ -55,7 +47,7 @@ module.exports = class SoundboardCommand extends Command { dispatcher.on('end', () => { voiceChannel.leave(); msg.react('✅'); - return null; }); + return null; } }; diff --git a/commands/random/star.js b/commands/random/star.js index 83858dbd..243a1622 100644 --- a/commands/random/star.js +++ b/commands/random/star.js @@ -25,11 +25,8 @@ module.exports = class StarCommand extends Command { async run(msg, args, reaction) { const { id } = args; const channel = msg.guild.channels.get(msg.guild.settings.get('starboard')); - if (!channel || this.starred.includes(id)) { - return null; - } else if (!channel.permissionsFor(this.client.user).has('SEND_MESSAGES')) { - return msg.say('I do not have Permission to send the message.'); - } + if (!channel || this.starred.includes(id)) return null; + if (!channel.permissionsFor(this.client.user).has('SEND_MESSAGES')) return null; const message = await msg.channel.fetchMessage(id); if (!reaction && msg.author.id === message.author.id) { return msg.reply('You cannot star your own messages, baka.'); diff --git a/commands/random/strawpoll.js b/commands/random/strawpoll.js index f3858aba..bcef4fcf 100644 --- a/commands/random/strawpoll.js +++ b/commands/random/strawpoll.js @@ -1,5 +1,4 @@ const Command = require('../../structures/Command'); -const { FriendlyError } = require('discord.js-commando'); const { stripIndents } = require('common-tags'); const snekfetch = require('snekfetch'); @@ -16,11 +15,8 @@ module.exports = class StrawpollCommand extends Command { prompt: 'What would you like the title of the Strawpoll to be?', type: 'string', validate: (title) => { - if (title.length < 200) { - return true; - } else { - return 'Invalid Title. Title must be under 200 characters.'; - } + if (title.length < 200) return true; + else return 'Title must be under 200 characters.'; } }, { @@ -29,11 +25,8 @@ module.exports = class StrawpollCommand extends Command { type: 'string', infinite: true, validate: (choice) => { - if (choice.length < 160) { - return true; - } else { - return 'Invalid Choice. Choices must be under 140 characters each.'; - } + if (choice.length < 160) return true; + else return 'Choices must be under 140 characters each.'; } } ] @@ -42,11 +35,8 @@ module.exports = class StrawpollCommand extends Command { async run(msg, args) { const { title, options } = args; - if (options.length < 2) { - throw new FriendlyError('You provided less than two choices.'); - } else if (options.length > 31) { - throw new FriendlyError('You provided more than thirty choices.'); - } + if (options.length < 2) return msg.say('You provided less than two choices.'); + if (options.length > 31) return msg.say('You provided more than thirty choices.'); const { body } = await snekfetch .post('https://strawpoll.me/api/v2/polls') .send({ title, options }); diff --git a/commands/randomimg/xkcd.js b/commands/randomimg/xkcd.js index 6567c444..92ae3c60 100644 --- a/commands/randomimg/xkcd.js +++ b/commands/randomimg/xkcd.js @@ -18,11 +18,8 @@ module.exports = class XKCDCommand extends Command { type: 'string', default: 'random', validate: (type) => { - if (['today', 'random'].includes(type.toLowerCase())) { - return true; - } else { - return 'Please enter either `today` or `random`'; - } + if (['today', 'random'].includes(type.toLowerCase())) return true; + else return 'Please enter either `today` or `random`'; } } ] diff --git a/commands/response/name.js b/commands/response/name.js index fc4d6bbe..c597ad11 100644 --- a/commands/response/name.js +++ b/commands/response/name.js @@ -14,11 +14,8 @@ module.exports = class RandomNameCommand extends Command { prompt: 'Which gender do you want to generate a name for?', type: 'string', validate: (gender) => { - if (['male', 'female'].includes(gender.toLowerCase())) { - return true; - } else { - return 'Please enter either `male` or `female`.'; - } + if (['male', 'female'].includes(gender.toLowerCase())) return true; + else return 'Please enter either `male` or `female`.'; }, parse: (gender) => gender.toLowerCase() } @@ -32,7 +29,7 @@ module.exports = class RandomNameCommand extends Command { if (gender === 'male') { const name = maleNames[Math.floor(Math.random() * maleNames.length)]; return msg.say(`${name} ${lastName}`); - } else if (gender === 'female') { + } else { const name = femaleNames[Math.floor(Math.random() * femaleNames.length)]; return msg.say(`${name} ${lastName}`); } diff --git a/commands/search/anime.js b/commands/search/anime.js index b41059ac..266a9eaf 100644 --- a/commands/search/anime.js +++ b/commands/search/anime.js @@ -29,9 +29,7 @@ module.exports = class AnimeCommand extends Command { try { const { text } = await snekfetch .get(`https://${ANIMELIST_LOGIN}@myanimelist.net/api/anime/search.xml`) - .query({ - q: query - }); + .query({ q: query }); const { anime } = await xml.parseStringAsync(text); const synopsis = cleanXML(anime.entry[0].synopsis[0].substr(0, 2000)); const embed = new RichEmbed() diff --git a/commands/search/bot-info.js b/commands/search/bot-info.js index 95b9ce55..597ba970 100644 --- a/commands/search/bot-info.js +++ b/commands/search/bot-info.js @@ -26,9 +26,7 @@ module.exports = class BotSearchCommand extends Command { try { const { body } = await snekfetch .get(`https://bots.discord.pw/api/bots/${bot.id}`) - .set({ - Authorization: DBOTS_KEY - }); + .set({ Authorization: DBOTS_KEY }); const embed = new RichEmbed() .setColor(0x9797FF) .setAuthor('Discord Bots', 'https://i.imgur.com/lrKYBQi.jpg') diff --git a/commands/search/bulbapedia.js b/commands/search/bulbapedia.js index 14f78a3c..3e148f1a 100644 --- a/commands/search/bulbapedia.js +++ b/commands/search/bulbapedia.js @@ -35,9 +35,7 @@ module.exports = class BulbapediaCommand extends Command { redirects: '', formatversion: 2 }); - if (body.query.pages[0].missing) { - return msg.say('No Results.'); - } + if (body.query.pages[0].missing) return msg.say('No Results.'); const embed = new RichEmbed() .setColor(0x3E7614) .setTitle(body.query.pages[0].title) diff --git a/commands/search/danbooru.js b/commands/search/danbooru.js index 3042c28f..b4e2d48c 100644 --- a/commands/search/danbooru.js +++ b/commands/search/danbooru.js @@ -1,4 +1,5 @@ const Command = require('../../structures/Command'); +const { stripIndents } = require('common-tags'); const snekfetch = require('snekfetch'); module.exports = class DanbooruCommand extends Command { @@ -28,9 +29,10 @@ module.exports = class DanbooruCommand extends Command { tags: `${query ? `${query} ` : ''}order:random`, limit: 1 }); - if (!body.length || !body[0].file_url) { - return msg.say('No Results'); - } - return msg.say(`${query ? `Result for ${query}:` : 'Random Image:'} https://danbooru.donmai.us${body[0].file_url}`); + if (!body.length || !body[0].file_url) return msg.say('No Results'); + return msg.say(stripIndents` + ${query ? `Result for ${query}:` : 'Random Image:'} + https://danbooru.donmai.us${body[0].file_url} + `); } }; diff --git a/commands/search/define.js b/commands/search/define.js index ac5bb910..ad2f887a 100644 --- a/commands/search/define.js +++ b/commands/search/define.js @@ -32,9 +32,7 @@ module.exports = class DefineCommand extends Command { useCanonical: false, api_key: WORDNIK_KEY }); - if (!body.length) { - return msg.say('No Results.'); - } + if (!body.length) return msg.say('No Results.'); const embed = new RichEmbed() .setColor(0x9797FF) .setTitle(body[0].word) diff --git a/commands/search/discrim.js b/commands/search/discrim.js index 946c490e..b6bd88fc 100644 --- a/commands/search/discrim.js +++ b/commands/search/discrim.js @@ -17,11 +17,8 @@ module.exports = class DiscrimCommand extends Command { type: 'string', default: '', validate: (discrim) => { - if (/[0-9]+$/g.test(discrim) && discrim.length === 4) { - return true; - } else { - return 'Invalid Discriminator.'; - } + if (/[0-9]+$/g.test(discrim) && discrim.length === 4) return true; + else return 'Invalid Discriminator.'; } } ] @@ -30,7 +27,7 @@ module.exports = class DiscrimCommand extends Command { run(msg, args) { const discrim = args.discrim || msg.author.discriminator; - const users = this.client.users.filter((u) => u.discriminator === discrim).map((u) => u.username); + const users = this.client.users.filter((user) => user.discriminator === discrim).map((user) => user.username); const embed = new RichEmbed() .setTitle(`${users.length} Users with the discriminator: ${discrim}`) .setDescription(users.join(', ')); diff --git a/commands/search/forecast.js b/commands/search/forecast.js index f04f2dea..41b4da71 100644 --- a/commands/search/forecast.js +++ b/commands/search/forecast.js @@ -1,4 +1,5 @@ const Command = require('../../structures/Command'); +const { stripIndents } = require('common-tags'); const { RichEmbed } = require('discord.js'); const snekfetch = require('snekfetch'); @@ -25,12 +26,10 @@ module.exports = class ForecastCommand extends Command { const { body } = await snekfetch .get('https://query.yahooapis.com/v1/public/yql') .query({ - q: `select * from weather.forecast where u=\'f\' AND woeid in (select woeid from geo.places(1) where text="${query}")`, + q: `select * from weather.forecast where u='f' AND woeid in (select woeid from geo.places(1) where text="${query}")`, // eslint-disable-line max-len format: 'json' }); - if (!body.query.count) { - return msg.say('Location Not Found.'); - } + if (!body.query.count) return msg.say('Location Not Found.'); const forecasts = body.query.results.channel.item.forecast; const embed = new RichEmbed() .setColor(0x0000FF) @@ -38,19 +37,47 @@ module.exports = class ForecastCommand extends Command { .setURL(body.query.results.channel.link) .setTimestamp() .addField(`❯ ${forecasts[0].day} - ${forecasts[0].date}`, - `**High:** ${forecasts[0].high}°F, **Low:** ${forecasts[0].low}°F, **Condition:** ${forecasts[0].text}`) + stripIndents` + **High:** ${forecasts[0].high}°F + **Low:** ${forecasts[0].low}°F + **Condition:** ${forecasts[0].text} + `) .addField(`❯ ${forecasts[1].day} - ${forecasts[1].date}`, - `**High:** ${forecasts[1].high}°F, **Low:** ${forecasts[1].low}°F, **Condition:** ${forecasts[1].text}`) + stripIndents` + **High:** ${forecasts[1].high}°F + **Low:** ${forecasts[1].low}°F + **Condition:** ${forecasts[1].text} + `) .addField(`❯ ${forecasts[2].day} - ${forecasts[2].date}`, - `**High:** ${forecasts[2].high}°F, **Low:** ${forecasts[2].low}°F, **Condition:** ${forecasts[2].text}`) + stripIndents` + **High:** ${forecasts[2].high}°F + **Low:** ${forecasts[2].low}°F + **Condition:** ${forecasts[2].text} + `) .addField(`❯ ${forecasts[3].day} - ${forecasts[3].date}`, - `**High:** ${forecasts[3].high}°F, **Low:** ${forecasts[3].low}°F, **Condition:** ${forecasts[3].text}`) + stripIndents` + **High:** ${forecasts[3].high}°F + **Low:** ${forecasts[3].low}°F + **Condition:** ${forecasts[3].text} + `) .addField(`❯ ${forecasts[4].day} - ${forecasts[4].date}`, - `**High:** ${forecasts[4].high}°F, **Low:** ${forecasts[4].low}°F, **Condition:** ${forecasts[4].text}`) + stripIndents` + **High:** ${forecasts[4].high}°F + **Low:** ${forecasts[4].low}°F + **Condition:** ${forecasts[4].text} + `) .addField(`❯ ${forecasts[5].day} - ${forecasts[5].date}`, - `**High:** ${forecasts[5].high}°F, **Low:** ${forecasts[5].low}°F, **Condition:** ${forecasts[5].text}`) + stripIndents` + **High:** ${forecasts[5].high}°F + **Low:** ${forecasts[5].low}°F + **Condition:** ${forecasts[5].text} + `) .addField(`❯ ${forecasts[6].day} - ${forecasts[6].date}`, - `**High:** ${forecasts[6].high}°F, **Low:** ${forecasts[6].low}°F, **Condition:** ${forecasts[6].text}`); + stripIndents` + **High:** ${forecasts[6].high}°F + **Low:** ${forecasts[6].low}°F + **Condition:** ${forecasts[6].text} + `); return msg.embed(embed); } }; diff --git a/commands/search/gelbooru.js b/commands/search/gelbooru.js index f4eab674..69c6da40 100644 --- a/commands/search/gelbooru.js +++ b/commands/search/gelbooru.js @@ -1,4 +1,5 @@ const Command = require('../../structures/Command'); +const { stripIndents } = require('common-tags'); const snekfetch = require('snekfetch'); const { promisifyAll } = require('tsubaki'); const xml = promisifyAll(require('xml2js')); @@ -23,19 +24,20 @@ module.exports = class GelbooruCommand extends Command { async run(msg, args) { const { query } = args; - const { text } = await snekfetch - .get('https://gelbooru.com/index.php') - .query({ - page: 'dapi', - s: 'post', - q: 'index', - tags: query, - limit: 1 - }); - const { posts } = await xml.parseStringAsync(text); - if (posts.$.count === '0') { - return msg.say('No Results.'); - } - return msg.say(`Result for ${query}: https:${posts.post[0].$.file_url}`); + const { text } = await snekfetch + .get('https://gelbooru.com/index.php') + .query({ + page: 'dapi', + s: 'post', + q: 'index', + tags: query, + limit: 1 + }); + const { posts } = await xml.parseStringAsync(text); + if (posts.$.count === '0') return msg.say('No Results.'); + return msg.say(stripIndents` + Result for ${query}: + https:${posts.post[0].$.file_url} + `); } }; diff --git a/commands/search/giphy.js b/commands/search/giphy.js index 378dbeba..4913193d 100644 --- a/commands/search/giphy.js +++ b/commands/search/giphy.js @@ -28,9 +28,7 @@ module.exports = class GiphyCommand extends Command { api_key: GIPHY_KEY, rating: msg.channel.nsfw ? 'r' : 'pg' }); - if (!body.data.length) { - return msg.say('No Results.'); - } + if (!body.data.length) return msg.say('No Results.'); const random = Math.floor(Math.random() * body.data.length); return msg.say(body.data[random].images.original.url); } diff --git a/commands/search/google.js b/commands/search/google.js index a385125b..f9c9e629 100644 --- a/commands/search/google.js +++ b/commands/search/google.js @@ -25,14 +25,10 @@ module.exports = class GoogleCommand extends Command { const message = await msg.say('Searching...'); const { text } = await snekfetch .get('https://www.google.com/search') - .query({ - q: query - }); + .query({ q: query }); const $ = cheerio.load(text); let href = $('.r').first().find('a').first().attr('href'); - if (!href) { - return msg.say('No Results.'); - } + if (!href) return msg.say('No Results.'); href = querystring.parse(href.replace('/url?', '')); return message.edit(href.q); } diff --git a/commands/search/konachan.js b/commands/search/konachan.js index 0eecde46..1be986c5 100644 --- a/commands/search/konachan.js +++ b/commands/search/konachan.js @@ -1,4 +1,5 @@ const Command = require('../../structures/Command'); +const { stripIndents } = require('common-tags'); const snekfetch = require('snekfetch'); module.exports = class KonachanCommand extends Command { @@ -28,9 +29,10 @@ module.exports = class KonachanCommand extends Command { tags: `${query ? `${query} ` : ''}order:random`, limit: 1 }); - if (!body.length) { - return msg.say('No Results.'); - } - return msg.say(`${query ? `Result for ${query}:` : 'Random Image:'} https:${body[0].file_url}`); + if (!body.length) return msg.say('No Results.'); + return msg.say(stripIndents` + ${query ? `Result for ${query}:` : 'Random Image:'} + https:${body[0].file_url} + `); } }; diff --git a/commands/search/manga.js b/commands/search/manga.js index 7b64faf4..6f642677 100644 --- a/commands/search/manga.js +++ b/commands/search/manga.js @@ -29,9 +29,7 @@ module.exports = class MangaCommand extends Command { try { const { text } = await snekfetch .get(`https://${ANIMELIST_LOGIN}@myanimelist.net/api/manga/search.xml`) - .query({ - q: query - }); + .query({ q: query }); const { manga } = await xml.parseStringAsync(text); const synopsis = cleanXML(manga.entry[0].synopsis[0].substr(0, 2000)); const embed = new RichEmbed() diff --git a/commands/search/map.js b/commands/search/map.js index 0791cdd8..c24648fb 100644 --- a/commands/search/map.js +++ b/commands/search/map.js @@ -17,11 +17,8 @@ module.exports = class MapCommand extends Command { prompt: 'What would you like the zoom level for the map to be? Limit 1-20.', type: 'integer', validate: (zoom) => { - if (zoom < 21 && zoom > 0) { - return true; - } else { - return 'Please enter a zoom value from 1-20'; - } + if (zoom < 21 && zoom > 0) return true; + else return 'Please enter a zoom value from 1-20'; } }, { diff --git a/commands/search/neopet.js b/commands/search/neopet.js index f1f51109..2685bfb8 100644 --- a/commands/search/neopet.js +++ b/commands/search/neopet.js @@ -30,9 +30,7 @@ module.exports = class NeopetCommand extends Command { }); const $ = cheerio.load(text); const link = $('textarea').first().text(); - if (!link.includes('cp')) { - return msg.say('Invalid Pet Name.'); - } + if (!link.includes('cp')) return msg.say('Invalid Pet Name.'); return msg.say(link); } }; diff --git a/commands/search/osu.js b/commands/search/osu.js index d857b45f..ed4419e9 100644 --- a/commands/search/osu.js +++ b/commands/search/osu.js @@ -30,9 +30,7 @@ module.exports = class OsuCommand extends Command { u: query, type: 'string' }); - if (!body.length) { - return msg.say('No Results.'); - } + if (!body.length) return msg.say('No Results.'); const embed = new RichEmbed() .setColor(0xFF66AA) .setAuthor('osu!', 'https://i.imgur.com/EmnUp00.png') diff --git a/commands/search/rule34.js b/commands/search/rule34.js index b19679e2..010b8eac 100644 --- a/commands/search/rule34.js +++ b/commands/search/rule34.js @@ -1,4 +1,5 @@ const Command = require('../../structures/Command'); +const { stripIndents } = require('common-tags'); const snekfetch = require('snekfetch'); const { promisifyAll } = require('tsubaki'); const xml = promisifyAll(require('xml2js')); @@ -33,9 +34,10 @@ module.exports = class Rule34Command extends Command { limit: 1 }); const { posts } = await xml.parseStringAsync(text); - if (posts.$.count === '0') { - return msg.say('No Results.'); - } - return msg.say(`Result for ${query}: https:${posts.post[0].$.file_url}`); + if (posts.$.count === '0') return msg.say('No Results.'); + return msg.say(stripIndents` + Result for ${query}: + https:${posts.post[0].$.file_url} + `); } }; diff --git a/commands/search/soundcloud.js b/commands/search/soundcloud.js index 1154ae22..764b25c6 100644 --- a/commands/search/soundcloud.js +++ b/commands/search/soundcloud.js @@ -29,9 +29,7 @@ module.exports = class SoundCloudCommand extends Command { q: query, client_id: SOUNDCLOUD_KEY }); - if (!body.length) { - return msg.say('No Results.'); - } + if (!body.length) return msg.say('No Results.'); const embed = new RichEmbed() .setColor(0xF15A22) .setAuthor('SoundCloud', 'https://i.imgur.com/lFIz7RU.png') diff --git a/commands/search/urban.js b/commands/search/urban.js index b08f54c3..46d06cae 100644 --- a/commands/search/urban.js +++ b/commands/search/urban.js @@ -24,12 +24,8 @@ module.exports = class UrbanCommand extends Command { const { query } = args; const { body } = await snekfetch .get('http://api.urbandictionary.com/v0/define') - .query({ - term: query - }); - if (!body.list.length) { - return msg.say('No Results.'); - } + .query({ term: query }); + if (!body.list.length) return msg.say('No Results.'); const embed = new RichEmbed() .setColor(0x32a8f0) .setAuthor('Urban Dictionary', 'https://i.imgur.com/fzFuuL7.png') diff --git a/commands/search/wattpad.js b/commands/search/wattpad.js index 310e9a63..5fcbab67 100644 --- a/commands/search/wattpad.js +++ b/commands/search/wattpad.js @@ -30,12 +30,8 @@ module.exports = class WattpadCommand extends Command { query, limit: 1 }) - .set({ - Authorization: `Basic ${WATTPAD_KEY}` - }); - if (!body.stories.length) { - return msg.say('No Results.'); - } + .set({ Authorization: `Basic ${WATTPAD_KEY}` }); + if (!body.stories.length) return msg.say('No Results.'); const embed = new RichEmbed() .setColor(0xF89C34) .setAuthor('Wattpad', 'https://i.imgur.com/Rw9vRQB.png') diff --git a/commands/search/weather.js b/commands/search/weather.js index de9b739b..66849997 100644 --- a/commands/search/weather.js +++ b/commands/search/weather.js @@ -25,12 +25,10 @@ module.exports = class WeatherCommand extends Command { const { body } = await snekfetch .get('https://query.yahooapis.com/v1/public/yql') .query({ - q: `select * from weather.forecast where u=\'f\' AND woeid in (select woeid from geo.places(1) where text="${query}")`, + q: `select * from weather.forecast where u='f' AND woeid in (select woeid from geo.places(1) where text="${query}")`, // eslint-disable-line max-len format: 'json' }); - if (!body.query.count) { - return msg.say('Location Not Found.'); - } + if (!body.query.count) return msg.say('Location Not Found.'); const embed = new RichEmbed() .setColor(0x0000FF) .setAuthor(body.query.results.channel.title, 'https://i.imgur.com/2MT0ViC.png') diff --git a/commands/search/wikipedia.js b/commands/search/wikipedia.js index 035f1fd6..8df39d6d 100644 --- a/commands/search/wikipedia.js +++ b/commands/search/wikipedia.js @@ -34,9 +34,7 @@ module.exports = class WikipediaCommand extends Command { redirects: '', formatversion: 2 }); - if (body.query.pages[0].missing) { - return msg.say('No Results.'); - } + if (body.query.pages[0].missing) return msg.say('No Results.'); const embed = new RichEmbed() .setColor(0xE7E7E7) .setTitle(body.query.pages[0].title) diff --git a/commands/search/youtube.js b/commands/search/youtube.js index e86010c7..d9b97195 100644 --- a/commands/search/youtube.js +++ b/commands/search/youtube.js @@ -32,9 +32,7 @@ module.exports = class YouTubeCommand extends Command { q: query, key: GOOGLE_KEY }); - if (!body.items.length) { - return msg.say('No Results.'); - } + if (!body.items.length) return msg.say('No Results.'); const embed = new RichEmbed() .setColor(0xDD2825) .setTitle(body.items[0].snippet.title) diff --git a/commands/search/yu-gi-oh.js b/commands/search/yu-gi-oh.js index 93503cd7..312d7128 100644 --- a/commands/search/yu-gi-oh.js +++ b/commands/search/yu-gi-oh.js @@ -25,9 +25,7 @@ module.exports = class YuGiOhCommand extends Command { const { query } = args; const { body } = await snekfetch .get(`http://yugiohprices.com/api/card_data/${query}`); - if (body.status === 'fail') { - return msg.say('No Results.'); - } + if (body.status === 'fail') return msg.say('No Results.'); const embed = new RichEmbed() .setColor(0xBE5F1F) .setTitle(body.data.name) diff --git a/commands/settings/clear-setting.js b/commands/settings/clear-setting.js index e063770d..52e56262 100644 --- a/commands/settings/clear-setting.js +++ b/commands/settings/clear-setting.js @@ -16,11 +16,8 @@ module.exports = class ClearSettingCommand extends Command { prompt: 'What setting do you want to clear?', type: 'string', validate: (setting) => { - if (settings.includes(setting)) { - return true; - } else { - return `Please enter one of the following: ${settings.join(', ')}.`; - } + if (settings.includes(setting)) return true; + else return `Please enter one of the following: ${settings.join(', ')}.`; } } ] diff --git a/commands/settings/member-message.js b/commands/settings/member-message.js index 93bd71c5..4d30ce76 100644 --- a/commands/settings/member-message.js +++ b/commands/settings/member-message.js @@ -17,11 +17,8 @@ module.exports = class MemberMsgCommand extends Command { prompt: 'Which message would you like to change? Please enter either `joinMsg` or `leaveMsg`.', type: 'string', validate: (type) => { - if (['joinMsg', 'leaveMsg'].includes(type)) { - return true; - } else { - return 'Please enter either `joinMsg` or `leaveMsg`.'; - } + if (['joinMsg', 'leaveMsg'].includes(type)) return true; + else return 'Please enter either `joinMsg` or `leaveMsg`.'; } }, { @@ -29,11 +26,8 @@ module.exports = class MemberMsgCommand extends Command { prompt: 'What should be sent to the channel? Use , , and as placeholders.', type: 'string', validate: (message) => { - if (message.length < 150) { - return true; - } else { - return 'Invalid Message. Message must be under 150 characters.'; - } + if (message.length < 150) return true; + else return 'Invalid Message. Message must be under 150 characters.'; } } ] @@ -45,7 +39,7 @@ module.exports = class MemberMsgCommand extends Command { if (type === 'joinMsg') { msg.guild.settings.set('joinMsg', message); return msg.say(`Join Message set to "${message}".`); - } else if (type === 'leaveMsg') { + } else { msg.guild.settings.set('leaveMsg', message); return msg.say(`Leave Message set to "${message}".`); } diff --git a/commands/settings/setting-list.js b/commands/settings/setting-list.js index 4efb8a4a..a3010ad0 100644 --- a/commands/settings/setting-list.js +++ b/commands/settings/setting-list.js @@ -13,21 +13,21 @@ module.exports = class SettingListCommand extends Command { } run(msg) { - const modLog = msg.guild.settings.get('modLog', false); - const memberLog = msg.guild.settings.get('memberLog', false); - const singleRole = msg.guild.settings.get('singleRole', false); - const joinRole = msg.guild.settings.get('joinRole', false); - const starboard = msg.guild.settings.get('starboard', false); + const modLog = msg.guild.channels.get(msg.guild.settings.get('modLog')); + const memberLog = msg.guild.channels.get(msg.guild.settings.get('memberLog')); + const singleRole = msg.guild.roles.get(msg.guild.settings.get('singleRole')); + const joinRole = msg.guild.roles.get(msg.guild.settings.get('joinRole')); + const starboard = msg.guild.channels.get(msg.guild.settings.get('starboard')); return msg.say(stripIndents` **Prefix:** ${msg.guild.commandPrefix} **Invite Guard:** ${msg.guild.settings.get('inviteGuard', false)} - **Mod Channel:** ${modLog ? msg.guild.channels.has(modLog) ? msg.guild.channels.get(modLog).name : 'Missing' : 'None'} - **Starboard:** ${starboard ? msg.guild.channels.has(starboard) ? msg.guild.channels.get(starboard).name : 'Missing' : 'None'} - **Join Role:** ${joinRole ? msg.guild.roles.has(joinRole) ? msg.guild.roles.get(joinRole).name : 'Missing' : 'None'} - **Member Channel:** ${memberLog ? msg.guild.channels.has(memberLog) ? msg.guild.channels.get(memberLog).name : 'Missing' : 'None'} + **Mod Channel:** ${modLog ? modLog.name : 'None'} + **Starboard:** ${starboard ? starboard.name : 'None'} + **Join Role:** ${joinRole ? joinRole.name : 'None'} + **Member Channel:** ${memberLog ? memberLog.name : 'None'} **Join Message:** ${msg.guild.settings.get('joinMsg', 'Welcome ! (Default)')} **Leave Message:** ${msg.guild.settings.get('leaveMsg', 'Bye ... (Default)')} - **Single Role:** ${singleRole ? msg.guild.roles.has(singleRole) ? msg.guild.roles.get(singleRole).name : 'Missing' : 'None'} + **Single Role:** ${singleRole ? singleRole.name : 'None'} `); } }; diff --git a/commands/textedit/binary.js b/commands/textedit/binary.js index bfe7467e..86a36356 100644 --- a/commands/textedit/binary.js +++ b/commands/textedit/binary.js @@ -13,13 +13,9 @@ module.exports = class BinaryCommand extends Command { prompt: 'What text would you like to convert to binary?', type: 'string', validate: (text) => { - if (this.binary(text).length < 2000) { - return true; - } else { - return 'Your text is too long.'; - } - }, - parse: (text) => this.binary(text) + if (this.binary(text).length < 2000) return true; + else return 'Your text is too long.'; + } } ] }); @@ -27,7 +23,8 @@ module.exports = class BinaryCommand extends Command { run(msg, args) { const { text } = args; - return msg.say(text); + const converted = this.binary(text); + return msg.say(converted); } binary(text) { diff --git a/commands/textedit/cow-say.js b/commands/textedit/cow-say.js index efe7c722..244013dd 100644 --- a/commands/textedit/cow-say.js +++ b/commands/textedit/cow-say.js @@ -14,11 +14,8 @@ module.exports = class CowsayCommand extends Command { prompt: 'What text would you like the cow to say?', type: 'string', validate: (text) => { - if (text.length < 1500) { - return true; - } else { - return 'Invalid Text. Text must be under 1500 characters.'; - } + if (text.length < 1500) return true; + else return 'Invalid Text. Text must be under 1500 characters.'; } } ] diff --git a/commands/textedit/mocking.js b/commands/textedit/mocking.js new file mode 100644 index 00000000..61f0c1e7 --- /dev/null +++ b/commands/textedit/mocking.js @@ -0,0 +1,32 @@ +const Command = require('../../structures/Command'); + +module.exports = class MockingCommand extends Command { + constructor(client) { + super(client, { + name: 'mocking', + group: 'textedit', + memberName: 'mocking', + description: 'I aM a caT, I LIkE To DrInK mILK.', + clientPermissions: ['USE_EXTERNAL_EMOJIS'], + args: [ + { + key: 'text', + prompt: 'WHaT tEXt WoUlD yOu LiKE to COnvErt?', + type: 'string', + validate: (text) => { + if (text.length < 1950) return true; + else return 'Invalid Text. Text must be under 1950 characters.'; + }, + parse: (text) => text.split('') + } + ] + }); + } + + run(msg, args) { + const { text } = args; + for (let i = 0; i < text.length; i += Math.floor(Math.random() * 4)) text[i] = text[i].toUpperCase(); + return msg.say(`\u180E${text.join('')} <:sponge:318612443398144000>`); + } +}; + diff --git a/commands/textedit/morse.js b/commands/textedit/morse.js index 3584e45f..771547ae 100644 --- a/commands/textedit/morse.js +++ b/commands/textedit/morse.js @@ -15,13 +15,9 @@ module.exports = class MorseCommand extends Command { prompt: 'What text would you like to convert to morse?', type: 'string', validate: (text) => { - if (letterTrans(text, dictionary, ' ').length < 1999) { - return true; - } else { - return 'Your text is too long.'; - } - }, - parse: (text) => letterTrans(text.toLowerCase(), dictionary, ' ') + if (letterTrans(text, dictionary, ' ').length < 1999) return true; + else return 'Your text is too long.'; + } } ] }); @@ -29,6 +25,7 @@ module.exports = class MorseCommand extends Command { run(msg, args) { const { text } = args; - return msg.say(text); + const converted = letterTrans(text.toLowerCase(), dictionary, ' '); + return msg.say(converted); } }; diff --git a/commands/textedit/pirate.js b/commands/textedit/pirate.js index ffa03ee7..95ca7b3e 100644 --- a/commands/textedit/pirate.js +++ b/commands/textedit/pirate.js @@ -15,13 +15,9 @@ module.exports = class PirateCommand extends Command { prompt: 'What text would you like to convert to pirate?', type: 'string', validate: (text) => { - if (wordTrans(text, dictionary).length < 1999) { - return true; - } else { - return 'Your text is too long.'; - } - }, - parse: (text) => wordTrans(text, dictionary) + if (wordTrans(text, dictionary).length < 1999) return true; + else return 'Your text is too long.'; + } } ] }); @@ -29,6 +25,7 @@ module.exports = class PirateCommand extends Command { run(msg, args) { const { text } = args; - return msg.say(`\u180E${text}`); + const converted = wordTrans(text, dictionary); + return msg.say(`\u180E${converted}`); } }; diff --git a/commands/textedit/repeat.js b/commands/textedit/repeat.js index d5f9c738..917f49c2 100644 --- a/commands/textedit/repeat.js +++ b/commands/textedit/repeat.js @@ -11,8 +11,7 @@ module.exports = class RepeatCommand extends Command { { key: 'text', prompt: 'What text would you like to repeat over and over and over and over?', - type: 'string', - parse: (text) => text.repeat(2000).substr(0, 1999) + type: 'string' } ] }); @@ -20,6 +19,7 @@ module.exports = class RepeatCommand extends Command { run(msg, args) { const { text } = args; - return msg.say(`\u180E${text}`); + const converted = text.repeat(2000).substr(0, 1999); + return msg.say(`\u180E${converted}`); } }; diff --git a/commands/textedit/reverse.js b/commands/textedit/reverse.js index 27872b3c..3408ebe4 100644 --- a/commands/textedit/reverse.js +++ b/commands/textedit/reverse.js @@ -11,8 +11,7 @@ module.exports = class ReverseCommand extends Command { { key: 'text', prompt: 'What text would you like to reverse?', - type: 'string', - parse: (text) => text.split('').reverse().join('') + type: 'string' } ] }); @@ -20,6 +19,7 @@ module.exports = class ReverseCommand extends Command { run(msg, args) { const { text } = args; - return msg.say(`\u180E${text}`); + const converted = text.split('').reverse().join(''); + return msg.say(`\u180E${converted}`); } }; diff --git a/commands/textedit/temmie.js b/commands/textedit/temmie.js index d9280519..c037cd8a 100644 --- a/commands/textedit/temmie.js +++ b/commands/textedit/temmie.js @@ -3,32 +3,29 @@ const { wordTrans } = require('custom-translate'); const dictionary = require('../../assets/json/temmie'); module.exports = class TemmieCommand extends Command { - constructor(client) { - super(client, { - name: 'temmie', - group: 'textedit', - memberName: 'temmie', - description: 'Translate text to Temmie speak.', - args: [ - { - key: 'text', - prompt: 'What text would you like to convert to Temmie speak?', - type: 'string', - validate: (text) => { - if (wordTrans(text, dictionary).length < 1999) { - return true; - } else { - return 'Your text is too long.'; - } - }, - parse: (text) => wordTrans(text, dictionary) - } + constructor(client) { + super(client, { + name: 'temmie', + group: 'textedit', + memberName: 'temmie', + description: 'Translate text to Temmie speak.', + args: [ + { + key: 'text', + prompt: 'What text would you like to convert to Temmie speak?', + type: 'string', + validate: (text) => { + if (wordTrans(text, dictionary).length < 1999) return true; + else return 'Your text is too long.'; + } + } ] - }); - } + }); + } - run(msg, args) { - const { text } = args; - return msg.say(`\u180E${text}`); - } + run(msg, args) { + const { text } = args; + const converted = wordTrans(text, dictionary); + return msg.say(`\u180E${converted}`); + } }; diff --git a/commands/textedit/translate.js b/commands/textedit/translate.js index 21c5ef63..7ee4ac51 100644 --- a/commands/textedit/translate.js +++ b/commands/textedit/translate.js @@ -24,11 +24,8 @@ module.exports = class TranslateCommand extends Command { prompt: 'Which language is being translated to?', type: 'string', validate: (to) => { - if (codes[to.toLowerCase()]) { - return true; - } else { - return 'Invalid Language Code. Use `help translate` for a list of codes.'; - } + if (codes[to.toLowerCase()]) return true; + else return 'Invalid Language Code. Use `help translate` for a list of codes.'; }, parse: (to) => to.toLowerCase() }, @@ -38,11 +35,8 @@ module.exports = class TranslateCommand extends Command { type: 'string', default: '', validate: (from) => { - if (codes[from.toLowerCase()]) { - return true; - } else { - return 'Invalid Language Code. Use `help translate` for a list of codes.'; - } + if (codes[from.toLowerCase()]) return true; + else return 'Invalid Language Code. Use `help translate` for a list of codes.'; }, parse: (from) => from.toLowerCase() } diff --git a/commands/textedit/upside-down.js b/commands/textedit/upside-down.js index 7817e166..9b544824 100644 --- a/commands/textedit/upside-down.js +++ b/commands/textedit/upside-down.js @@ -14,8 +14,7 @@ module.exports = class UpsideDownCommand extends Command { { key: 'text', prompt: 'What text would you like to flip upside-down?', - type: 'string', - parse: (text) => letterTrans(text, dictionary) + type: 'string' } ] }); @@ -23,6 +22,7 @@ module.exports = class UpsideDownCommand extends Command { run(msg, args) { const { text } = args; - return msg.say(text); + const converted = letterTrans(text, dictionary); + return msg.say(converted); } }; diff --git a/commands/textedit/zalgo.js b/commands/textedit/zalgo.js index 47bb0541..631ea89c 100644 --- a/commands/textedit/zalgo.js +++ b/commands/textedit/zalgo.js @@ -14,13 +14,9 @@ module.exports = class ZalgoCommand extends Command { prompt: 'What text would you like to convert to zalgo?', type: 'string', validate: (text) => { - if (text.length < 500) { - return true; - } else { - return 'Invalid Text. Text must be under 500 characters.'; - } - }, - parse: (text) => zalgo(text) + if (text.length < 500) return true; + else return 'Invalid Text. Text must be under 500 characters.'; + } } ] }); @@ -28,6 +24,7 @@ module.exports = class ZalgoCommand extends Command { run(msg, args) { const { text } = args; - return msg.say(`\u180E${text}`); + const converted = zalgo(text); + return msg.say(`\u180E${converted}`); } }; diff --git a/commands/userinfo/user-info.js b/commands/userinfo/user-info.js index a45c0bdf..678f16d0 100644 --- a/commands/userinfo/user-info.js +++ b/commands/userinfo/user-info.js @@ -2,10 +2,10 @@ const Command = require('../../structures/Command'); const { RichEmbed } = require('discord.js'); const moment = require('moment'); const statuses = { - online: "<:online:313956277808005120> Online", - idle: "<:away:313956277220802560> Idle", - dnd: "<:dnd:313956276893646850> Do Not Disturb", - offline: "<:offline:313956277237710868> Offline" + online: '<:online:313956277808005120> Online', + idle: '<:away:313956277220802560> Idle', + dnd: '<:dnd:313956276893646850> Do Not Disturb', + offline: '<:offline:313956277237710868> Offline' }; const colors = { online: 0x00AE86, diff --git a/commands/util/help.js b/commands/util/help.js index 32f4c3a7..5f9b67a3 100644 --- a/commands/util/help.js +++ b/commands/util/help.js @@ -38,18 +38,18 @@ module.exports = class HelpCommand extends Command { ${commands[0].details || ''} `); } else { - return msg.say(`Could not identify command. Use \`${msg.usage(null)}\` to view a list of commands you can use.`); + return msg.say(`Could not identify command. Use \`${msg.usage(null)}\` to view a list of commands.`); } } else { const embed = new RichEmbed() .setTitle(!showAll ? `Commands Available in ${msg.guild ? msg.guild.name : 'this DM'}` : 'All Commands') - .setDescription(`Use \`${msg.usage('')}\` to view detailed information about a specific command.`) + .setDescription(`Use \`${msg.usage('')}\` to view detailed information about a command.`) .setColor(0x00AE86); for (const group of this.client.registry.groups.values()) { embed.addField(`❯ ${group.name}`, - showAll - ? group.commands.map((c) => c.name).join(', ') - : group.commands.filter((c) => c.isUsable(msg)).map((c) => c.name).join(', ') || 'None Available'); + showAll ? + group.commands.map((c) => c.name).join(', ') : + group.commands.filter((c) => c.isUsable(msg)).map((c) => c.name).join(', ') || 'None'); } try { await msg.direct({ embed }); diff --git a/commands/util/info.js b/commands/util/info.js index 4526b9c8..4462eec0 100644 --- a/commands/util/info.js +++ b/commands/util/info.js @@ -19,7 +19,7 @@ module.exports = class InfoCommand extends Command { async run(msg) { const guilds = await this.client.shard.fetchClientValues('guilds.size'); - const memory = await this.client.shard.broadcastEval('Math.round(process.memoryUsage().heapUsed / 1024 / 1024)'); + const memory = await this.client.shard.broadcastEval('process.memoryUsage().heapUsed'); const embed = new RichEmbed() .setColor(0x00AE86) .setFooter('©2017 dragonfire535#8081') @@ -32,7 +32,7 @@ module.exports = class InfoCommand extends Command { .addField('❯ Source Code', '[View Here](https://github.com/dragonfire535/xiaobot)', true) .addField('❯ Memory Usage', - `${memory.reduce((prev, val) => prev + val, 0)}MB`, true) + `${Math.round(memory.reduce((prev, val) => prev + val, 0)) / 1024 / 1024}MB`, true) .addField('❯ Uptime', moment.duration(this.client.uptime).format('d[d]h[h]m[m]s[s]'), true) .addField('❯ Version', @@ -40,7 +40,7 @@ module.exports = class InfoCommand extends Command { .addField('❯ Node Version', process.version, true) .addField('❯ Library', - '[discord.js](https://github.com/hydrabolt/discord.js)[-commando](https://github.com/Gawdl3y/discord.js-commando)', true); + '[discord.js](https://discord.js.org)[-commando](https://github.com/Gawdl3y/discord.js-commando)', true); // eslint-disable-line max-len return msg.embed(embed); } }; diff --git a/commands/util/shard-info.js b/commands/util/shard-info.js index eec8fd32..88ceb338 100644 --- a/commands/util/shard-info.js +++ b/commands/util/shard-info.js @@ -19,11 +19,8 @@ module.exports = class ShardInfoCommand extends Command { prompt: 'Which Shard would you like to get data for?', type: 'integer', validate: (shard) => { - if (shard < this.client.options.shardCount && shard > -1) { - return true; - } else { - return 'Invalid Shard ID'; - } + if (shard < this.client.options.shardCount && shard > -1) return true; + else return 'Invalid Shard ID'; } } ] @@ -32,7 +29,7 @@ module.exports = class ShardInfoCommand extends Command { async run(msg, args) { const { shard } = args; - const memory = await this.client.shard.broadcastEval('Math.round(process.memoryUsage().heapUsed / 1024 / 1024)'); + const memory = await this.client.shard.broadcastEval('process.memoryUsage().heapUsed'); const uptime = await this.client.shard.fetchClientValues('uptime'); const guilds = await this.client.shard.fetchClientValues('guilds.size'); const embed = new RichEmbed() @@ -41,7 +38,7 @@ module.exports = class ShardInfoCommand extends Command { .addField('❯ Servers', guilds[shard], true) .addField('❯ Memory Usage', - `${memory[shard]}MB`, true) + `${Math.round(memory[shard]) / 1024 / 1024}MB`, true) .addField('❯ Uptime', moment.duration(uptime[shard]).format('d[d]h[h]m[m]s[s]'), true); return msg.embed(embed); diff --git a/commands/util/uptime.js b/commands/util/uptime.js index da19b080..bbb22aa6 100644 --- a/commands/util/uptime.js +++ b/commands/util/uptime.js @@ -14,6 +14,6 @@ module.exports = class UptimeCommand extends Command { } run(msg) { - return msg.say(`I've been active on this shard for: **${moment.duration(this.client.uptime).format('d[ days], h[ hours], m[ minutes, and ]s[ seconds]')}**!`); + return msg.say(moment.duration(this.client.uptime).format('d[ days], h[ hours], m[ minutes, and ]s[ seconds]')); } }; diff --git a/providers/Sequelize.js b/providers/Sequelize.js index 7f93f793..34ab6ed9 100644 --- a/providers/Sequelize.js +++ b/providers/Sequelize.js @@ -1,3 +1,5 @@ +/* eslint-disable indent */ + const { SettingProvider } = require('discord.js-commando'); const Sequelize = require('sequelize'); @@ -110,16 +112,12 @@ class SequelizeProvider extends SettingProvider { this.setupGuildGroup(client.guilds.get(guild), group, settings); } }); - for (const [event, listener] of this.listeners) { - client.on(event, listener); - } + for (const [event, listener] of this.listeners) client.on(event, listener); } destroy() { // Remove all listeners from the client - for (const [event, listener] of this.listeners) { - this.client.removeListener(event, listener); - } + for (const [event, listener] of this.listeners) this.client.removeListener(event, listener); this.listeners.clear(); } @@ -141,18 +139,14 @@ class SequelizeProvider extends SettingProvider { { guild: guild !== 'global' ? guild : '0', settings: JSON.stringify(settings) }, { where: { guild: guild !== 'global' ? guild : '0' } } ); - if (guild === 'global') { - this.updateOtherShards(key, val); - } + if (guild === 'global') this.updateOtherShards(key, val); return val; } async remove(guild, key) { guild = this.constructor.getGuildID(guild); const settings = this.settings.get(guild); - if (!settings || typeof settings[key] === 'undefined') { - return undefined; - } + if (!settings || typeof settings[key] === 'undefined') return undefined; const val = settings[key]; settings[key] = undefined; @@ -160,9 +154,7 @@ class SequelizeProvider extends SettingProvider { { guild: guild !== 'global' ? guild : '0', settings: JSON.stringify(settings) }, { where: { guild: guild !== 'global' ? guild : '0' } } ); - if (guild === 'global') { - this.updateOtherShards(key, undefined); - } + if (guild === 'global') this.updateOtherShards(key, undefined); return val; } @@ -180,27 +172,18 @@ class SequelizeProvider extends SettingProvider { * @private */ setupGuild(guild, settings) { - if (typeof guild !== 'string') { - throw new TypeError('The guild must be a guild ID or "global".'); - } + if (typeof guild !== 'string') throw new TypeError('The guild must be a guild ID or "global".'); guild = this.client.guilds.get(guild) || null; // Load the command prefix if (typeof settings.prefix !== 'undefined') { - if (guild) { - guild._commandPrefix = settings.prefix; - } else { - this.client._commandPrefix = settings.prefix; - } + if (guild) guild._commandPrefix = settings.prefix; + else this.client._commandPrefix = settings.prefix; } // Load all command/group statuses - for (const command of this.client.registry.commands.values()) { - this.setupGuildCommand(guild, command, settings); - } - for (const group of this.client.registry.groups.values()) { - this.setupGuildGroup(guild, group, settings); - } + for (const command of this.client.registry.commands.values()) this.setupGuildCommand(guild, command, settings); + for (const group of this.client.registry.groups.values()) this.setupGuildGroup(guild, group, settings); } /** @@ -213,9 +196,7 @@ class SequelizeProvider extends SettingProvider { setupGuildCommand(guild, command, settings) { if (typeof settings[`cmd-${command.name}`] === 'undefined') return; if (guild) { - if (!guild._commandsEnabled) { - guild._commandsEnabled = {}; - } + if (!guild._commandsEnabled) guild._commandsEnabled = {}; guild._commandsEnabled[command.name] = settings[`cmd-${command.name}`]; } else { command._globalEnabled = settings[`cmd-${command.name}`]; @@ -232,9 +213,7 @@ class SequelizeProvider extends SettingProvider { setupGuildGroup(guild, group, settings) { if (typeof settings[`grp-${group.id}`] === 'undefined') return; if (guild) { - if (!guild._groupsEnabled) { - guild._groupsEnabled = {}; - } + if (!guild._groupsEnabled) guild._groupsEnabled = {}; guild._groupsEnabled[group.id] = settings[`grp-${group.id}`]; } else { group._globalEnabled = settings[`grp-${group.id}`]; @@ -252,7 +231,7 @@ class SequelizeProvider extends SettingProvider { key = JSON.stringify(key); val = typeof val !== 'undefined' ? JSON.stringify(val) : 'undefined'; this.client.shard.broadcastEval(` - if (this.shard.id !== ${this.client.shard.id} && this.provider && this.provider.settings) { + if(this.shard.id !== ${this.client.shard.id} && this.provider && this.provider.settings) { this.provider.settings.global[${key}] = ${val}; } `); diff --git a/structures/PostgreSQL.js b/structures/PostgreSQL.js index d3659f5e..9b6a6f68 100644 --- a/structures/PostgreSQL.js +++ b/structures/PostgreSQL.js @@ -3,21 +3,21 @@ const { DATABASE_URL } = process.env; const database = new Sequelize(DATABASE_URL, { logging: false }); class Database { - static get db() { - return database; - } + static get db() { + return database; + } - static start() { - database.authenticate() - .then(() => console.log('[DATABASE] Connection has been established successfully.')) - .then(() => console.log('[DATABASE] Synchronizing...')) - .then(() => database.sync() - .then(() => console.log('[DATABASE] Synchronizing complete!')) - .catch(err => console.error(`[DATABASE] Error synchronizing: ${err}`)) - ) - .then(() => console.log('[DATABASE] Ready!')) - .catch(err => console.error(`[DATABASE] Unable to connect: ${err}`)); - } + static start() { + database.authenticate() + .then(() => console.log('[DATABASE] Connection has been established successfully.')) + .then(() => console.log('[DATABASE] Synchronizing...')) + .then(() => database.sync() + .then(() => console.log('[DATABASE] Synchronizing complete!')) + .catch((err) => console.error(`[DATABASE] Error synchronizing: ${err}`)) + ) + .then(() => console.log('[DATABASE] Ready!')) + .catch((err) => console.error(`[DATABASE] Unable to connect: ${err}`)); + } } module.exports = Database; diff --git a/structures/Stats.js b/structures/Stats.js index 403e2977..bc113936 100644 --- a/structures/Stats.js +++ b/structures/Stats.js @@ -5,14 +5,10 @@ class Stats { static dBots(count, id) { snekfetch .post(`https://bots.discord.pw/api/bots/${id}/stats`) - .set({ - Authorization: DBOTS_KEY - }) - .send({ - server_count: count - }) + .set({ Authorization: DBOTS_KEY }) + .send({ server_count: count }) .then(() => console.log('[CARBON] Successfully posted to Carbon.')) - .catch(err => console.error(`[CARBON] Failed to post to Carbon. ${err}`)); + .catch((err) => console.error(`[CARBON] Failed to post to Carbon. ${err}`)); } static carbon(count) { @@ -23,7 +19,7 @@ class Stats { servercount: count }) .then(() => console.log('[DBOTS] Successfully posted to Discord Bots.')) - .catch(err => console.error(`[DBOTS] Failed to post to Discord Bots. ${err}`)); + .catch((err) => console.error(`[DBOTS] Failed to post to Discord Bots. ${err}`)); } }