From 7802bb49cbb007b8f1b3f195981e7daa47c18613 Mon Sep 17 00:00:00 2001 From: Daniel Odendahl Jr Date: Wed, 31 May 2017 04:41:01 +0000 Subject: [PATCH] Clean-Ups --- XiaoBot.js | 11 +++---- commands/avataredit/3000-years.js | 8 ++--- commands/avataredit/beautiful.js | 6 ++-- commands/avataredit/bob-ross.js | 6 ++-- commands/avataredit/card.js | 9 +++--- commands/avataredit/challenger.js | 6 ++-- commands/avataredit/dexter.js | 6 ++-- commands/avataredit/greyscale.js | 8 ++--- commands/avataredit/invert.js | 12 +++----- commands/avataredit/rip.js | 12 +++----- commands/avataredit/simba.js | 6 ++-- commands/avataredit/steam-card.js | 11 +++---- commands/avataredit/triggered.js | 8 ++--- commands/avataredit/wanted.js | 6 ++-- commands/games/battle.js | 2 +- commands/games/lottery.js | 2 +- commands/games/math-game.js | 17 +++++------ commands/games/quiz.js | 13 +++----- commands/games/rock-paper-scissors.js | 2 +- commands/games/slots.js | 2 +- commands/games/typing-game.js | 13 +++----- commands/guildinfo/emoji.js | 6 ++-- commands/guildinfo/server-info.js | 9 +++--- commands/moderation/ban.js | 22 +++++--------- commands/moderation/kick.js | 22 +++++--------- commands/moderation/lockdown.js | 14 +++------ commands/moderation/prune.js | 17 +++-------- commands/moderation/softban.js | 24 +++++---------- commands/moderation/unban.js | 22 +++++--------- commands/moderation/warn.js | 17 ++++------- commands/numedit/currency.js | 2 +- commands/numedit/math.js | 7 ++--- commands/numedit/temperature.js | 2 +- commands/random/cleverbot.js | 5 ++- commands/random/easter-egg.js | 2 +- commands/random/give-flower.js | 2 +- commands/random/horoscope.js | 6 ++-- commands/random/lenny.js | 2 +- commands/random/meme.js | 6 ++-- commands/random/nitro.js | 8 ++--- commands/random/soundboard.js | 11 +++---- commands/random/spam.js | 8 ++--- commands/random/star.js | 4 +-- commands/random/strawpoll.js | 2 +- commands/random/today.js | 8 ++--- commands/random/would-you-rather.js | 8 ++--- commands/randomimg/cat.js | 2 +- commands/randomimg/dog.js | 2 +- commands/randomimg/vocaloid.js | 2 +- commands/randomimg/xiao.js | 8 ++--- commands/randomimg/xkcd.js | 6 ++-- commands/response/8-ball.js | 2 +- commands/response/choose.js | 2 +- commands/response/coin.js | 2 +- commands/response/compliment.js | 2 +- commands/response/fact-core.js | 2 +- commands/response/fishy.js | 2 +- commands/response/fortune.js | 2 +- commands/response/magic-conch.js | 2 +- commands/response/name.js | 2 +- commands/response/offspring.js | 2 +- commands/response/quantum-coin.js | 2 +- commands/response/rate-waifu.js | 2 +- commands/response/roast.js | 2 +- commands/response/roll.js | 2 +- commands/response/roulette.js | 2 +- commands/response/ship.js | 2 +- commands/roleplay/cuddle.js | 2 +- commands/roleplay/divorce.js | 2 +- commands/roleplay/eat.js | 2 +- commands/roleplay/falcon-punch.js | 2 +- commands/roleplay/fist-bump.js | 2 +- commands/roleplay/high-five.js | 2 +- commands/roleplay/hit-with-shovel.js | 2 +- commands/roleplay/hug.js | 2 +- commands/roleplay/inhale.js | 2 +- commands/roleplay/kill.js | 2 +- commands/roleplay/kiss.js | 2 +- commands/roleplay/marry.js | 2 +- commands/roleplay/pat.js | 2 +- commands/roleplay/poke.js | 2 +- commands/roleplay/punch.js | 2 +- commands/roleplay/slap.js | 2 +- commands/search/anime.js | 6 ++-- commands/search/bot-info.js | 8 ++--- commands/search/bulbapedia.js | 6 ++-- commands/search/danbooru.js | 5 +-- commands/search/define.js | 6 ++-- commands/search/discrim.js | 6 ++-- commands/search/forecast.js | 6 ++-- commands/search/gelbooru.js | 4 +-- commands/search/giphy.js | 2 +- commands/search/github.js | 6 ++-- commands/search/google.js | 2 +- commands/search/konachan.js | 4 +-- commands/search/lmgtfy.js | 2 +- commands/search/manga.js | 6 ++-- commands/search/map.js | 6 ++-- commands/search/neopet.js | 2 +- commands/search/osu.js | 6 ++-- commands/search/rule34.js | 4 +-- commands/search/soundcloud.js | 6 ++-- commands/search/urban.js | 6 ++-- commands/search/wattpad.js | 8 ++--- commands/search/weather.js | 6 ++-- commands/search/wikipedia.js | 6 ++-- commands/search/youtube.js | 6 ++-- commands/search/yu-gi-oh.js | 6 ++-- commands/settings/clear-setting.js | 8 ++--- commands/settings/invite-guard.js | 10 ++---- commands/settings/join-role.js | 8 ++--- commands/settings/member-channel.js | 8 ++--- commands/settings/member-message.js | 8 ++--- commands/settings/mod-channel.js | 8 ++--- commands/settings/setting-list.js | 2 +- commands/settings/single-role.js | 8 ++--- commands/settings/staff-role.js | 8 ++--- commands/settings/starboard.js | 8 ++--- commands/textedit/binary.js | 20 ++++++------ commands/textedit/cow-say.js | 2 +- commands/textedit/embed.js | 6 ++-- commands/textedit/morse.js | 2 +- commands/textedit/pirate.js | 2 +- commands/textedit/repeat.js | 2 +- commands/textedit/reverse.js | 2 +- commands/textedit/say.js | 5 ++- commands/textedit/temmie.js | 2 +- commands/textedit/translate.js | 6 ++-- commands/textedit/upside-down.js | 2 +- commands/textedit/webhook.js | 6 ++-- commands/textedit/zalgo.js | 2 +- commands/userinfo/avatar.js | 2 +- commands/userinfo/user-info.js | 6 ++-- commands/util/help.js | 11 +++---- commands/util/info.js | 8 ++--- commands/util/invite.js | 2 +- commands/util/ping.js | 7 ++--- commands/util/shard-info.js | 6 ++-- commands/util/uptime.js | 2 +- package.json | 4 +-- structures/Command.js | 44 +++++++++++++++++++++++++++ structures/Stats.js | 2 +- 142 files changed, 351 insertions(+), 495 deletions(-) create mode 100644 structures/Command.js diff --git a/XiaoBot.js b/XiaoBot.js index 39344bd3..8387cedf 100644 --- a/XiaoBot.js +++ b/XiaoBot.js @@ -65,7 +65,7 @@ client.dispatcher.addInhibitor(msg => { return ['singleRole', msg.reply(`Only the ${msg.guild.roles.get(role).name} role may use commands.`)]; }); -client.on('message', async (msg) => { +client.on('message', (msg) => { if (msg.guild && msg.guild.settings.get('inviteGuard') && /(discord(\.gg\/|app\.com\/invite\/|\.me\/))/gi.test(msg.content)) { if (msg.author.bot || msg.member.hasPermission('ADMINISTRATOR') || @@ -73,9 +73,8 @@ client.on('message', async (msg) => { msg.member.roles.has(msg.guild.settings.get('staffRole')) || !msg.channel.permissionsFor(client.user).has('SEND_MESSAGES')) return; if (msg.channel.permissionsFor(client.user).has('MANAGE_MESSAGES')) msg.delete(); - else msg.channel.send('Message could not be deleted, missing the `Manage Messages` permission.'); return msg.reply('Invites are prohibited from being posted here.'); - } else return; + } }); client.on('messageReactionAdd', (reaction, user) => { @@ -84,8 +83,7 @@ client.on('messageReactionAdd', (reaction, user) => { const channel = msg.guild.channels.get(msg.guild.settings.get('starboard')); if (!channel) return; if (user.id === msg.author.id) { - if (msg.channel.permissionsFor(client.user).has('MANAGE_MESSAGES')) - reaction.remove(user); + if (msg.channel.permissionsFor(client.user).has('MANAGE_MESSAGES')) reaction.remove(user); return msg.reply('You cannot star your own messages, baka.'); } client.registry.resolveCommand('random:star').run(msg, { id: msg.id }, true); @@ -93,8 +91,7 @@ client.on('messageReactionAdd', (reaction, user) => { client.on('guildMemberAdd', (member) => { const role = member.guild.roles.get(member.guild.settings.get('joinRole')); - if (member.guild.me.hasPermission('MANAGE_ROLES') && role) - member.addRole(role).catch(() => null); + if (role && member.guild.me.hasPermission('MANAGE_ROLES')) member.addRole(role).catch(() => null); const channel = member.guild.channels.get(member.guild.settings.get('memberLog')); if (!channel) return; if (!channel.permissionsFor(client.user).has('SEND_MESSAGES')) return; diff --git a/commands/avataredit/3000-years.js b/commands/avataredit/3000-years.js index 4e0063dc..44a1d2c3 100644 --- a/commands/avataredit/3000-years.js +++ b/commands/avataredit/3000-years.js @@ -1,4 +1,4 @@ -const { Command } = require('discord.js-commando'); +const Command = require('../../structures/Command'); const Canvas = require('canvas'); const snekfetch = require('snekfetch'); const { promisifyAll } = require('tsubaki'); @@ -11,12 +11,13 @@ module.exports = class YearsCommand extends Command { name: '3000-years', aliases: ['az'], group: 'avataredit', - memberName: '3000years', + memberName: '3000-years', description: 'It\'s been 3000 years...', throttling: { usages: 1, duration: 15 }, + clientPermissions: ['ATTACH_FILES'], args: [ { key: 'user', @@ -28,9 +29,6 @@ module.exports = class YearsCommand extends Command { } async run(msg, args) { - if (msg.channel.type !== 'dm') - if (!msg.channel.permissionsFor(this.client.user).has('ATTACH_FILES')) - return msg.say('This Command requires the `Attach Files` Permission.'); const { user } = args; const avatarURL = user.avatarURL('png', 256); if (!avatarURL) return msg.say('This user has no avatar.'); diff --git a/commands/avataredit/beautiful.js b/commands/avataredit/beautiful.js index 3f96410c..2a695b9a 100644 --- a/commands/avataredit/beautiful.js +++ b/commands/avataredit/beautiful.js @@ -1,4 +1,4 @@ -const { Command } = require('discord.js-commando'); +const Command = require('../../structures/Command'); const Canvas = require('canvas'); const snekfetch = require('snekfetch'); const { promisifyAll } = require('tsubaki'); @@ -17,6 +17,7 @@ module.exports = class BeautifulCommand extends Command { usages: 1, duration: 15 }, + clientPermissions: ['ATTACH_FILES'], args: [ { key: 'user', @@ -28,9 +29,6 @@ module.exports = class BeautifulCommand extends Command { } async run(msg, args) { - if (msg.channel.type !== 'dm') - if (!msg.channel.permissionsFor(this.client.user).has('ATTACH_FILES')) - return msg.say('This Command requires the `Attach Files` Permission.'); const { user } = args; const avatarURL = user.avatarURL('png', 256); if (!avatarURL) return msg.say('This user has no avatar.'); diff --git a/commands/avataredit/bob-ross.js b/commands/avataredit/bob-ross.js index b313b2ba..0e8decaa 100644 --- a/commands/avataredit/bob-ross.js +++ b/commands/avataredit/bob-ross.js @@ -1,4 +1,4 @@ -const { Command } = require('discord.js-commando'); +const Command = require('../../structures/Command'); const Canvas = require('canvas'); const snekfetch = require('snekfetch'); const { promisifyAll } = require('tsubaki'); @@ -17,6 +17,7 @@ module.exports = class BobRossCommand extends Command { usages: 1, duration: 15 }, + clientPermissions: ['ATTACH_FILES'], args: [ { key: 'user', @@ -28,9 +29,6 @@ module.exports = class BobRossCommand extends Command { } async run(msg, args) { - if (msg.channel.type !== 'dm') - if (!msg.channel.permissionsFor(this.client.user).has('ATTACH_FILES')) - return msg.say('This Command requires the `Attach Files` Permission.'); const { user } = args; const avatarURL = user.avatarURL('png', 256); if (!avatarURL) return msg.say('This user has no avatar.'); diff --git a/commands/avataredit/card.js b/commands/avataredit/card.js index 8f4e3453..dd0b5f8c 100644 --- a/commands/avataredit/card.js +++ b/commands/avataredit/card.js @@ -1,4 +1,4 @@ -const { Command } = require('discord.js-commando'); +const Command = require('../../structures/Command'); const Canvas = require('canvas'); const snekfetch = require('snekfetch'); const moment = require('moment'); @@ -20,6 +20,7 @@ module.exports = class CardCommand extends Command { usages: 1, duration: 15 }, + clientPermissions: ['ATTACH_FILES'], args: [ { key: 'member', @@ -31,16 +32,14 @@ module.exports = class CardCommand extends Command { } async run(msg, args) { - if (!msg.channel.permissionsFor(this.client.user).has('ATTACH_FILES')) - return msg.say('This Command requires the `Attach Files` Permission.'); const { member } = args; + const avatarURL = member.user.avatarURL('png', 512); + if (!avatarURL) return msg.say('This user 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'; - const avatarURL = member.user.avatarURL('png', 512); - if (!avatarURL) return msg.say('This user has no avatar.'); try { const Image = Canvas.Image; Canvas.registerFont(path.join(__dirname, '..', '..', 'assets', 'fonts', 'OpenSans.ttf'), { family: 'Open Sans' }); diff --git a/commands/avataredit/challenger.js b/commands/avataredit/challenger.js index 5129d45f..10147a02 100644 --- a/commands/avataredit/challenger.js +++ b/commands/avataredit/challenger.js @@ -1,4 +1,4 @@ -const { Command } = require('discord.js-commando'); +const Command = require('../../structures/Command'); const Canvas = require('canvas'); const snekfetch = require('snekfetch'); const { promisifyAll } = require('tsubaki'); @@ -16,6 +16,7 @@ module.exports = class ChallengerCommand extends Command { usages: 1, duration: 15 }, + clientPermissions: ['ATTACH_FILES'], args: [ { key: 'user', @@ -27,9 +28,6 @@ module.exports = class ChallengerCommand extends Command { } async run(msg, args) { - if (msg.channel.type !== 'dm') - if (!msg.channel.permissionsFor(this.client.user).has('ATTACH_FILES')) - return msg.say('This Command requires the `Attach Files` Permission.'); const { user } = args; const avatarURL = user.avatarURL('png', 256); if (!avatarURL) return msg.say('This user has no avatar.'); diff --git a/commands/avataredit/dexter.js b/commands/avataredit/dexter.js index a7f84bde..ef82ec30 100644 --- a/commands/avataredit/dexter.js +++ b/commands/avataredit/dexter.js @@ -1,4 +1,4 @@ -const { Command } = require('discord.js-commando'); +const Command = require('../../structures/Command'); const Canvas = require('canvas'); const snekfetch = require('snekfetch'); const { promisifyAll } = require('tsubaki'); @@ -16,6 +16,7 @@ module.exports = class DexterCommand extends Command { usages: 1, duration: 15 }, + clientPermissions: ['ATTACH_FILES'], args: [ { key: 'user', @@ -27,9 +28,6 @@ module.exports = class DexterCommand extends Command { } async run(msg, args) { - if (msg.channel.type !== 'dm') - if (!msg.channel.permissionsFor(this.client.user).has('ATTACH_FILES')) - return msg.say('This Command requires the `Attach Files` Permission.'); const { user } = args; const avatarURL = user.avatarURL('png', 256); if (!avatarURL) return msg.say('This user has no avatar.'); diff --git a/commands/avataredit/greyscale.js b/commands/avataredit/greyscale.js index c6383977..94b9cbdb 100644 --- a/commands/avataredit/greyscale.js +++ b/commands/avataredit/greyscale.js @@ -1,4 +1,4 @@ -const { Command } = require('discord.js-commando'); +const Command = require('../../structures/Command'); const Canvas = require('canvas'); const snekfetch = require('snekfetch'); @@ -14,6 +14,7 @@ module.exports = class GreyscaleCommand extends Command { usages: 1, duration: 15 }, + clientPermissions: ['ATTACH_FILES'], args: [ { key: 'user', @@ -25,9 +26,6 @@ module.exports = class GreyscaleCommand extends Command { } async run(msg, args) { - if (msg.channel.type !== 'dm') - if (!msg.channel.permissionsFor(this.client.user).has('ATTACH_FILES')) - return msg.say('This Command requires the `Attach Files` Permission.'); const { user } = args; const avatarURL = user.avatarURL('png', 256); if (!avatarURL) return msg.say('This user has no avatar.'); @@ -39,7 +37,7 @@ module.exports = class GreyscaleCommand extends Command { const generate = () => { ctx.drawImage(avatar, 0, 0, 256, 256); const imgData = ctx.getImageData(0, 0, 256, 256); - const data = imgData.data; + const { data } = imgData; for (let i = 0; i < data.length; i += 4) { const brightness = 0.34 * data[i] + 0.5 * data[i + 1] + 0.16 * data[i + 2]; data[i] = brightness; diff --git a/commands/avataredit/invert.js b/commands/avataredit/invert.js index 61f9653f..e4ac8218 100644 --- a/commands/avataredit/invert.js +++ b/commands/avataredit/invert.js @@ -1,4 +1,4 @@ -const { Command } = require('discord.js-commando'); +const Command = require('../../structures/Command'); const Canvas = require('canvas'); const snekfetch = require('snekfetch'); @@ -13,6 +13,7 @@ module.exports = class InvertCommand extends Command { usages: 1, duration: 15 }, + clientPermissions: ['ATTACH_FILES'], args: [ { key: 'user', @@ -24,9 +25,6 @@ module.exports = class InvertCommand extends Command { } async run(msg, args) { - if (msg.channel.type !== 'dm') - if (!msg.channel.permissionsFor(this.client.user).has('ATTACH_FILES')) - return msg.say('This Command requires the `Attach Files` Permission.'); const { user } = args; const avatarURL = user.avatarURL('png', 256); if (!avatarURL) return msg.say('This user has no avatar.'); @@ -38,7 +36,7 @@ module.exports = class InvertCommand extends Command { const generate = () => { ctx.drawImage(avatar, 0, 0, 256, 256); const imgData = ctx.getImageData(0, 0, 256, 256); - const data = imgData.data; + const { data } = imgData; for (let i = 0; i < data.length; i += 4) { data[i] = 255 - data[i]; data[i + 1] = 255 - data[i + 1]; @@ -46,8 +44,8 @@ module.exports = class InvertCommand extends Command { } ctx.putImageData(imgData, 0, 0); }; - const avatarImg = await snekfetch.get(avatarURL); - avatar.src = avatarImg.body; + const { body } = await snekfetch.get(avatarURL); + avatar.src = body; generate(); return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'invert.png' }] }) .catch(err => msg.say(`${err.name}: ${err.message}`)); diff --git a/commands/avataredit/rip.js b/commands/avataredit/rip.js index 16ba8a9b..7790142a 100644 --- a/commands/avataredit/rip.js +++ b/commands/avataredit/rip.js @@ -1,4 +1,4 @@ -const { Command } = require('discord.js-commando'); +const Command = require('../../structures/Command'); const Canvas = require('canvas'); const snekfetch = require('snekfetch'); const { promisifyAll } = require('tsubaki'); @@ -17,6 +17,7 @@ module.exports = class RIPCommand extends Command { usages: 1, duration: 15 }, + clientPermissions: ['ATTACH_FILES'], args: [ { key: 'user', @@ -28,9 +29,6 @@ module.exports = class RIPCommand extends Command { } async run(msg, args) { - if (msg.channel.type !== 'dm') - if (!msg.channel.permissionsFor(this.client.user).has('ATTACH_FILES')) - return msg.say('This Command requires the `Attach Files` Permission.'); const { user } = args; const avatarURL = user.avatarURL('png', 256); if (!avatarURL) return msg.say('This User has no Avatar.'); @@ -44,7 +42,7 @@ module.exports = class RIPCommand extends Command { ctx.drawImage(base, 0, 0); ctx.drawImage(avatar, 158, 51, 200, 200); const imgData = ctx.getImageData(158, 51, 200, 200); - const data = imgData.data; + const { data } = imgData; for (let i = 0; i < data.length; i += 4) { const brightness = 0.34 * data[i] + 0.5 * data[i + 1] + 0.16 * data[i + 2]; data[i] = brightness; @@ -54,8 +52,8 @@ module.exports = class RIPCommand extends Command { ctx.putImageData(imgData, 158, 51); }; base.src = await fs.readFileAsync(path.join(__dirname, '..', '..', 'assets', 'images', 'rip.png')); - const avatarImg = await snekfetch.get(avatarURL); - avatar.src = avatarImg.body; + const { body } = await snekfetch.get(avatarURL); + avatar.src = body; generate(); return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'rip.png' }] }) .catch(err => msg.say(`${err.name}: ${err.message}`)); diff --git a/commands/avataredit/simba.js b/commands/avataredit/simba.js index e997333d..1f5335dc 100644 --- a/commands/avataredit/simba.js +++ b/commands/avataredit/simba.js @@ -1,4 +1,4 @@ -const { Command } = require('discord.js-commando'); +const Command = require('../../structures/Command'); const Canvas = require('canvas'); const snekfetch = require('snekfetch'); const { promisifyAll } = require('tsubaki'); @@ -16,6 +16,7 @@ module.exports = class SimbaCommand extends Command { usages: 1, duration: 15 }, + clientPermissions: ['ATTACH_FILES'], args: [ { key: 'user', @@ -27,9 +28,6 @@ module.exports = class SimbaCommand extends Command { } async run(msg, args) { - if (msg.channel.type !== 'dm') - if (!msg.channel.permissionsFor(this.client.user).has('ATTACH_FILES')) - return msg.say('This Command requires the `Attach Files` Permission.'); const { user } = args; const avatarURL = user.avatarURL('png', 256); if (!avatarURL) return msg.say('This user has no avatar.'); diff --git a/commands/avataredit/steam-card.js b/commands/avataredit/steam-card.js index 51ea5d56..0740155d 100644 --- a/commands/avataredit/steam-card.js +++ b/commands/avataredit/steam-card.js @@ -1,4 +1,4 @@ -const { Command } = require('discord.js-commando'); +const Command = require('../../structures/Command'); const Canvas = require('canvas'); const snekfetch = require('snekfetch'); const { promisifyAll } = require('tsubaki'); @@ -16,6 +16,7 @@ module.exports = class SteamCardCommand extends Command { usages: 1, duration: 15 }, + clientPermissions: ['ATTACH_FILES'], args: [ { key: 'user', @@ -27,11 +28,7 @@ module.exports = class SteamCardCommand extends Command { } async run(msg, args) { - if (msg.channel.type !== 'dm') - if (!msg.channel.permissionsFor(this.client.user).has('ATTACH_FILES')) - return msg.say('This Command requires the `Attach Files` Permission.'); const { user } = args; - const username = msg.guild ? (msg.guild.member(user) ? msg.guild.member(user).displayName : user.username) : user.username; const avatarURL = user.avatarURL('png', 512); if (!avatarURL) return msg.say('This user has no avatar.'); try { @@ -47,13 +44,13 @@ module.exports = class SteamCardCommand extends Command { ctx.drawImage(avatar, 25, 25, 450, 450); ctx.drawImage(base, 0, 0); ctx.font = '30px Open Sans'; - ctx.fillText(username, 35, 48); + ctx.fillText(user.username, 35, 48); }; base.src = await fs.readFileAsync(path.join(__dirname, '..', '..', 'assets', 'images', 'steam-card.png')); const { body } = await snekfetch.get(avatarURL); avatar.src = body; generate(); - return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'card.png' }] }) + return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'steam.png' }] }) .catch(err => msg.say(`${err.name}: ${err.message}`)); } catch (err) { return msg.say(`${err.name}: ${err.message}`); diff --git a/commands/avataredit/triggered.js b/commands/avataredit/triggered.js index 177a343f..b5459556 100644 --- a/commands/avataredit/triggered.js +++ b/commands/avataredit/triggered.js @@ -1,4 +1,4 @@ -const { Command } = require('discord.js-commando'); +const Command = require('../../structures/Command'); const Canvas = require('canvas'); const snekfetch = require('snekfetch'); const { promisifyAll } = require('tsubaki'); @@ -16,6 +16,7 @@ module.exports = class TriggeredCommand extends Command { usages: 1, duration: 15 }, + clientPermissions: ['ATTACH_FILES'], args: [ { key: 'user', @@ -27,9 +28,6 @@ module.exports = class TriggeredCommand extends Command { } async run(msg, args) { - if (msg.channel.type !== 'dm') - if (!msg.channel.permissionsFor(this.client.user).has('ATTACH_FILES')) - return msg.say('This Command requires the `Attach Files` Permission.'); const { user } = args; const avatarURL = user.avatarURL('png', 512); if (!avatarURL) return msg.say('This user has no avatar.'); @@ -44,7 +42,7 @@ module.exports = class TriggeredCommand extends Command { ctx.fillRect(0, 0, 320, 371); ctx.drawImage(avatar, 0, 0, 320, 320); const imgData = ctx.getImageData(0, 0, 320, 320); - const data = imgData.data; + const { data } = imgData; for (let i = 0; i < data.length; i += 4) { data[i] = Math.max(255, data[i]); } diff --git a/commands/avataredit/wanted.js b/commands/avataredit/wanted.js index f4ba6934..f9195064 100644 --- a/commands/avataredit/wanted.js +++ b/commands/avataredit/wanted.js @@ -1,4 +1,4 @@ -const { Command } = require('discord.js-commando'); +const Command = require('../../structures/Command'); const Canvas = require('canvas'); const snekfetch = require('snekfetch'); const { promisifyAll } = require('tsubaki'); @@ -16,6 +16,7 @@ module.exports = class WantedCommand extends Command { usages: 1, duration: 15 }, + clientPermissions: ['ATTACH_FILES'], args: [ { key: 'user', @@ -27,9 +28,6 @@ module.exports = class WantedCommand extends Command { } async run(msg, args) { - if (msg.channel.type !== 'dm') - if (!msg.channel.permissionsFor(this.client.user).has('ATTACH_FILES')) - return msg.say('This Command requires the `Attach Files` Permission.'); const { user } = args; const avatarURL = user.avatarURL('png', 512); if (!avatarURL) return msg.say('This user has no avatar.'); diff --git a/commands/games/battle.js b/commands/games/battle.js index 6d0d68b8..c459ab69 100644 --- a/commands/games/battle.js +++ b/commands/games/battle.js @@ -1,4 +1,4 @@ -const { Command } = require('discord.js-commando'); +const Command = require('../../structures/Command'); const { stripIndents } = require('common-tags'); module.exports = class BattleCommand extends Command { diff --git a/commands/games/lottery.js b/commands/games/lottery.js index 4ed4c36b..bb55d2c4 100644 --- a/commands/games/lottery.js +++ b/commands/games/lottery.js @@ -1,4 +1,4 @@ -const { Command } = require('discord.js-commando'); +const Command = require('../../structures/Command'); module.exports = class LotteryCommand extends Command { constructor(client) { diff --git a/commands/games/math-game.js b/commands/games/math-game.js index 7fb506ba..944ad912 100644 --- a/commands/games/math-game.js +++ b/commands/games/math-game.js @@ -1,4 +1,4 @@ -const { Command } = require('discord.js-commando'); +const Command = require('../../structures/Command'); const { RichEmbed } = require('discord.js'); const math = require('mathjs'); const operations = ['+', '-', '*']; @@ -10,6 +10,7 @@ module.exports = class MathGameCommand extends Command { group: 'games', memberName: 'math-game', description: 'See how fast you can answer a math problem in a given time limit.', + clientPermissions: ['EMBED_LINKS'], args: [ { key: 'difficulty', @@ -26,9 +27,6 @@ module.exports = class MathGameCommand extends Command { } async run(msg, args) { - if (msg.channel.type !== 'dm') - if (!msg.channel.permissionsFor(this.client.user).has('EMBED_LINKS')) - return msg.say('This Command requires the `Embed Links` Permission.'); const { difficulty } = args; const operation = operations[Math.floor(Math.random() * operations.length)]; let value; @@ -50,22 +48,21 @@ module.exports = class MathGameCommand extends Command { break; } const expression = `${Math.floor(Math.random() * value) + 1} ${operation} ${Math.floor(Math.random() * value) + 1}`; - const solved = math.eval(expression).toString(); + const answer = math.eval(expression).toString(); const embed = new RichEmbed() .setTitle('You have **10** seconds to answer:') .setDescription(expression); - msg.embed(embed); + await msg.embed(embed); try { const collected = await msg.channel.awaitMessages(res => res.author.id === msg.author.id, { max: 1, time: 10000, errors: ['time'] }); - if (collected.first().content !== solved) - return msg.say(`Nope! The correct answer is: ${solved}.`); - return msg.say(`Perfect! ${solved} is the correct answer!`); + if (collected.first().content !== answer) return msg.say(`Nope, sorry, it's ${answer}.`); + return msg.say('Nice job! 10/10! You deserve some cake!'); } catch (err) { - return msg.say(`Time! The correct answer is ${solved}.`); + return msg.say(`Time! It was ${answer}, sorry!`); } } }; diff --git a/commands/games/quiz.js b/commands/games/quiz.js index b8514c34..baad1f4e 100644 --- a/commands/games/quiz.js +++ b/commands/games/quiz.js @@ -1,4 +1,4 @@ -const { Command } = require('discord.js-commando'); +const Command = require('../../structures/Command'); const { RichEmbed } = require('discord.js'); const { stripIndents } = require('common-tags'); const snekfetch = require('snekfetch'); @@ -10,14 +10,12 @@ module.exports = class QuizCommand extends Command { aliases: ['jeopardy'], group: 'games', memberName: 'quiz', - description: 'Answer a quiz question.' + description: 'Answer a quiz question.', + clientPermissions: ['EMBED_LINKS'] }); } async run(msg) { - if (msg.channel.type !== 'dm') - if (!msg.channel.permissionsFor(this.client.user).has('EMBED_LINKS')) - return msg.say('This Command requires the `Embed Links` Permission.'); try { const { body } = await snekfetch .get('https://opentdb.com/api.php') @@ -33,15 +31,14 @@ module.exports = class QuizCommand extends Command { **${decodeURIComponent(body.results[0].category)}** True or False: ${decodeURIComponent(body.results[0].question)} `); - msg.embed(embed); + await msg.embed(embed); try { const collected = await msg.channel.awaitMessages(res => res.author.id === msg.author.id, { max: 1, time: 15000, errors: ['time'] }); - if (collected.first().content.toLowerCase() !== answer) - return msg.say(`Nope, sorry, it\'s ${answer}.`); + if (collected.first().content.toLowerCase() !== answer) return msg.say(`Nope, sorry, it's ${answer}.`); 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 631a25de..e5f7dd39 100644 --- a/commands/games/rock-paper-scissors.js +++ b/commands/games/rock-paper-scissors.js @@ -1,4 +1,4 @@ -const { Command } = require('discord.js-commando'); +const Command = require('../../structures/Command'); const responses = ['Paper', 'Rock', 'Scissors']; module.exports = class RockPaperScissorsCommand extends Command { diff --git a/commands/games/slots.js b/commands/games/slots.js index 62fe0184..33fbaf9b 100644 --- a/commands/games/slots.js +++ b/commands/games/slots.js @@ -1,4 +1,4 @@ -const { Command } = require('discord.js-commando'); +const Command = require('../../structures/Command'); const { stripIndents } = require('common-tags'); const slotThing = [':grapes:', ':tangerine:', ':pear:', ':cherries:']; diff --git a/commands/games/typing-game.js b/commands/games/typing-game.js index 68ce74a9..db2d41bf 100644 --- a/commands/games/typing-game.js +++ b/commands/games/typing-game.js @@ -1,4 +1,4 @@ -const { Command } = require('discord.js-commando'); +const Command = require('../../structures/Command'); const { RichEmbed } = require('discord.js'); const sentences = require('../../assets/json/typing-game'); @@ -9,6 +9,7 @@ module.exports = class TypingGameCommand extends Command { group: 'games', memberName: 'typing-game', description: 'See how fast you can type a sentence in a given time limit.', + clientPermissions: ['EMBED_LINKS'], args: [ { key: 'difficulty', @@ -25,9 +26,6 @@ module.exports = class TypingGameCommand extends Command { } async run(msg, args) { - if (msg.channel.type !== 'dm') - if (!msg.channel.permissionsFor(this.client.user).has('EMBED_LINKS')) - return msg.say('This Command requires the `Embed Links` Permission.'); const { difficulty } = args; const sentence = sentences[Math.floor(Math.random() * sentences.length)]; let time; @@ -51,18 +49,17 @@ module.exports = class TypingGameCommand extends Command { const embed = new RichEmbed() .setTitle(`You have **${time / 1000}** seconds to type:`) .setDescription(sentence); - msg.embed(embed); + await msg.embed(embed); try { const collected = await msg.channel.awaitMessages(res => res.author.id === msg.author.id, { max: 1, time: time, errors: ['time'] }); - if (collected.first().content !== sentence) - return msg.say('Nope, your sentence does not match the original. Try again next time!'); + if (collected.first().content !== sentence) return msg.say('Nope, sorry!'); return msg.say(`Good Job! You won!`); } catch (err) { - return msg.say('Time! Try again next time!'); + return msg.say('Time! Sorry!'); } } }; diff --git a/commands/guildinfo/emoji.js b/commands/guildinfo/emoji.js index 7e0c8804..fa6e945d 100644 --- a/commands/guildinfo/emoji.js +++ b/commands/guildinfo/emoji.js @@ -1,4 +1,4 @@ -const { Command } = require('discord.js-commando'); +const Command = require('../../structures/Command'); module.exports = class EmojiCommand extends Command { constructor(client) { @@ -6,13 +6,13 @@ module.exports = class EmojiCommand extends Command { name: 'emoji', group: 'guildinfo', memberName: 'emoji', - description: 'Gives a list of the current server\'s custom emoji.', + description: 'Gives a list of the server\'s custom emoji.', guildOnly: true }); } run(msg) { return msg.say(msg.guild.emojis.map(e => e).join('')) - .catch(() => msg.say('There was an error sending the emoji. Perhaps you have no custom emoji?')); + .catch(() => msg.say('There was an error sending the emoji.')); } }; diff --git a/commands/guildinfo/server-info.js b/commands/guildinfo/server-info.js index ee92017e..485ad877 100644 --- a/commands/guildinfo/server-info.js +++ b/commands/guildinfo/server-info.js @@ -1,4 +1,4 @@ -const { Command } = require('discord.js-commando'); +const Command = require('../../structures/Command'); const { RichEmbed } = require('discord.js'); const { stripIndents } = require('common-tags'); const moment = require('moment'); @@ -11,14 +11,13 @@ module.exports = class GuildInfoCommand extends Command { aliases: ['guild', 'server', 'guild-info'], group: 'guildinfo', memberName: 'server-info', - description: 'Gives some info on the current server.', - guildOnly: true + description: 'Gives some info on the server.', + guildOnly: true, + clientPermissions: ['EMBED_LINKS'] }); } run(msg) { - if (!msg.channel.permissionsFor(this.client.user).has('EMBED_LINKS')) - return msg.say('This Command requires the `Embed Links` Permission.'); const embed = new RichEmbed() .setColor(0x00AE86) .setThumbnail(msg.guild.iconURL()) diff --git a/commands/moderation/ban.js b/commands/moderation/ban.js index fc7c6d39..a4b1b403 100644 --- a/commands/moderation/ban.js +++ b/commands/moderation/ban.js @@ -1,4 +1,4 @@ -const { Command } = require('discord.js-commando'); +const Command = require('../../structures/Command'); const { RichEmbed } = require('discord.js'); const { stripIndents } = require('common-tags'); @@ -11,6 +11,9 @@ module.exports = class BanCommand extends Command { memberName: 'ban', description: 'Bans a user and logs the ban to the mod logs.', guildOnly: true, + clientPermissions: ['BAN_MEMBERS'], + userPermissions: ['BAN_MEMBERS'], + allowStaff: true, args: [ { key: 'member', @@ -30,22 +33,13 @@ module.exports = class BanCommand extends Command { }); } - hasPermission(msg) { - const staffRole = msg.guild.roles.get(msg.guild.settings.get('staffRole')); - if (staffRole && !msg.member.roles.has(staffRole.id)) return `You do not have the ${staffRole.name} role.`; - else if (!msg.member.hasPermission('BAN_MEMBERS')) return 'You do not have the `Ban Members` Permission.'; - else return true; - } - async run(msg, args) { - if (!msg.channel.permissionsFor(this.client.user).has('BAN_MEMBERS')) - return msg.say('This Command requires the `Ban Members` Permission.'); const modlogs = msg.guild.channels.get(msg.guild.settings.get('modLog')); - if (!modlogs) return msg.say('This Command requires a channel set with the `modchannel` command.'); + if (!modlogs) return msg.say('This Command requires a channel set with the `mod-channel` command.'); if (!modlogs.permissionsFor(this.client.user).has('SEND_MESSAGES')) - return msg.say('This Command requires the `Send Messages` Permission for the Mod Log Channel.'); + return msg.say('This Command requires the `SEND_MESSAGES` Permission for the Mod Log Channel.'); if (!modlogs.permissionsFor(this.client.user).has('EMBED_LINKS')) - return msg.say('This Command requires the `Embed Links` Permission.'); + return msg.say('This Command requires the `EMBED_LINKS` Permission for the Mod Log Channel.'); const { member, reason } = args; if (!member.bannable) return msg.say('This member is not bannable. Perhaps they have a higher role than me?'); try { @@ -68,7 +62,7 @@ module.exports = class BanCommand extends Command { **Action:** Ban **Reason:** ${reason} `); - await modlogs.send({ embed }); + modlogs.send({ embed }); return null; } catch (err) { return msg.say(`${err.name}: ${err.message}`); diff --git a/commands/moderation/kick.js b/commands/moderation/kick.js index a7d33d50..d131412c 100644 --- a/commands/moderation/kick.js +++ b/commands/moderation/kick.js @@ -1,4 +1,4 @@ -const { Command } = require('discord.js-commando'); +const Command = require('../../structures/Command'); const { RichEmbed } = require('discord.js'); const { stripIndents } = require('common-tags'); @@ -10,6 +10,9 @@ module.exports = class KickCommand extends Command { memberName: 'kick', description: 'Kicks a user and logs the kick to the mod logs.', guildOnly: true, + clientPermissions: ['KICK_MEMBERS'], + userPermissions: ['KICK_MEMBERS'], + allowStaff: true, args: [ { key: 'member', @@ -29,22 +32,13 @@ module.exports = class KickCommand extends Command { }); } - hasPermission(msg) { - const staffRole = msg.guild.roles.get(msg.guild.settings.get('staffRole')); - if (staffRole && !msg.member.roles.has(staffRole.id)) return `You do not have the ${staffRole.name} role.`; - else if (!msg.member.hasPermission('KICK_MEMBERS')) return 'You do not have the `Kick Members` Permission.'; - else return true; - } - async run(msg, args) { - if (!msg.channel.permissionsFor(this.client.user).has('KICK_MEMBERS')) - return msg.say('This Command requires the `Kick Members` Permission.'); const modlogs = msg.guild.channels.get(msg.guild.settings.get('modLog')); - if (!modlogs) return msg.say('This Command requires a channel set with the `modchannel` command.'); + if (!modlogs) return msg.say('This Command requires a channel set with the `mod-channel` command.'); if (!modlogs.permissionsFor(this.client.user).has('SEND_MESSAGES')) - return msg.say('This Command requires the `Send Messages` Permission for the Mod Log Channel.'); + return msg.say('This Command requires the `SEND_MESSAGES` Permission for the Mod Log Channel.'); if (!modlogs.permissionsFor(this.client.user).has('EMBED_LINKS')) - return msg.say('This Command requires the `Embed Links` Permission.'); + return msg.say('This Command requires the `EMBED_LINKS` Permission for the Mod Log Channel.'); const { member, reason } = args; if (!member.kickable) return msg.say('This member is not kickable. Perhaps they have a higher role than me?'); try { @@ -67,7 +61,7 @@ module.exports = class KickCommand extends Command { **Action:** Kick **Reason:** ${reason} `); - await modlogs.send({ embed }); + modlogs.send({ embed }); return null; } catch (err) { return msg.say(`${err.name}: ${err.message}`); diff --git a/commands/moderation/lockdown.js b/commands/moderation/lockdown.js index d77a8ed6..ebdb4c18 100644 --- a/commands/moderation/lockdown.js +++ b/commands/moderation/lockdown.js @@ -1,4 +1,4 @@ -const { Command } = require('discord.js-commando'); +const Command = require('../../structures/Command'); const { stripIndents } = require('common-tags'); module.exports = class LockdownCommand extends Command { @@ -9,6 +9,9 @@ module.exports = class LockdownCommand extends Command { memberName: 'lockdown', description: 'Locks down the current channel or removes a lockdown, which prevents non-administrator members from speaking.', guildOnly: true, + clientPermissions: ['ADMINISTRATOR'], + userPermissions: ['ADMINISTRATOR'], + allowStaff: true, args: [ { key: 'type', @@ -25,16 +28,7 @@ module.exports = class LockdownCommand extends Command { }); } - hasPermission(msg) { - const staffRole = msg.guild.roles.get(msg.guild.settings.get('staffRole')); - if (staffRole && !msg.member.roles.has(staffRole.id)) return `You do not have the ${staffRole.name} role.`; - else if (!msg.member.hasPermission('ADMINISTRATOR')) return 'You do not have the `Administrator` Permission.'; - else return true; - } - async run(msg, args) { - if (!msg.channel.permissionsFor(this.client.user).has('ADMINISTRATOR')) - return msg.say('This Command requires the `Administrator` Permission.'); const { type } = args; if (type === 'start') { try { diff --git a/commands/moderation/prune.js b/commands/moderation/prune.js index a93c9c34..5397ecbb 100644 --- a/commands/moderation/prune.js +++ b/commands/moderation/prune.js @@ -1,4 +1,4 @@ -const { Command } = require('discord.js-commando'); +const Command = require('../../structures/Command'); module.exports = class PruneCommand extends Command { constructor(client) { @@ -12,6 +12,9 @@ module.exports = class PruneCommand extends Command { usages: 1, duration: 15 }, + clientPermissions: ['READ_MESSAGE_HISTORY', 'MANAGE_MESSAGES'], + userPermissions: ['MANAGE_MESSAGES'], + allowStaff: true, args: [ { key: 'count', @@ -26,19 +29,7 @@ module.exports = class PruneCommand extends Command { ] }); } - - hasPermission(msg) { - const staffRole = msg.guild.roles.get(msg.guild.settings.get('staffRole')); - if (staffRole && !msg.member.roles.has(staffRole.id)) return `You do not have the ${staffRole.name} role.`; - else if (!msg.member.hasPermission('MANAGE_MESSAGES')) return 'You do not have the `Manage Messages` Permission.'; - else return true; - } - async run(msg, args) { - if (!msg.channel.permissionsFor(this.client.user).has('READ_MESSAGE_HISTORY')) - return msg.say('This Command requires the `Read Message History` Permission.'); - if (!msg.channel.permissionsFor(this.client.user).has('MANAGE_MESSAGES')) - return msg.say('This Command requires the `Manage Messages` Permission.'); const { count } = args; try { const messages = await msg.channel.fetchMessages({ limit: count + 1 }); diff --git a/commands/moderation/softban.js b/commands/moderation/softban.js index ba641973..5d2bbafa 100644 --- a/commands/moderation/softban.js +++ b/commands/moderation/softban.js @@ -1,4 +1,4 @@ -const { Command } = require('discord.js-commando'); +const Command = require('../../structures/Command'); const { RichEmbed } = require('discord.js'); const { stripIndents } = require('common-tags'); @@ -11,6 +11,9 @@ module.exports = class SoftbanCommand extends Command { memberName: 'softban', description: 'Kicks a user and deletes their messages, and logs the softban to the mod logs.', guildOnly: true, + clientPermissions: ['BAN_MEMBERS'], + userPermissions: ['KICK_MEMBERS'], + allowStaff: true, args: [ { key: 'member', @@ -30,24 +33,13 @@ module.exports = class SoftbanCommand extends Command { }); } - hasPermission(msg) { - const staffRole = msg.guild.roles.get(msg.guild.settings.get('staffRole')); - if (staffRole && !msg.member.roles.has(staffRole.id)) return `You do not have the ${staffRole.name} role.`; - else if (!msg.member.hasPermission('KICK_MEMBERS')) return 'You do not have the `Kick Members` Permission.'; - else return true; - } - async run(msg, args) { - if (!msg.channel.permissionsFor(this.client.user).has('BAN_MEMBERS')) - return msg.say('This Command requires the `Ban Members` Permission.'); - if (!msg.channel.permissionsFor(this.client.user).has('KICK_MEMBERS')) - return msg.say('This Command requires the `Kick Members` Permission.'); const modlogs = msg.guild.channels.get(msg.guild.settings.get('modLog')); - if (!modlogs) return msg.say('This Command requires a channel set with the `modchannel` command.'); + if (!modlogs) return msg.say('This Command requires a channel set with the `mod-channel` command.'); if (!modlogs.permissionsFor(this.client.user).has('SEND_MESSAGES')) - return msg.say('This Command requires the `Send Messages` Permission for the Mod Log Channel.'); + return msg.say('This Command requires the `SEND_MESSAGES` Permission for the Mod Log Channel.'); if (!modlogs.permissionsFor(this.client.user).has('EMBED_LINKS')) - return msg.say('This Command requires the `Embed Links` Permission.'); + return msg.say('This Command requires the `EMBED_LINKS` Permission for the Mod Log Channel.'); const { member, reason } = args; if (!member.bannable) return msg.say('This member is not softbannable. Perhaps they have a higher role than me?'); try { @@ -71,7 +63,7 @@ module.exports = class SoftbanCommand extends Command { **Action:** Softban **Reason:** ${reason} `); - await modlogs.send({ embed }); + modlogs.send({ embed }); return null; } catch (err) { return msg.say(`${err.name}: ${err.message}`); diff --git a/commands/moderation/unban.js b/commands/moderation/unban.js index b7ba73f5..59ff99d9 100644 --- a/commands/moderation/unban.js +++ b/commands/moderation/unban.js @@ -1,4 +1,4 @@ -const { Command } = require('discord.js-commando'); +const Command = require('../../structures/Command'); const { RichEmbed } = require('discord.js'); const { stripIndents } = require('common-tags'); @@ -11,6 +11,9 @@ module.exports = class UnbanCommand extends Command { memberName: 'unban', description: 'Unbans a user and logs the unban to the mod logs.', guildOnly: true, + clientPermissions: ['BAN_MEMBERS'], + userPermissions: ['BAN_MEMBERS'], + allowStaff: true, args: [ { key: 'id', @@ -30,22 +33,13 @@ module.exports = class UnbanCommand extends Command { }); } - hasPermission(msg) { - const staffRole = msg.guild.roles.get(msg.guild.settings.get('staffRole')); - if (staffRole && !msg.member.roles.has(staffRole.id)) return `You do not have the ${staffRole.name} role.`; - else if (!msg.member.hasPermission('BAN_MEMBERS')) return 'You do not have the `Ban Members` Permission.'; - else return true; - } - async run(msg, args) { - if (!msg.channel.permissionsFor(this.client.user).has('BAN_MEMBERS')) - return msg.say('This Command requires the `Ban Members` Permission.'); const modlogs = msg.guild.channels.get(msg.guild.settings.get('modLog')); - if (!modlogs) return msg.say('This Command requires a channel set with the `modchannel` command.'); + if (!modlogs) return msg.say('This Command requires a channel set with the `mod-channel` command.'); if (!modlogs.permissionsFor(this.client.user).has('SEND_MESSAGES')) - return msg.say('This Command requires the `Send Messages` Permission for the Mod Log Channel.'); + return msg.say('This Command requires the `SEND_MESSAGES` Permission for the Mod Log Channel.'); if (!modlogs.permissionsFor(this.client.user).has('EMBED_LINKS')) - return msg.say('This Command requires the `Embed Links` Permission.'); + return msg.say('This Command requires the `EMBED_LINKS` Permission for the Mod Log Channel.'); 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.'); @@ -62,7 +56,7 @@ module.exports = class UnbanCommand extends Command { **Action:** Unban **Reason:** ${reason} `); - await modlogs.send({ embed }); + modlogs.send({ embed }); return null; } catch (err) { return msg.say(`${err.name}: ${err.message}`); diff --git a/commands/moderation/warn.js b/commands/moderation/warn.js index f1fc82e1..4ee43efe 100644 --- a/commands/moderation/warn.js +++ b/commands/moderation/warn.js @@ -1,4 +1,4 @@ -const { Command } = require('discord.js-commando'); +const Command = require('../../structures/Command'); const { RichEmbed } = require('discord.js'); const { stripIndents } = require('common-tags'); @@ -10,6 +10,8 @@ module.exports = class WarnCommand extends Command { memberName: 'warn', description: 'Warns a user and logs the warn to the mod logs.', guildOnly: true, + allowStaff: true, + userPermissions: ['KICK_MEMBERS'], args: [ { key: 'member', @@ -29,20 +31,13 @@ module.exports = class WarnCommand extends Command { }); } - hasPermission(msg) { - const staffRole = msg.guild.roles.get(msg.guild.settings.get('staffRole')); - if (staffRole && !msg.member.roles.has(staffRole.id)) return `You do not have the ${staffRole.name} role.`; - else if (!msg.member.hasPermission('KICK_MEMBERS')) return 'You do not have the `Kick Members` Permission.'; - else return true; - } - async run(msg, args) { const modlogs = msg.guild.channels.get(msg.guild.settings.get('modLog')); - if (!modlogs) return msg.say('This Command requires a channel set with the `modchannel` command.'); + if (!modlogs) return msg.say('This Command requires a channel set with the `mod-channel` command.'); if (!modlogs.permissionsFor(this.client.user).has('SEND_MESSAGES')) - return msg.say('This Command requires the `Send Messages` Permission for the Mod Log Channel.'); + return msg.say('This Command requires the `SEND_MESSAGES` Permission for the Mod Log Channel.'); if (!modlogs.permissionsFor(this.client.user).has('EMBED_LINKS')) - return msg.say('This Command requires the `Embed Links` Permission.'); + return msg.say('This Command requires the `EMBED_LINKS` Permission for the Mod Log Channel.'); const { member, reason } = args; if (!member.kickable) return msg.say('This member is not warnable. Perhaps they have a higher role than me?'); try { diff --git a/commands/numedit/currency.js b/commands/numedit/currency.js index 14bea4b3..3598e88f 100644 --- a/commands/numedit/currency.js +++ b/commands/numedit/currency.js @@ -1,4 +1,4 @@ -const { Command } = require('discord.js-commando'); +const Command = require('../../structures/Command'); const snekfetch = require('snekfetch'); const codes = require('../../assets/json/currency'); diff --git a/commands/numedit/math.js b/commands/numedit/math.js index 7c17ba5f..f0f1d475 100644 --- a/commands/numedit/math.js +++ b/commands/numedit/math.js @@ -1,4 +1,4 @@ -const { Command } = require('discord.js-commando'); +const Command = require('../../structures/Command'); const math = require('mathjs'); module.exports = class MathCommand extends Command { @@ -22,10 +22,9 @@ module.exports = class MathCommand extends Command { const { expression } = args; try { const solved = math.eval(expression); - return msg.say(solved) - .catch(() => msg.say('Invalid statement.')); + return msg.say(solved).catch(() => msg.say('Invalid Statement.')); } catch (err) { - return msg.say('Invalid statement.'); + return msg.say('Invalid Statement.'); } } }; diff --git a/commands/numedit/temperature.js b/commands/numedit/temperature.js index 6557426b..afd07a9c 100644 --- a/commands/numedit/temperature.js +++ b/commands/numedit/temperature.js @@ -1,4 +1,4 @@ -const { Command } = require('discord.js-commando'); +const Command = require('../../structures/Command'); module.exports = class TemperatureCommand extends Command { constructor(client) { diff --git a/commands/random/cleverbot.js b/commands/random/cleverbot.js index 87b1e880..b003a137 100644 --- a/commands/random/cleverbot.js +++ b/commands/random/cleverbot.js @@ -1,4 +1,4 @@ -const { Command } = require('discord.js-commando'); +const Command = require('../../structures/Command'); const Cleverbot = require('cleverio'); const { CLEVS_KEY, CLEVS_USER, CLEVS_NICK } = process.env; @@ -32,8 +32,7 @@ module.exports = class CleverbotCommand extends Command { msg.channel.startTyping(); try { const { response } = await this.clevs.ask(text); - return msg.reply(response) - .then(() => msg.channel.stopTyping()); + return msg.reply(response).then(() => msg.channel.stopTyping()); } catch (err) { return msg.say(`${err.name}: ${err.message}`); } diff --git a/commands/random/easter-egg.js b/commands/random/easter-egg.js index 14c5a44c..821ef9ae 100644 --- a/commands/random/easter-egg.js +++ b/commands/random/easter-egg.js @@ -1,4 +1,4 @@ -const { Command } = require('discord.js-commando'); +const Command = require('../../structures/Command'); const eastereggs = require('../../assets/json/easter-egg'); module.exports = class EasterEggCommand extends Command { diff --git a/commands/random/give-flower.js b/commands/random/give-flower.js index 06e8bc9b..14d6e14d 100644 --- a/commands/random/give-flower.js +++ b/commands/random/give-flower.js @@ -1,4 +1,4 @@ -const { Command } = require('discord.js-commando'); +const Command = require('../../structures/Command'); module.exports = class GiveFlowerCommand extends Command { constructor(client) { diff --git a/commands/random/horoscope.js b/commands/random/horoscope.js index df86a1a4..b6a246c6 100644 --- a/commands/random/horoscope.js +++ b/commands/random/horoscope.js @@ -1,4 +1,4 @@ -const { Command } = require('discord.js-commando'); +const Command = require('../../structures/Command'); const { RichEmbed } = require('discord.js'); const snekfetch = require('snekfetch'); const signs = require('../../assets/json/horoscope'); @@ -11,6 +11,7 @@ module.exports = class HoroscopeCommand extends Command { memberName: 'horoscope', description: 'Gives the horoscope for today for a particular sign.', details: `**Signs:** ${signs.join(', ')}`, + clientPermissions: ['EMBED_LINKS'], args: [ { key: 'sign', @@ -27,9 +28,6 @@ module.exports = class HoroscopeCommand extends Command { } async run(msg, args) { - if (msg.channel.type !== 'dm') - if (!msg.channel.permissionsFor(this.client.user).has('EMBED_LINKS')) - return msg.say('This Command requires the `Embed Links` Permission.'); const { sign } = args; try { const { text } = await snekfetch diff --git a/commands/random/lenny.js b/commands/random/lenny.js index e1e98ebc..5e6a72e5 100644 --- a/commands/random/lenny.js +++ b/commands/random/lenny.js @@ -1,4 +1,4 @@ -const { Command } = require('discord.js-commando'); +const Command = require('../../structures/Command'); module.exports = class LennyCommand extends Command { constructor(client) { diff --git a/commands/random/meme.js b/commands/random/meme.js index 62ba38a4..d349aad3 100644 --- a/commands/random/meme.js +++ b/commands/random/meme.js @@ -1,4 +1,4 @@ -const { Command } = require('discord.js-commando'); +const Command = require('../../structures/Command'); const codes = require('../../assets/json/meme'); module.exports = class MemeCommand extends Command { @@ -9,6 +9,7 @@ module.exports = class MemeCommand extends Command { memberName: 'meme', description: 'Sends a Meme with text of your choice, and a background of your choice.', details: `**Codes:** ${codes.join(', ')}`, + clientPermissions: ['ATTACH_FILES'], args: [ { key: 'type', @@ -37,9 +38,6 @@ module.exports = class MemeCommand extends Command { } run(msg, args) { - if (msg.channel.type !== 'dm') - if (!msg.channel.permissionsFor(this.client.user).has('ATTACH_FILES')) - return msg.say('This Command requires the `Attach Files` Permission.'); const { type, top, bottom } = args; return msg.say({ files: [`https://memegen.link/${type}/${top}/${bottom}.jpg`] }) .catch(err => msg.say(`${err.name}: ${err.message}`)); diff --git a/commands/random/nitro.js b/commands/random/nitro.js index 0b8ac3a2..dd685e66 100644 --- a/commands/random/nitro.js +++ b/commands/random/nitro.js @@ -1,4 +1,4 @@ -const { Command } = require('discord.js-commando'); +const Command = require('../../structures/Command'); const { RichEmbed } = require('discord.js'); const { stripIndents } = require('common-tags'); @@ -8,14 +8,12 @@ module.exports = class NitroCommand extends Command { name: 'nitro', group: 'random', memberName: 'nitro', - description: 'Sends a "This Message Can Only be viewed by Nitro Members" message.' + description: 'Sends a "This Message Can Only be viewed by Nitro Members" message.', + clientPermissions: ['EMBED_LINKS'] }); } run(msg) { - if (msg.channel.type !== 'dm') - if (!msg.channel.permissionsFor(this.client.user).has('EMBED_LINKS')) - return msg.say('This Command requires the `Embed Links` Permission.'); const embed = new RichEmbed() .setAuthor('Discord Nitro') .setThumbnail('https://i.imgur.com/wzhMMnl.jpg') diff --git a/commands/random/soundboard.js b/commands/random/soundboard.js index 6c9a53cb..5cdc5dd4 100644 --- a/commands/random/soundboard.js +++ b/commands/random/soundboard.js @@ -1,4 +1,4 @@ -const { Command } = require('discord.js-commando'); +const Command = require('../../structures/Command'); const { names, paths } = require('../../assets/json/soundboard'); const path = require('path'); @@ -16,6 +16,7 @@ module.exports = class SoundboardCommand extends Command { usages: 1, duration: 15 }, + clientPermissions: ['ADD_REACTIONS'], args: [ { key: 'sound', @@ -32,14 +33,12 @@ module.exports = class SoundboardCommand extends Command { } async run(msg, args) { - if (!msg.channel.permissionsFor(this.client.user).has('ADD_REACTIONS')) - return msg.say('This Command requires the `Add Reactions` Permission.'); const voiceChannel = msg.member.voiceChannel; if (!voiceChannel) return msg.say('Please enter a Voice Channel first.'); if (!voiceChannel.permissionsFor(this.client.user).has('CONNECT')) - return msg.say('This Command requires the `Connect` Permission.'); + return msg.say('This Command requires the `CONNECT` Permission.'); if (!voiceChannel.permissionsFor(this.client.user).has('SPEAK')) - return msg.say('This Command requires the `Speak` Permission.'); + return msg.say('This Command requires the `SPEAK` Permission.'); if (!voiceChannel.joinable) return msg.say('This Voice Channel is not joinable.'); const alreadyConnected = this.client.voiceConnections.get(voiceChannel.guild.id); if (alreadyConnected) return msg.say('I am already playing a sound.'); @@ -47,7 +46,7 @@ module.exports = class SoundboardCommand extends Command { try { const connection = await voiceChannel.join(); msg.react('🔊'); - const dispatcher = connection.playStream(path.join(__dirname, '..', '..', 'assets', 'sounds', paths[sound])); + const dispatcher = connection.playFile(path.join(__dirname, '..', '..', 'assets', 'sounds', paths[sound])); dispatcher.on('end', () => { voiceChannel.leave(); msg.react('✅'); diff --git a/commands/random/spam.js b/commands/random/spam.js index ccbac13c..3fa875d2 100644 --- a/commands/random/spam.js +++ b/commands/random/spam.js @@ -1,4 +1,4 @@ -const { Command } = require('discord.js-commando'); +const Command = require('../../structures/Command'); const path = require('path'); module.exports = class SpamCommand extends Command { @@ -7,14 +7,12 @@ module.exports = class SpamCommand extends Command { name: 'spam', group: 'random', memberName: 'spam', - description: 'Puts a picture of Spam.' + description: 'Puts a picture of Spam.', + clientPermissions: ['ATTACH_FILES'] }); } run(msg) { - if (msg.channel.type !== 'dm') - if (!msg.channel.permissionsFor(this.client.user).has('ATTACH_FILES')) - return msg.say('This Command requires the `Attach Files` Permission.'); return msg.say({ files: [path.join(__dirname, '..', '..', 'assets', 'images', 'spam.png')] }) .catch(err => msg.say(`${err.name}: ${err.message}`)); } diff --git a/commands/random/star.js b/commands/random/star.js index 039f54c9..46efa8b8 100644 --- a/commands/random/star.js +++ b/commands/random/star.js @@ -1,4 +1,4 @@ -const { Command } = require('discord.js-commando'); +const Command = require('../../structures/Command'); const { RichEmbed } = require('discord.js'); const moment = require('moment'); @@ -24,7 +24,7 @@ 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 || !channel.permissionsFor(this.client.user).has('EMBED_LINKS')) return null; + if (!channel || !channel.permissionsFor(this.client.user).has(['SEND_MESSAGES', 'EMBED_LINKS'])) return null; if (this.starred.includes(id)) return null; try { const message = await msg.channel.fetchMessage(id); diff --git a/commands/random/strawpoll.js b/commands/random/strawpoll.js index acf28353..2c315f8e 100644 --- a/commands/random/strawpoll.js +++ b/commands/random/strawpoll.js @@ -1,4 +1,4 @@ -const { Command } = require('discord.js-commando'); +const Command = require('../../structures/Command'); const { stripIndents } = require('common-tags'); const snekfetch = require('snekfetch'); diff --git a/commands/random/today.js b/commands/random/today.js index 095315df..facdf309 100644 --- a/commands/random/today.js +++ b/commands/random/today.js @@ -1,4 +1,4 @@ -const { Command } = require('discord.js-commando'); +const Command = require('../../structures/Command'); const { RichEmbed } = require('discord.js'); const snekfetch = require('snekfetch'); @@ -8,14 +8,12 @@ module.exports = class TodayCommand extends Command { name: 'today', group: 'random', memberName: 'today', - description: 'Tells you what happened today in history.' + description: 'Tells you what happened today in history.', + clientPermissions: ['EMBED_LINKS'] }); } async run(msg) { - if (msg.channel.type !== 'dm') - if (!msg.channel.permissionsFor(this.client.user).has('EMBED_LINKS')) - return msg.say('This Command requires the `Embed Links` Permission.'); try { const { text } = await snekfetch .get('http://history.muffinlabs.com/date'); diff --git a/commands/random/would-you-rather.js b/commands/random/would-you-rather.js index ba32a163..7dfd3faa 100644 --- a/commands/random/would-you-rather.js +++ b/commands/random/would-you-rather.js @@ -1,4 +1,4 @@ -const { Command } = require('discord.js-commando'); +const Command = require('../../structures/Command'); const { RichEmbed } = require('discord.js'); const snekfetch = require('snekfetch'); @@ -9,14 +9,12 @@ module.exports = class WouldYouRatherCommand extends Command { aliases: ['wyrather'], group: 'random', memberName: 'would-you-rather', - description: 'Gets a random would you rather question.' + description: 'Gets a random would you rather question.', + clientPermissions: ['EMBED_LINKS'] }); } async run(msg) { - if (msg.channel.type !== 'dm') - if (!msg.channel.permissionsFor(this.client.user).has('EMBED_LINKS')) - return msg.say('This Command requires the `Embed Links` Permission.'); try { const { body } = await snekfetch .get('http://www.rrrather.com/botapi'); diff --git a/commands/randomimg/cat.js b/commands/randomimg/cat.js index c1622f3f..c4c3e9a7 100644 --- a/commands/randomimg/cat.js +++ b/commands/randomimg/cat.js @@ -1,4 +1,4 @@ -const { Command } = require('discord.js-commando'); +const Command = require('../../structures/Command'); const snekfetch = require('snekfetch'); module.exports = class CatCommand extends Command { diff --git a/commands/randomimg/dog.js b/commands/randomimg/dog.js index 1bed8090..59eefa96 100644 --- a/commands/randomimg/dog.js +++ b/commands/randomimg/dog.js @@ -1,4 +1,4 @@ -const { Command } = require('discord.js-commando'); +const Command = require('../../structures/Command'); const snekfetch = require('snekfetch'); module.exports = class DogCommand extends Command { diff --git a/commands/randomimg/vocaloid.js b/commands/randomimg/vocaloid.js index a57e4d93..037d668a 100644 --- a/commands/randomimg/vocaloid.js +++ b/commands/randomimg/vocaloid.js @@ -1,4 +1,4 @@ -const { Command } = require('discord.js-commando'); +const Command = require('../../structures/Command'); const songs = require('../../assets/json/vocaloid'); module.exports = class VocaloidCommand extends Command { diff --git a/commands/randomimg/xiao.js b/commands/randomimg/xiao.js index ba65a463..ecb5784c 100644 --- a/commands/randomimg/xiao.js +++ b/commands/randomimg/xiao.js @@ -1,4 +1,4 @@ -const { Command } = require('discord.js-commando'); +const Command = require('../../structures/Command'); const path = require('path'); module.exports = class XiaoCommand extends Command { @@ -8,14 +8,12 @@ module.exports = class XiaoCommand extends Command { aliases: ['xiao-pai'], group: 'randomimg', memberName: 'xiao', - description: 'Sends a random image of Xiao Pai.' + description: 'Sends a random image of Xiao Pai.', + clientPermissions: ['ATTACH_FILES'] }); } run(msg) { - if (msg.channel.type !== 'dm') - if (!msg.channel.permissionsFor(this.client.user).has('ATTACH_FILES')) - return msg.say('This Command requires the `Attach Files` Permission.'); const xiao = Math.floor(Math.random() * 10) + 1; return msg.say({ files: [path.join(__dirname, '..', '..', 'assets', 'images', `xiao${xiao}.png`)] }) .catch(err => msg.say(`${err.name}: ${err.message}`)); diff --git a/commands/randomimg/xkcd.js b/commands/randomimg/xkcd.js index a14d85a5..56ed6710 100644 --- a/commands/randomimg/xkcd.js +++ b/commands/randomimg/xkcd.js @@ -1,4 +1,4 @@ -const { Command } = require('discord.js-commando'); +const Command = require('../../structures/Command'); const { RichEmbed } = require('discord.js'); const snekfetch = require('snekfetch'); @@ -10,6 +10,7 @@ module.exports = class XKCDCommand extends Command { group: 'randomimg', memberName: 'xkcd', description: 'Gets an XKCD Comic, optionally opting for today\'s.', + clientPermissions: ['EMBED_LINKS'], args: [ { key: 'type', @@ -26,9 +27,6 @@ module.exports = class XKCDCommand extends Command { } async run(msg, args) { - if (msg.channel.type !== 'dm') - if (!msg.channel.permissionsFor(this.client.user).has('ATTACH_FILES')) - return msg.say('This Command requires the `Attach Files` Permission.'); const { type } = args; try { const current = await snekfetch diff --git a/commands/response/8-ball.js b/commands/response/8-ball.js index 58236d0a..a1bd834a 100644 --- a/commands/response/8-ball.js +++ b/commands/response/8-ball.js @@ -1,4 +1,4 @@ -const { Command } = require('discord.js-commando'); +const Command = require('../../structures/Command'); const { stripIndents } = require('common-tags'); const answers = require('../../assets/json/8-ball'); diff --git a/commands/response/choose.js b/commands/response/choose.js index 8ae97184..5380a5c1 100644 --- a/commands/response/choose.js +++ b/commands/response/choose.js @@ -1,4 +1,4 @@ -const { Command } = require('discord.js-commando'); +const Command = require('../../structures/Command'); module.exports = class ChooseCommand extends Command { constructor(client) { diff --git a/commands/response/coin.js b/commands/response/coin.js index 7096b0c1..f53833dc 100644 --- a/commands/response/coin.js +++ b/commands/response/coin.js @@ -1,4 +1,4 @@ -const { Command } = require('discord.js-commando'); +const Command = require('../../structures/Command'); const sides = ['heads', 'tails']; module.exports = class CoinFlipCommand extends Command { diff --git a/commands/response/compliment.js b/commands/response/compliment.js index 06305a7a..9fc852fd 100644 --- a/commands/response/compliment.js +++ b/commands/response/compliment.js @@ -1,4 +1,4 @@ -const { Command } = require('discord.js-commando'); +const Command = require('../../structures/Command'); const compliments = require('../../assets/json/compliment'); module.exports = class ComplimentCommand extends Command { diff --git a/commands/response/fact-core.js b/commands/response/fact-core.js index a69cc085..33f1769f 100644 --- a/commands/response/fact-core.js +++ b/commands/response/fact-core.js @@ -1,4 +1,4 @@ -const { Command } = require('discord.js-commando'); +const Command = require('../../structures/Command'); const facts = require('../../assets/json/fact-core'); module.exports = class FactCoreCommand extends Command { diff --git a/commands/response/fishy.js b/commands/response/fishy.js index 5daece7e..6e7b75bd 100644 --- a/commands/response/fishy.js +++ b/commands/response/fishy.js @@ -1,4 +1,4 @@ -const { Command } = require('discord.js-commando'); +const Command = require('../../structures/Command'); const fishes = [':fish:', ':tropical_fish:', ':blowfish:']; module.exports = class FishyCommand extends Command { diff --git a/commands/response/fortune.js b/commands/response/fortune.js index bba4537c..1444a8af 100644 --- a/commands/response/fortune.js +++ b/commands/response/fortune.js @@ -1,4 +1,4 @@ -const { Command } = require('discord.js-commando'); +const Command = require('../../structures/Command'); const fortunes = require('../../assets/json/fortune'); module.exports = class FortuneCookieCommand extends Command { diff --git a/commands/response/magic-conch.js b/commands/response/magic-conch.js index 44762915..46b518a2 100644 --- a/commands/response/magic-conch.js +++ b/commands/response/magic-conch.js @@ -1,4 +1,4 @@ -const { Command } = require('discord.js-commando'); +const Command = require('../../structures/Command'); const { stripIndents } = require('common-tags'); const answers = require('../../assets/json/magic-conch'); diff --git a/commands/response/name.js b/commands/response/name.js index bcc58d1f..0834a126 100644 --- a/commands/response/name.js +++ b/commands/response/name.js @@ -1,4 +1,4 @@ -const { Command } = require('discord.js-commando'); +const Command = require('../../structures/Command'); const { lastNames, maleNames, femaleNames } = require('../../assets/json/name'); module.exports = class RandomNameCommand extends Command { diff --git a/commands/response/offspring.js b/commands/response/offspring.js index 52fc9165..d0909b08 100644 --- a/commands/response/offspring.js +++ b/commands/response/offspring.js @@ -1,4 +1,4 @@ -const { Command } = require('discord.js-commando'); +const Command = require('../../structures/Command'); const genders = ['boy', 'girl']; module.exports = class OffspringCommand extends Command { diff --git a/commands/response/quantum-coin.js b/commands/response/quantum-coin.js index f3e52505..cb56948e 100644 --- a/commands/response/quantum-coin.js +++ b/commands/response/quantum-coin.js @@ -1,4 +1,4 @@ -const { Command } = require('discord.js-commando'); +const Command = require('../../structures/Command'); const sides = ['on nothing', 'on NaN', 'on 0', 'in the air', 'on null']; module.exports = class QuantumCoinCommand extends Command { diff --git a/commands/response/rate-waifu.js b/commands/response/rate-waifu.js index 4451c7d6..92798340 100644 --- a/commands/response/rate-waifu.js +++ b/commands/response/rate-waifu.js @@ -1,4 +1,4 @@ -const { Command } = require('discord.js-commando'); +const Command = require('../../structures/Command'); module.exports = class RateWaifuCommand extends Command { constructor(client) { diff --git a/commands/response/roast.js b/commands/response/roast.js index d97c17e3..d76d9c5c 100644 --- a/commands/response/roast.js +++ b/commands/response/roast.js @@ -1,4 +1,4 @@ -const { Command } = require('discord.js-commando'); +const Command = require('../../structures/Command'); const roasts = require('../../assets/json/roast'); module.exports = class RoastCommand extends Command { diff --git a/commands/response/roll.js b/commands/response/roll.js index 2f3c2a14..24b9e042 100644 --- a/commands/response/roll.js +++ b/commands/response/roll.js @@ -1,4 +1,4 @@ -const { Command } = require('discord.js-commando'); +const Command = require('../../structures/Command'); module.exports = class RollCommand extends Command { constructor(client) { diff --git a/commands/response/roulette.js b/commands/response/roulette.js index 045c7431..2f5a25b6 100644 --- a/commands/response/roulette.js +++ b/commands/response/roulette.js @@ -1,4 +1,4 @@ -const { Command } = require('discord.js-commando'); +const Command = require('../../structures/Command'); module.exports = class RouletteCommand extends Command { constructor(client) { diff --git a/commands/response/ship.js b/commands/response/ship.js index 5f37ce2d..2a621c73 100644 --- a/commands/response/ship.js +++ b/commands/response/ship.js @@ -1,4 +1,4 @@ -const { Command } = require('discord.js-commando'); +const Command = require('../../structures/Command'); module.exports = class ShipCommand extends Command { constructor(client) { diff --git a/commands/roleplay/cuddle.js b/commands/roleplay/cuddle.js index b061d883..e2ad0f58 100644 --- a/commands/roleplay/cuddle.js +++ b/commands/roleplay/cuddle.js @@ -1,4 +1,4 @@ -const { Command } = require('discord.js-commando'); +const Command = require('../../structures/Command'); module.exports = class CuddleCommand extends Command { constructor(client) { diff --git a/commands/roleplay/divorce.js b/commands/roleplay/divorce.js index b103cc49..65d64dfe 100644 --- a/commands/roleplay/divorce.js +++ b/commands/roleplay/divorce.js @@ -1,4 +1,4 @@ -const { Command } = require('discord.js-commando'); +const Command = require('../../structures/Command'); module.exports = class DivorceCommand extends Command { constructor(client) { diff --git a/commands/roleplay/eat.js b/commands/roleplay/eat.js index 2a7b29d5..e0f6a1ab 100644 --- a/commands/roleplay/eat.js +++ b/commands/roleplay/eat.js @@ -1,4 +1,4 @@ -const { Command } = require('discord.js-commando'); +const Command = require('../../structures/Command'); module.exports = class EatCommand extends Command { constructor(client) { diff --git a/commands/roleplay/falcon-punch.js b/commands/roleplay/falcon-punch.js index b39ce84b..497644be 100644 --- a/commands/roleplay/falcon-punch.js +++ b/commands/roleplay/falcon-punch.js @@ -1,4 +1,4 @@ -const { Command } = require('discord.js-commando'); +const Command = require('../../structures/Command'); module.exports = class FalconPunchCommand extends Command { constructor(client) { diff --git a/commands/roleplay/fist-bump.js b/commands/roleplay/fist-bump.js index 48eb0e28..c9f312b4 100644 --- a/commands/roleplay/fist-bump.js +++ b/commands/roleplay/fist-bump.js @@ -1,4 +1,4 @@ -const { Command } = require('discord.js-commando'); +const Command = require('../../structures/Command'); module.exports = class FistBumpCommand extends Command { constructor(client) { diff --git a/commands/roleplay/high-five.js b/commands/roleplay/high-five.js index 6d0c960d..5cf37f38 100644 --- a/commands/roleplay/high-five.js +++ b/commands/roleplay/high-five.js @@ -1,4 +1,4 @@ -const { Command } = require('discord.js-commando'); +const Command = require('../../structures/Command'); module.exports = class HighFivesCommand extends Command { constructor(client) { diff --git a/commands/roleplay/hit-with-shovel.js b/commands/roleplay/hit-with-shovel.js index b427c359..aa2fa243 100644 --- a/commands/roleplay/hit-with-shovel.js +++ b/commands/roleplay/hit-with-shovel.js @@ -1,4 +1,4 @@ -const { Command } = require('discord.js-commando'); +const Command = require('../../structures/Command'); module.exports = class HitwithShovelCommand extends Command { constructor(client) { diff --git a/commands/roleplay/hug.js b/commands/roleplay/hug.js index b5ca705d..ecc903f8 100644 --- a/commands/roleplay/hug.js +++ b/commands/roleplay/hug.js @@ -1,4 +1,4 @@ -const { Command } = require('discord.js-commando'); +const Command = require('../../structures/Command'); module.exports = class HugCommand extends Command { constructor(client) { diff --git a/commands/roleplay/inhale.js b/commands/roleplay/inhale.js index 4ccaf940..ee479292 100644 --- a/commands/roleplay/inhale.js +++ b/commands/roleplay/inhale.js @@ -1,4 +1,4 @@ -const { Command } = require('discord.js-commando'); +const Command = require('../../structures/Command'); module.exports = class InhaleCommand extends Command { constructor(client) { diff --git a/commands/roleplay/kill.js b/commands/roleplay/kill.js index 98a5e874..4bb8ad24 100644 --- a/commands/roleplay/kill.js +++ b/commands/roleplay/kill.js @@ -1,4 +1,4 @@ -const { Command } = require('discord.js-commando'); +const Command = require('../../structures/Command'); module.exports = class KillCommand extends Command { constructor(client) { diff --git a/commands/roleplay/kiss.js b/commands/roleplay/kiss.js index c7a9a458..58c45324 100644 --- a/commands/roleplay/kiss.js +++ b/commands/roleplay/kiss.js @@ -1,4 +1,4 @@ -const { Command } = require('discord.js-commando'); +const Command = require('../../structures/Command'); module.exports = class KissCommand extends Command { constructor(client) { diff --git a/commands/roleplay/marry.js b/commands/roleplay/marry.js index c198ce89..6c47df60 100644 --- a/commands/roleplay/marry.js +++ b/commands/roleplay/marry.js @@ -1,4 +1,4 @@ -const { Command } = require('discord.js-commando'); +const Command = require('../../structures/Command'); module.exports = class MarryCommand extends Command { constructor(client) { diff --git a/commands/roleplay/pat.js b/commands/roleplay/pat.js index a4caa811..c9417755 100644 --- a/commands/roleplay/pat.js +++ b/commands/roleplay/pat.js @@ -1,4 +1,4 @@ -const { Command } = require('discord.js-commando'); +const Command = require('../../structures/Command'); module.exports = class PatCommand extends Command { constructor(client) { diff --git a/commands/roleplay/poke.js b/commands/roleplay/poke.js index 99fa8c26..0927b103 100644 --- a/commands/roleplay/poke.js +++ b/commands/roleplay/poke.js @@ -1,4 +1,4 @@ -const { Command } = require('discord.js-commando'); +const Command = require('../../structures/Command'); module.exports = class PokeCommand extends Command { constructor(client) { diff --git a/commands/roleplay/punch.js b/commands/roleplay/punch.js index ce77816f..61a601d5 100644 --- a/commands/roleplay/punch.js +++ b/commands/roleplay/punch.js @@ -1,4 +1,4 @@ -const { Command } = require('discord.js-commando'); +const Command = require('../../structures/Command'); module.exports = class PunchCommand extends Command { constructor(client) { diff --git a/commands/roleplay/slap.js b/commands/roleplay/slap.js index 114aa6cc..f395bb85 100644 --- a/commands/roleplay/slap.js +++ b/commands/roleplay/slap.js @@ -1,4 +1,4 @@ -const { Command } = require('discord.js-commando'); +const Command = require('../../structures/Command'); module.exports = class SlapCommand extends Command { constructor(client) { diff --git a/commands/search/anime.js b/commands/search/anime.js index aff51895..a3f8e32c 100644 --- a/commands/search/anime.js +++ b/commands/search/anime.js @@ -1,4 +1,4 @@ -const { Command } = require('discord.js-commando'); +const Command = require('../../structures/Command'); const { RichEmbed } = require('discord.js'); const snekfetch = require('snekfetch'); const { promisifyAll } = require('tsubaki'); @@ -12,6 +12,7 @@ module.exports = class AnimeCommand extends Command { group: 'search', memberName: 'anime', description: 'Searches My Anime List for a specified anime.', + clientPermissions: ['EMBED_LINKS'], args: [ { key: 'query', @@ -23,9 +24,6 @@ module.exports = class AnimeCommand extends Command { } async run(msg, args) { - if (msg.channel.type !== 'dm') - if (!msg.channel.permissionsFor(this.client.user).has('EMBED_LINKS')) - return msg.say('This Command requires the `Embed Links` Permission.'); const { query } = args; try { const { text } = await snekfetch diff --git a/commands/search/bot-info.js b/commands/search/bot-info.js index e652be35..7a3a08b5 100644 --- a/commands/search/bot-info.js +++ b/commands/search/bot-info.js @@ -1,4 +1,4 @@ -const { Command } = require('discord.js-commando'); +const Command = require('../../structures/Command'); const { RichEmbed } = require('discord.js'); const snekfetch = require('snekfetch'); const { DBOTS_KEY } = process.env; @@ -10,6 +10,7 @@ module.exports = class BotSearchCommand extends Command { group: 'search', memberName: 'bot-info', description: 'Searches Discord Bots for info on a bot.', + clientPermissions: ['EMBED_LINKS'], args: [ { key: 'bot', @@ -21,14 +22,11 @@ module.exports = class BotSearchCommand extends Command { } async run(msg, args) { - if (msg.channel.type !== 'dm') - if (!msg.channel.permissionsFor(this.client.user).has('EMBED_LINKS')) - return msg.say('This Command requires the `Embed Links` Permission.'); const { bot } = args; 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 8aea929f..48616fba 100644 --- a/commands/search/bulbapedia.js +++ b/commands/search/bulbapedia.js @@ -1,4 +1,4 @@ -const { Command } = require('discord.js-commando'); +const Command = require('../../structures/Command'); const { RichEmbed } = require('discord.js'); const snekfetch = require('snekfetch'); @@ -10,6 +10,7 @@ module.exports = class BulbapediaCommand extends Command { group: 'search', memberName: 'bulbapedia', description: 'Searches Bulbapedia for something.', + clientPermissions: ['EMBED_LINKS'], args: [ { key: 'query', @@ -21,9 +22,6 @@ module.exports = class BulbapediaCommand extends Command { } async run(msg, args) { - if (msg.channel.type !== 'dm') - if (!msg.channel.permissionsFor(this.client.user).has('EMBED_LINKS')) - return msg.say('This Command requires the `Embed Links` Permission.'); const { query } = args; try { const { body } = await snekfetch diff --git a/commands/search/danbooru.js b/commands/search/danbooru.js index 90f7a312..af5c0cf2 100644 --- a/commands/search/danbooru.js +++ b/commands/search/danbooru.js @@ -1,4 +1,4 @@ -const { Command } = require('discord.js-commando'); +const Command = require('../../structures/Command'); const snekfetch = require('snekfetch'); module.exports = class DanbooruCommand extends Command { @@ -8,6 +8,7 @@ module.exports = class DanbooruCommand extends Command { group: 'search', memberName: 'danbooru', description: 'Sends an image from Danbooru, with optional query.', + nsfw: true, args: [ { key: 'query', @@ -20,7 +21,6 @@ module.exports = class DanbooruCommand extends Command { } async run(msg, args) { - if (!msg.channel.nsfw) return msg.say('This Command can only be used in NSFW Channels.'); const { query } = args; try { const { body } = await snekfetch @@ -30,6 +30,7 @@ module.exports = class DanbooruCommand extends Command { limit: 1 }); if (!body.length) throw new Error('No Results.'); + if (!body[0].file_url) throw new Error('No Results.'); return msg.say(`${query ? `Result for ${query}:` : 'Random Image:'} https://danbooru.donmai.us${body[0].file_url}`); } catch (err) { return msg.say(`${err.name}: ${err.message}`); diff --git a/commands/search/define.js b/commands/search/define.js index fe6ead39..3f10d314 100644 --- a/commands/search/define.js +++ b/commands/search/define.js @@ -1,4 +1,4 @@ -const { Command } = require('discord.js-commando'); +const Command = require('../../structures/Command'); const { RichEmbed } = require('discord.js'); const snekfetch = require('snekfetch'); const { WORDNIK_KEY } = process.env; @@ -10,6 +10,7 @@ module.exports = class DefineCommand extends Command { group: 'search', memberName: 'define', description: 'Defines a word.', + clientPermissions: ['EMBED_LINKS'], args: [ { key: 'query', @@ -22,9 +23,6 @@ module.exports = class DefineCommand extends Command { } async run(msg, args) { - if (msg.channel.type !== 'dm') - if (!msg.channel.permissionsFor(this.client.user).has('EMBED_LINKS')) - return msg.say('This Command requires the `Embed Links` Permission.'); const { query } = args; try { const { body } = await snekfetch diff --git a/commands/search/discrim.js b/commands/search/discrim.js index 72116ce8..ef57cb46 100644 --- a/commands/search/discrim.js +++ b/commands/search/discrim.js @@ -1,4 +1,4 @@ -const { Command } = require('discord.js-commando'); +const Command = require('../../structures/Command'); const { RichEmbed } = require('discord.js'); module.exports = class DiscrimCommand extends Command { @@ -9,6 +9,7 @@ module.exports = class DiscrimCommand extends Command { group: 'search', memberName: 'discrim', description: 'Searches for other users with a certain discriminator.', + clientPermissions: ['EMBED_LINKS'], args: [ { key: 'discrim', @@ -24,9 +25,6 @@ module.exports = class DiscrimCommand extends Command { } run(msg, args) { - if (msg.channel.type !== 'dm') - if (!msg.channel.permissionsFor(this.client.user).has('EMBED_LINKS')) - return msg.say('This Command requires the `Embed Links` Permission.'); const { discrim } = args; const users = this.client.users.filter(u => u.discriminator === discrim).map(u => u.username).sort(); const embed = new RichEmbed() diff --git a/commands/search/forecast.js b/commands/search/forecast.js index cdbc2969..16188d59 100644 --- a/commands/search/forecast.js +++ b/commands/search/forecast.js @@ -1,4 +1,4 @@ -const { Command } = require('discord.js-commando'); +const Command = require('../../structures/Command'); const { RichEmbed } = require('discord.js'); const snekfetch = require('snekfetch'); @@ -9,6 +9,7 @@ module.exports = class ForecastCommand extends Command { group: 'search', memberName: 'forecast', description: 'Gets the seven-day forecast for a specified location.', + clientPermissions: ['EMBED_LINKS'], args: [ { key: 'query', @@ -20,9 +21,6 @@ module.exports = class ForecastCommand extends Command { } async run(msg, args) { - if (msg.channel.type !== 'dm') - if (!msg.channel.permissionsFor(this.client.user).has('EMBED_LINKS')) - return msg.say('This Command requires the `Embed Links` Permission.'); const { query } = args; try { const { body } = await snekfetch diff --git a/commands/search/gelbooru.js b/commands/search/gelbooru.js index 2685c97a..2218d799 100644 --- a/commands/search/gelbooru.js +++ b/commands/search/gelbooru.js @@ -1,4 +1,4 @@ -const { Command } = require('discord.js-commando'); +const Command = require('../../structures/Command'); const snekfetch = require('snekfetch'); const { promisifyAll } = require('tsubaki'); const xml = promisifyAll(require('xml2js')); @@ -10,6 +10,7 @@ module.exports = class GelbooruCommand extends Command { group: 'search', memberName: 'gelbooru', description: 'Sends an image from Gelbooru, with query.', + nsfw: true, args: [ { key: 'query', @@ -21,7 +22,6 @@ module.exports = class GelbooruCommand extends Command { } async run(msg, args) { - if (!msg.channel.nsfw) return msg.say('This Command can only be used in NSFW Channels.'); const { query } = args; try { const { text } = await snekfetch diff --git a/commands/search/giphy.js b/commands/search/giphy.js index 5396888f..4c53c13d 100644 --- a/commands/search/giphy.js +++ b/commands/search/giphy.js @@ -1,4 +1,4 @@ -const { Command } = require('discord.js-commando'); +const Command = require('../../structures/Command'); const snekfetch = require('snekfetch'); const { GIPHY_KEY } = process.env; diff --git a/commands/search/github.js b/commands/search/github.js index d75d3e45..b4f1d17d 100644 --- a/commands/search/github.js +++ b/commands/search/github.js @@ -1,4 +1,4 @@ -const { Command } = require('discord.js-commando'); +const Command = require('../../structures/Command'); const { RichEmbed } = require('discord.js'); const snekfetch = require('snekfetch'); const moment = require('moment'); @@ -11,6 +11,7 @@ module.exports = class GithubCommand extends Command { group: 'search', memberName: 'github', description: 'Gets repo information from GitHub.', + clientPermissions: ['EMBED_LINKS'], args: [ { key: 'repo', @@ -22,9 +23,6 @@ module.exports = class GithubCommand extends Command { } async run(msg, args) { - if (msg.channel.type !== 'dm') - if (!msg.channel.permissionsFor(this.client.user).has('EMBED_LINKS')) - return msg.say('This Command requires the `Embed Links` Permission.'); const { repo } = args; try { const { body } = await snekfetch diff --git a/commands/search/google.js b/commands/search/google.js index bcce2ead..75eb4e5f 100644 --- a/commands/search/google.js +++ b/commands/search/google.js @@ -1,4 +1,4 @@ -const { Command } = require('discord.js-commando'); +const Command = require('../../structures/Command'); const snekfetch = require('snekfetch'); const cheerio = require('cheerio'); const querystring = require('querystring'); diff --git a/commands/search/konachan.js b/commands/search/konachan.js index 092ac042..96912807 100644 --- a/commands/search/konachan.js +++ b/commands/search/konachan.js @@ -1,4 +1,4 @@ -const { Command } = require('discord.js-commando'); +const Command = require('../../structures/Command'); const snekfetch = require('snekfetch'); module.exports = class KonachanCommand extends Command { @@ -8,6 +8,7 @@ module.exports = class KonachanCommand extends Command { group: 'search', memberName: 'konachan', description: 'Sends an image from Konachan, with optional query.', + nsfw: true, args: [ { key: 'query', @@ -20,7 +21,6 @@ module.exports = class KonachanCommand extends Command { } async run(msg, args) { - if (!msg.channel.nsfw) return msg.say('This Command can only be used in NSFW Channels.'); const { query } = args; try { const { body } = await snekfetch diff --git a/commands/search/lmgtfy.js b/commands/search/lmgtfy.js index 08224004..2ddc3718 100644 --- a/commands/search/lmgtfy.js +++ b/commands/search/lmgtfy.js @@ -1,4 +1,4 @@ -const { Command } = require('discord.js-commando'); +const Command = require('../../structures/Command'); module.exports = class LMGTFYCommand extends Command { constructor(client) { diff --git a/commands/search/manga.js b/commands/search/manga.js index 31d76467..b3ad39fc 100644 --- a/commands/search/manga.js +++ b/commands/search/manga.js @@ -1,4 +1,4 @@ -const { Command } = require('discord.js-commando'); +const Command = require('../../structures/Command'); const { RichEmbed } = require('discord.js'); const snekfetch = require('snekfetch'); const { promisifyAll } = require('tsubaki'); @@ -12,6 +12,7 @@ module.exports = class MangaCommand extends Command { group: 'search', memberName: 'manga', description: 'Searches My Anime List for a specified manga.', + clientPermissions: ['EMBED_LINKS'], args: [ { key: 'query', @@ -23,9 +24,6 @@ module.exports = class MangaCommand extends Command { } async run(msg, args) { - if (msg.channel.type !== 'dm') - if (!msg.channel.permissionsFor(this.client.user).has('EMBED_LINKS')) - return msg.say('This Command requires the `Embed Links` Permission.'); const { query } = args; try { const { text } = await snekfetch diff --git a/commands/search/map.js b/commands/search/map.js index 448fa379..7b07cf28 100644 --- a/commands/search/map.js +++ b/commands/search/map.js @@ -1,4 +1,4 @@ -const { Command } = require('discord.js-commando'); +const Command = require('../../structures/Command'); const snekfetch = require('snekfetch'); const { GOOGLE_KEY } = process.env; @@ -9,6 +9,7 @@ module.exports = class MapCommand extends Command { group: 'search', memberName: 'map', description: 'Gets a map image for the location you define with the zoom level you define (1-20).', + clientPermissions: ['ATTACH_FILES'], args: [ { key: 'zoom', @@ -31,9 +32,6 @@ module.exports = class MapCommand extends Command { } async run(msg, args) { - if (msg.channel.type !== 'dm') - if (!msg.channel.permissionsFor(this.client.user).has('ATTACH_FILES')) - return msg.say('This Command requires the `Attach Files` Permission.'); const { zoom, query } = args; try { const { body } = await snekfetch diff --git a/commands/search/neopet.js b/commands/search/neopet.js index 3472203d..35e17b2f 100644 --- a/commands/search/neopet.js +++ b/commands/search/neopet.js @@ -1,4 +1,4 @@ -const { Command } = require('discord.js-commando'); +const Command = require('../../structures/Command'); const snekfetch = require('snekfetch'); const cheerio = require('cheerio'); diff --git a/commands/search/osu.js b/commands/search/osu.js index 9a3000b9..4803904f 100644 --- a/commands/search/osu.js +++ b/commands/search/osu.js @@ -1,4 +1,4 @@ -const { Command } = require('discord.js-commando'); +const Command = require('../../structures/Command'); const { RichEmbed } = require('discord.js'); const snekfetch = require('snekfetch'); const { OSU_KEY } = process.env; @@ -10,6 +10,7 @@ module.exports = class OsuCommand extends Command { group: 'search', memberName: 'osu', description: 'Searches Osu! user data.', + clientPermissions: ['EMBED_LINKS'], args: [ { key: 'query', @@ -21,9 +22,6 @@ module.exports = class OsuCommand extends Command { } async run(msg, args) { - if (msg.channel.type !== 'dm') - if (!msg.channel.permissionsFor(this.client.user).has('EMBED_LINKS')) - return msg.say('This Command requires the `Embed Links` Permission.'); const { query } = args; try { const { body } = await snekfetch diff --git a/commands/search/rule34.js b/commands/search/rule34.js index 8e3aa6e7..951a8c7e 100644 --- a/commands/search/rule34.js +++ b/commands/search/rule34.js @@ -1,4 +1,4 @@ -const { Command } = require('discord.js-commando'); +const Command = require('../../structures/Command'); const snekfetch = require('snekfetch'); const { promisifyAll } = require('tsubaki'); const xml = promisifyAll(require('xml2js')); @@ -10,6 +10,7 @@ module.exports = class Rule34Command extends Command { group: 'search', memberName: 'rule34', description: 'Sends an image from Rule34, with query.', + nsfw: true, args: [ { key: 'query', @@ -21,7 +22,6 @@ module.exports = class Rule34Command extends Command { } async run(msg, args) { - if (!msg.channel.nsfw) return msg.say('This Command can only be used in NSFW Channels.'); const { query } = args; try { const { text } = await snekfetch diff --git a/commands/search/soundcloud.js b/commands/search/soundcloud.js index c59e8630..cc2b2aa7 100644 --- a/commands/search/soundcloud.js +++ b/commands/search/soundcloud.js @@ -1,4 +1,4 @@ -const { Command } = require('discord.js-commando'); +const Command = require('../../structures/Command'); const { RichEmbed } = require('discord.js'); const snekfetch = require('snekfetch'); const { SOUNDCLOUD_KEY } = process.env; @@ -10,6 +10,7 @@ module.exports = class SoundCloudCommand extends Command { group: 'search', memberName: 'soundcloud', description: 'Searches SoundCloud for a song.', + clientPermissions: ['EMBED_LINKS'], args: [ { key: 'query', @@ -21,9 +22,6 @@ module.exports = class SoundCloudCommand extends Command { } async run(msg, args) { - if (msg.channel.type !== 'dm') - if (!msg.channel.permissionsFor(this.client.user).has('EMBED_LINKS')) - return msg.say('This Command requires the `Embed Links` Permission.'); const { query } = args; try { const { body } = await snekfetch diff --git a/commands/search/urban.js b/commands/search/urban.js index 52941cc2..e8285bbd 100644 --- a/commands/search/urban.js +++ b/commands/search/urban.js @@ -1,4 +1,4 @@ -const { Command } = require('discord.js-commando'); +const Command = require('../../structures/Command'); const { RichEmbed } = require('discord.js'); const snekfetch = require('snekfetch'); @@ -9,6 +9,7 @@ module.exports = class UrbanCommand extends Command { group: 'search', memberName: 'urban', description: 'Searches Urban Dictionary for a word.', + clientPermissions: ['EMBED_LINKS'], args: [ { key: 'query', @@ -20,9 +21,6 @@ module.exports = class UrbanCommand extends Command { } async run(msg, args) { - if (msg.channel.type !== 'dm') - if (!msg.channel.permissionsFor(this.client.user).has('EMBED_LINKS')) - return msg.say('This Command requires the `Embed Links` Permission.'); const { query } = args; try { const { body } = await snekfetch diff --git a/commands/search/wattpad.js b/commands/search/wattpad.js index 4ea5a50c..064c14d6 100644 --- a/commands/search/wattpad.js +++ b/commands/search/wattpad.js @@ -1,4 +1,4 @@ -const { Command } = require('discord.js-commando'); +const Command = require('../../structures/Command'); const { RichEmbed } = require('discord.js'); const snekfetch = require('snekfetch'); const moment = require('moment'); @@ -11,6 +11,7 @@ module.exports = class WattpadCommand extends Command { group: 'search', memberName: 'wattpad', description: 'Searches Wattpad for a book.', + clientPermissions: ['EMBED_LINKS'], args: [ { key: 'query', @@ -22,9 +23,6 @@ module.exports = class WattpadCommand extends Command { } async run(msg, args) { - if (msg.channel.type !== 'dm') - if (!msg.channel.permissionsFor(this.client.user).has('EMBED_LINKS')) - return msg.say('This Command requires the `Embed Links` Permission.'); const { query } = args; try { const { body } = await snekfetch @@ -33,7 +31,7 @@ module.exports = class WattpadCommand extends Command { query, limit: 1 }) - .set({ 'Authorization': `Basic ${WATTPAD_KEY}` }); + .set({ Authorization: `Basic ${WATTPAD_KEY}` }); if (!body.stories.length) throw new Error('No Results.'); const embed = new RichEmbed() .setColor(0xF89C34) diff --git a/commands/search/weather.js b/commands/search/weather.js index 797e6054..7f9971d5 100644 --- a/commands/search/weather.js +++ b/commands/search/weather.js @@ -1,4 +1,4 @@ -const { Command } = require('discord.js-commando'); +const Command = require('../../structures/Command'); const { RichEmbed } = require('discord.js'); const snekfetch = require('snekfetch'); @@ -9,6 +9,7 @@ module.exports = class WeatherCommand extends Command { group: 'search', memberName: 'weather', description: 'Gets weather information for a specified location.', + clientPermissions: ['EMBED_LINKS'], args: [ { key: 'query', @@ -20,9 +21,6 @@ module.exports = class WeatherCommand extends Command { } async run(msg, args) { - if (msg.channel.type !== 'dm') - if (!msg.channel.permissionsFor(this.client.user).has('EMBED_LINKS')) - return msg.say('This Command requires the `Embed Links` Permission.'); const { query } = args; try { const { body } = await snekfetch diff --git a/commands/search/wikipedia.js b/commands/search/wikipedia.js index ee6b1050..c8b87a26 100644 --- a/commands/search/wikipedia.js +++ b/commands/search/wikipedia.js @@ -1,4 +1,4 @@ -const { Command } = require('discord.js-commando'); +const Command = require('../../structures/Command'); const { RichEmbed } = require('discord.js'); const snekfetch = require('snekfetch'); @@ -9,6 +9,7 @@ module.exports = class WikipediaCommand extends Command { group: 'search', memberName: 'wikipedia', description: 'Searches Wikipedia for something.', + clientPermissions: ['EMBED_LINKS'], args: [ { key: 'query', @@ -20,9 +21,6 @@ module.exports = class WikipediaCommand extends Command { } async run(msg, args) { - if (msg.channel.type !== 'dm') - if (!msg.channel.permissionsFor(this.client.user).has('EMBED_LINKS')) - return msg.say('This Command requires the `Embed Links` Permission.'); const { query } = args; try { const { body } = await snekfetch diff --git a/commands/search/youtube.js b/commands/search/youtube.js index 31414469..6d5c6f02 100644 --- a/commands/search/youtube.js +++ b/commands/search/youtube.js @@ -1,4 +1,4 @@ -const { Command } = require('discord.js-commando'); +const Command = require('../../structures/Command'); const { RichEmbed } = require('discord.js'); const snekfetch = require('snekfetch'); const { GOOGLE_KEY } = process.env; @@ -10,6 +10,7 @@ module.exports = class YouTubeCommand extends Command { group: 'search', memberName: 'youtube', description: 'Searches YouTube for a video.', + clientPermissions: ['EMBED_LINKS'], args: [ { key: 'query', @@ -21,9 +22,6 @@ module.exports = class YouTubeCommand extends Command { } async run(msg, args) { - if (msg.channel.type !== 'dm') - if (!msg.channel.permissionsFor(this.client.user).has('EMBED_LINKS')) - return msg.say('This Command requires the `Embed Links` Permission.'); const { query } = args; try { const { body } = await snekfetch diff --git a/commands/search/yu-gi-oh.js b/commands/search/yu-gi-oh.js index 42803783..6bf40559 100644 --- a/commands/search/yu-gi-oh.js +++ b/commands/search/yu-gi-oh.js @@ -1,4 +1,4 @@ -const { Command } = require('discord.js-commando'); +const Command = require('../../structures/Command'); const { RichEmbed } = require('discord.js'); const snekfetch = require('snekfetch'); @@ -9,6 +9,7 @@ module.exports = class YuGiOhCommand extends Command { group: 'search', memberName: 'yu-gi-oh', description: 'Gets info on a Yu-Gi-Oh! Card.', + clientPermissions: ['EMBED_LINKS'], args: [ { key: 'query', @@ -21,9 +22,6 @@ module.exports = class YuGiOhCommand extends Command { } async run(msg, args) { - if (msg.channel.type !== 'dm') - if (!msg.channel.permissionsFor(this.client.user).has('EMBED_LINKS')) - return msg.say('This Command requires the `Embed Links` Permission.'); const { query } = args; try { const { body } = await snekfetch diff --git a/commands/settings/clear-setting.js b/commands/settings/clear-setting.js index 3d62d6b4..246237ac 100644 --- a/commands/settings/clear-setting.js +++ b/commands/settings/clear-setting.js @@ -1,4 +1,4 @@ -const { Command } = require('discord.js-commando'); +const Command = require('../../structures/Command'); const settings = require('../../assets/json/clear-setting'); module.exports = class ClearSettingCommand extends Command { @@ -9,6 +9,7 @@ module.exports = class ClearSettingCommand extends Command { memberName: 'clear-setting', description: 'Removes a custom setting from your server.', guildOnly: true, + userPermissions: ['ADMINISTRATOR'], args: [ { key: 'setting', @@ -23,11 +24,6 @@ module.exports = class ClearSettingCommand extends Command { }); } - hasPermission(msg) { - if (!msg.member.hasPermission('ADMINISTRATOR')) return 'You do not have the `Administrator` Permission.'; - else return true; - } - run(msg, args) { const { setting } = args; msg.guild.settings.remove(setting); diff --git a/commands/settings/invite-guard.js b/commands/settings/invite-guard.js index 556e95ed..264ea92d 100644 --- a/commands/settings/invite-guard.js +++ b/commands/settings/invite-guard.js @@ -1,4 +1,4 @@ -const { Command } = require('discord.js-commando'); +const Command = require('../../structures/Command'); module.exports = class InviteGuardCommand extends Command { constructor(client) { @@ -7,15 +7,11 @@ module.exports = class InviteGuardCommand extends Command { group: 'settings', memberName: 'invite-guard', description: 'Configures auto-delete for invites.', - guildOnly: true + guildOnly: true, + userPermissions: ['ADMINISTRATOR'] }); } - hasPermission(msg) { - if (!msg.member.hasPermission('ADMINISTRATOR')) return 'You do not have the `Administrator` Permission.'; - else return true; - } - run(msg) { msg.guild.settings.set('inviteGuard', true); return msg.say('Invite Guard is now active.'); diff --git a/commands/settings/join-role.js b/commands/settings/join-role.js index 1e390203..828e0c77 100644 --- a/commands/settings/join-role.js +++ b/commands/settings/join-role.js @@ -1,4 +1,4 @@ -const { Command } = require('discord.js-commando'); +const Command = require('../../structures/Command'); module.exports = class JoinRoleCommand extends Command { constructor(client) { @@ -8,6 +8,7 @@ module.exports = class JoinRoleCommand extends Command { memberName: 'join-role', description: 'Sets a role that new members are automatically joined to.', guildOnly: true, + userPermissions: ['ADMINISTRATOR'], args: [ { key: 'role', @@ -18,11 +19,6 @@ module.exports = class JoinRoleCommand extends Command { }); } - hasPermission(msg) { - if (!msg.member.hasPermission('ADMINISTRATOR')) return 'You do not have the `Administrator` Permission.'; - else return true; - } - run(msg, args) { const { role } = args; msg.guild.settings.set('joinRole', role.id); diff --git a/commands/settings/member-channel.js b/commands/settings/member-channel.js index 71164aa1..5c7192ab 100644 --- a/commands/settings/member-channel.js +++ b/commands/settings/member-channel.js @@ -1,4 +1,4 @@ -const { Command } = require('discord.js-commando'); +const Command = require('../../structures/Command'); module.exports = class MemberLogCommand extends Command { constructor(client) { @@ -8,6 +8,7 @@ module.exports = class MemberLogCommand extends Command { memberName: 'member-channel', description: 'Sets the channel for the member logs to be sent.', guildOnly: true, + userPermissions: ['ADMINISTRATOR'], args: [ { key: 'channel', @@ -18,11 +19,6 @@ module.exports = class MemberLogCommand extends Command { }); } - hasPermission(msg) { - if (!msg.member.hasPermission('ADMINISTRATOR')) return 'You do not have the `Administrator` Permission.'; - else return true; - } - run(msg, args) { const { channel } = args; msg.guild.settings.set('memberLog', channel.id); diff --git a/commands/settings/member-message.js b/commands/settings/member-message.js index 17f0b6b7..6aca7c82 100644 --- a/commands/settings/member-message.js +++ b/commands/settings/member-message.js @@ -1,4 +1,4 @@ -const { Command } = require('discord.js-commando'); +const Command = require('../../structures/Command'); module.exports = class MemberMsgCommand extends Command { constructor(client) { @@ -10,6 +10,7 @@ module.exports = class MemberMsgCommand extends Command { description: 'Sets the message for either join/leave logs to use.', details: '**Placeholders:** : Username, : Server Name, : A Mention of the User', guildOnly: true, + userPermissions: ['ADMINISTRATOR'], args: [ { key: 'type', @@ -33,11 +34,6 @@ module.exports = class MemberMsgCommand extends Command { }); } - hasPermission(msg) { - if (!msg.member.hasPermission('ADMINISTRATOR')) return 'You do not have the `Administrator` Permission.'; - else return true; - } - run(msg, args) { const { type, message } = args; if (type === 'joinMsg') { diff --git a/commands/settings/mod-channel.js b/commands/settings/mod-channel.js index ccfbf5c3..30736337 100644 --- a/commands/settings/mod-channel.js +++ b/commands/settings/mod-channel.js @@ -1,4 +1,4 @@ -const { Command } = require('discord.js-commando'); +const Command = require('../../structures/Command'); module.exports = class ModChannelCommand extends Command { constructor(client) { @@ -8,6 +8,7 @@ module.exports = class ModChannelCommand extends Command { memberName: 'mod-channel', description: 'Sets the channel for the mod logs to be sent.', guildOnly: true, + userPermissions: ['ADMINISTRATOR'], args: [ { key: 'channel', @@ -18,11 +19,6 @@ module.exports = class ModChannelCommand extends Command { }); } - hasPermission(msg) { - if (!msg.member.hasPermission('ADMINISTRATOR')) return 'You do not have the `Administrator` Permission.'; - else return true; - } - run(msg, args) { const { channel } = args; msg.guild.settings.set('modLog', channel.id); diff --git a/commands/settings/setting-list.js b/commands/settings/setting-list.js index e0697cdf..84e6c4e4 100644 --- a/commands/settings/setting-list.js +++ b/commands/settings/setting-list.js @@ -1,4 +1,4 @@ -const { Command } = require('discord.js-commando'); +const Command = require('../../structures/Command'); const { stripIndents } = require('common-tags'); module.exports = class SettingListCommand extends Command { diff --git a/commands/settings/single-role.js b/commands/settings/single-role.js index 0d7e1d11..0e5e8a6f 100644 --- a/commands/settings/single-role.js +++ b/commands/settings/single-role.js @@ -1,4 +1,4 @@ -const { Command } = require('discord.js-commando'); +const Command = require('../../structures/Command'); module.exports = class SingleRoleCommand extends Command { constructor(client) { @@ -8,6 +8,7 @@ module.exports = class SingleRoleCommand extends Command { memberName: 'single-role', description: 'Sets a single role that is able to use commands.', guildOnly: true, + userPermissions: ['ADMINISTRATOR'], args: [ { key: 'role', @@ -18,11 +19,6 @@ module.exports = class SingleRoleCommand extends Command { }); } - hasPermission(msg) { - if (!msg.member.hasPermission('ADMINISTRATOR')) return 'You do not have the `Administrator` Permission.'; - else return true; - } - run(msg, args) { const { role } = args; msg.guild.settings.set('singleRole', role.id); diff --git a/commands/settings/staff-role.js b/commands/settings/staff-role.js index 6cddab14..6758cf5c 100644 --- a/commands/settings/staff-role.js +++ b/commands/settings/staff-role.js @@ -1,4 +1,4 @@ -const { Command } = require('discord.js-commando'); +const Command = require('../../structures/Command'); module.exports = class StaffRoleCommand extends Command { constructor(client) { @@ -8,6 +8,7 @@ module.exports = class StaffRoleCommand extends Command { memberName: 'staff-role', description: 'Sets the role that can use Mod Commands without perms.', guildOnly: true, + userPermissions: ['ADMINISTRATOR'], args: [ { key: 'role', @@ -18,11 +19,6 @@ module.exports = class StaffRoleCommand extends Command { }); } - hasPermission(msg) { - if (!msg.member.hasPermission('ADMINISTRATOR')) return 'You do not have the `Administrator` Permission.'; - else return true; - } - run(msg, args) { const { role } = args; msg.guild.settings.set('staffRole', role.id); diff --git a/commands/settings/starboard.js b/commands/settings/starboard.js index e686ccf1..077a7162 100644 --- a/commands/settings/starboard.js +++ b/commands/settings/starboard.js @@ -1,4 +1,4 @@ -const { Command } = require('discord.js-commando'); +const Command = require('../../structures/Command'); module.exports = class StarboardCommand extends Command { constructor(client) { @@ -8,6 +8,7 @@ module.exports = class StarboardCommand extends Command { memberName: 'starboard', description: 'Sets the channel for the starboard.', guildOnly: true, + userPermissions: ['ADMINISTRATOR'], args: [ { key: 'channel', @@ -18,11 +19,6 @@ module.exports = class StarboardCommand extends Command { }); } - hasPermission(msg) { - if (!msg.member.hasPermission('ADMINISTRATOR')) return 'You do not have the `Administrator` Permission.'; - else return true; - } - run(msg, args) { const { channel } = args; msg.guild.settings.set('starboard', channel.id); diff --git a/commands/textedit/binary.js b/commands/textedit/binary.js index b4ecd90a..e5949bed 100644 --- a/commands/textedit/binary.js +++ b/commands/textedit/binary.js @@ -1,11 +1,4 @@ -const { Command } = require('discord.js-commando'); -const binary = (str) => { - return unescape(encodeURIComponent(str)) - .split('').map(str => { - const binary = str.charCodeAt(0).toString(2); - return `${'00000000'.slice(binary.length)}${binary}`; - }).join(''); -}; +const Command = require('../../structures/Command'); module.exports = class BinaryCommand extends Command { constructor(client) { @@ -20,10 +13,10 @@ module.exports = class BinaryCommand extends Command { prompt: 'What text would you like to convert to binary?', type: 'string', validate: text => { - if (binary(text).length < 2000) return true; + if (this.binary(text).length < 2000) return true; return 'Your text is too long.'; }, - parse: text => binary(text) + parse: text => this.binary(text) } ] }); @@ -33,4 +26,11 @@ module.exports = class BinaryCommand extends Command { const { text } = args; return msg.say(text); } + + binary(text) { + return unescape(encodeURIComponent(text)).split('').map(str => { + const converted = str.charCodeAt(0).toString(2); + return `${'00000000'.slice(converted.length)}${converted}`; + }).join(''); + } }; diff --git a/commands/textedit/cow-say.js b/commands/textedit/cow-say.js index a0046cb3..c28204c6 100644 --- a/commands/textedit/cow-say.js +++ b/commands/textedit/cow-say.js @@ -1,4 +1,4 @@ -const { Command } = require('discord.js-commando'); +const Command = require('../../structures/Command'); const { stripIndent } = require('common-tags'); module.exports = class CowsayCommand extends Command { diff --git a/commands/textedit/embed.js b/commands/textedit/embed.js index c3bd0dee..9522b58a 100644 --- a/commands/textedit/embed.js +++ b/commands/textedit/embed.js @@ -1,4 +1,4 @@ -const { Command } = require('discord.js-commando'); +const Command = require('../../structures/Command'); const { RichEmbed } = require('discord.js'); module.exports = class EmbedCommand extends Command { @@ -8,6 +8,7 @@ module.exports = class EmbedCommand extends Command { group: 'textedit', memberName: 'embed', description: 'Sends a message in an embed.', + clientPermissions: ['EMBED_LINKS'], args: [ { key: 'text', @@ -19,9 +20,6 @@ module.exports = class EmbedCommand extends Command { } run(msg, args) { - if (msg.channel.type !== 'dm') - if (!msg.channel.permissionsFor(this.client.user).has('EMBED_LINKS')) - return msg.say('This Command requires the `Embed Links` Permission.'); const { text } = args; const embed = new RichEmbed() .setAuthor(msg.author.tag, msg.author.displayAvatarURL) diff --git a/commands/textedit/morse.js b/commands/textedit/morse.js index fe846bac..73300bbc 100644 --- a/commands/textedit/morse.js +++ b/commands/textedit/morse.js @@ -1,4 +1,4 @@ -const { Command } = require('discord.js-commando'); +const Command = require('../../structures/Command'); const { letterTrans } = require('custom-translate'); const dictionary = require('../../assets/json/morse'); diff --git a/commands/textedit/pirate.js b/commands/textedit/pirate.js index 4615114a..cec84e0d 100644 --- a/commands/textedit/pirate.js +++ b/commands/textedit/pirate.js @@ -1,4 +1,4 @@ -const { Command } = require('discord.js-commando'); +const Command = require('../../structures/Command'); const { wordTrans } = require('custom-translate'); const dictionary = require('../../assets/json/pirate'); diff --git a/commands/textedit/repeat.js b/commands/textedit/repeat.js index 3b149c89..d6420cf7 100644 --- a/commands/textedit/repeat.js +++ b/commands/textedit/repeat.js @@ -1,4 +1,4 @@ -const { Command } = require('discord.js-commando'); +const Command = require('../../structures/Command'); module.exports = class RepeatCommand extends Command { constructor(client) { diff --git a/commands/textedit/reverse.js b/commands/textedit/reverse.js index 49ddc78a..052b7f5a 100644 --- a/commands/textedit/reverse.js +++ b/commands/textedit/reverse.js @@ -1,4 +1,4 @@ -const { Command } = require('discord.js-commando'); +const Command = require('../../structures/Command'); module.exports = class ReverseCommand extends Command { constructor(client) { diff --git a/commands/textedit/say.js b/commands/textedit/say.js index a16b3f34..c5dcdb8d 100644 --- a/commands/textedit/say.js +++ b/commands/textedit/say.js @@ -1,4 +1,4 @@ -const { Command } = require('discord.js-commando'); +const Command = require('../../structures/Command'); module.exports = class SayCommand extends Command { constructor(client) { @@ -9,6 +9,7 @@ module.exports = class SayCommand extends Command { memberName: 'say', description: 'Make XiaoBot say what you wish.', guildOnly: true, + clientPermissions: ['MANAGE_MESSAGES'], args: [ { key: 'text', @@ -20,8 +21,6 @@ module.exports = class SayCommand extends Command { } run(msg, args) { - if (!msg.channel.permissionsFor(this.client.user).has('MANAGE_MESSAGES')) - return msg.say('This Command requires the `Manage Messages` Permission.'); const { text } = args; msg.delete(); return msg.say(`\u180E${text}`); diff --git a/commands/textedit/temmie.js b/commands/textedit/temmie.js index 6116ec94..2884d0c1 100644 --- a/commands/textedit/temmie.js +++ b/commands/textedit/temmie.js @@ -1,4 +1,4 @@ -const { Command } = require('discord.js-commando'); +const Command = require('../../structures/Command'); const { wordTrans } = require('custom-translate'); const dictionary = require('../../assets/json/temmie'); diff --git a/commands/textedit/translate.js b/commands/textedit/translate.js index ac776a04..c7706c49 100644 --- a/commands/textedit/translate.js +++ b/commands/textedit/translate.js @@ -1,4 +1,4 @@ -const { Command } = require('discord.js-commando'); +const Command = require('../../structures/Command'); const { RichEmbed } = require('discord.js'); const snekfetch = require('snekfetch'); const codes = require('../../assets/json/translate'); @@ -12,6 +12,7 @@ module.exports = class TranslateCommand extends Command { memberName: 'translate', description: 'Translates text to a specified language.', details: '**Codes:** https://tech.yandex.com/translate/doc/dg/concepts/api-overview-docpage/#languages', + clientPermissions: ['EMBED_LINKS'], args: [ { key: 'text', @@ -44,9 +45,6 @@ module.exports = class TranslateCommand extends Command { } async run(msg, args) { - if (msg.channel.type !== 'dm') - if (!msg.channel.permissionsFor(this.client.user).has('EMBED_LINKS')) - return msg.say('This Command requires the `Embed Links` Permission.'); const { text, to, from } = args; try { const { body } = await snekfetch diff --git a/commands/textedit/upside-down.js b/commands/textedit/upside-down.js index be469c0d..44397208 100644 --- a/commands/textedit/upside-down.js +++ b/commands/textedit/upside-down.js @@ -1,4 +1,4 @@ -const { Command } = require('discord.js-commando'); +const Command = require('../../structures/Command'); const { letterTrans } = require('custom-translate'); const dictionary = require('../../assets/json/upside-down'); diff --git a/commands/textedit/webhook.js b/commands/textedit/webhook.js index c6ddd636..17072040 100644 --- a/commands/textedit/webhook.js +++ b/commands/textedit/webhook.js @@ -1,4 +1,4 @@ -const { Command } = require('discord.js-commando'); +const Command = require('../../structures/Command'); const snekfetch = require('snekfetch'); const { WEBHOOK_URL } = process.env; @@ -11,6 +11,8 @@ module.exports = class WebhookCommand extends Command { memberName: 'webhook', description: 'Posts a message to the webhook defined in your `process.env`.', guildOnly: true, + ownerOnly: true, + clientPermissions: ['MANAGE_MESSAGES'], args: [ { key: 'content', @@ -26,8 +28,6 @@ module.exports = class WebhookCommand extends Command { } async run(msg, args) { - if (!msg.channel.permissionsFor(this.client.user).has('MANAGE_MESSAGES')) - return msg.say('This Command requires the `Manage Messages` Permission.'); const { content } = args; try { msg.delete(); diff --git a/commands/textedit/zalgo.js b/commands/textedit/zalgo.js index e588518a..2b1a325e 100644 --- a/commands/textedit/zalgo.js +++ b/commands/textedit/zalgo.js @@ -1,4 +1,4 @@ -const { Command } = require('discord.js-commando'); +const Command = require('../../structures/Command'); const zalgo = require('zalgolize'); module.exports = class ZalgoCommand extends Command { diff --git a/commands/userinfo/avatar.js b/commands/userinfo/avatar.js index 596df7d0..880cb394 100644 --- a/commands/userinfo/avatar.js +++ b/commands/userinfo/avatar.js @@ -1,4 +1,4 @@ -const { Command } = require('discord.js-commando'); +const Command = require('../../structures/Command'); module.exports = class AvatarCommand extends Command { constructor(client) { diff --git a/commands/userinfo/user-info.js b/commands/userinfo/user-info.js index 57b6b492..6ed3b78c 100644 --- a/commands/userinfo/user-info.js +++ b/commands/userinfo/user-info.js @@ -1,4 +1,4 @@ -const { Command } = require('discord.js-commando'); +const Command = require('../../structures/Command'); const { RichEmbed } = require('discord.js'); const { stripIndents } = require('common-tags'); const moment = require('moment'); @@ -13,6 +13,7 @@ module.exports = class UserInfoCommand extends Command { memberName: 'user', description: 'Gives some info on a user.', guildOnly: true, + clientPermissions: ['EMBED_LINKS'], args: [ { key: 'member', @@ -24,9 +25,6 @@ module.exports = class UserInfoCommand extends Command { } run(msg, args) { - if (msg.channel.type !== 'dm') - if (!msg.channel.permissionsFor(this.client.user).has('EMBED_LINKS')) - return msg.say('This Command requires the `Embed Links` Permission.'); const { member } = args; let stat; let color; diff --git a/commands/util/help.js b/commands/util/help.js index 2824a783..da9ceca3 100644 --- a/commands/util/help.js +++ b/commands/util/help.js @@ -1,4 +1,4 @@ -const { Command } = require('discord.js-commando'); +const Command = require('../../structures/Command'); const { RichEmbed } = require('discord.js'); const { stripIndents } = require('common-tags'); @@ -11,6 +11,7 @@ module.exports = class HelpCommand extends Command { memberName: 'help', description: 'Displays a list of available commands, or detailed information for a specified command.', guarded: true, + clientPermissions: ['EMBED_LINKS'], args: [ { key: 'command', @@ -36,15 +37,11 @@ module.exports = class HelpCommand extends Command { **Group:** ${commands[0].group.name} ${commands[0].details || ''} `); - } else if (commands.length > 1) { - return msg.say(`Multiple Commands Found. Please be more specific: ${commands.map(c => c.name).join(', ')}`); - } else { - return msg.say(`Could not identify command. Use ${msg.usage(null)} to view a list of commands you can use.`); - } + } else return msg.say(`Could not identify command. Use \`${msg.usage(null)}\` to view a list of commands you can use.`); } 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 specific command.`) .setColor(0x00AE86); for (const group of this.client.registry.groups.values()) { embed.addField(group.name, diff --git a/commands/util/info.js b/commands/util/info.js index ce0dac3b..14063643 100644 --- a/commands/util/info.js +++ b/commands/util/info.js @@ -1,4 +1,4 @@ -const { Command } = require('discord.js-commando'); +const Command = require('../../structures/Command'); const { RichEmbed } = require('discord.js'); const { oneLine } = require('common-tags'); const { version } = require('../../package'); @@ -13,14 +13,12 @@ module.exports = class InfoCommand extends Command { group: 'util', memberName: 'info', description: 'Gives some bot info.', - guarded: true + guarded: true, + clientPermissions: ['EMBED_LINKS'] }); } async run(msg) { - if (msg.channel.type !== 'dm') - if (!msg.channel.permissionsFor(this.client.user).has('EMBED_LINKS')) - return msg.say('This Command requires the `Embed Links` Permission.'); const guilds = await this.client.shard.fetchClientValues('guilds.size'); const memory = await this.client.shard.broadcastEval('Math.round(process.memoryUsage().heapUsed / 1024 / 1024)'); const embed = new RichEmbed() diff --git a/commands/util/invite.js b/commands/util/invite.js index 78a6c702..589334b4 100644 --- a/commands/util/invite.js +++ b/commands/util/invite.js @@ -1,4 +1,4 @@ -const { Command } = require('discord.js-commando'); +const Command = require('../../structures/Command'); const { stripIndents } = require('common-tags'); module.exports = class InviteCommand extends Command { diff --git a/commands/util/ping.js b/commands/util/ping.js index add28f66..95e91835 100644 --- a/commands/util/ping.js +++ b/commands/util/ping.js @@ -1,4 +1,4 @@ -const { Command } = require('discord.js-commando'); +const Command = require('../../structures/Command'); const { stripIndents } = require('common-tags'); module.exports = class PingCommand extends Command { @@ -16,9 +16,8 @@ module.exports = class PingCommand extends Command { async run(msg) { const message = await msg.say('Pinging...'); return message.edit(stripIndents` - :ping_pong: Pong! - **Message Ping:** ${Math.round(message.createdTimestamp - msg.createdTimestamp)}ms - **Heartbeat Ping:** ${Math.round(this.client.ping)}ms + :ping_pong: Pong! \`${Math.round(message.createdTimestamp - msg.createdTimestamp)}ms\` + Heartbeat: \`${Math.round(this.client.ping)}ms\` `); } }; diff --git a/commands/util/shard-info.js b/commands/util/shard-info.js index 200bbaea..cef992bc 100644 --- a/commands/util/shard-info.js +++ b/commands/util/shard-info.js @@ -1,4 +1,4 @@ -const { Command } = require('discord.js-commando'); +const Command = require('../../structures/Command'); const { RichEmbed } = require('discord.js'); const moment = require('moment'); require('moment-duration-format'); @@ -12,6 +12,7 @@ module.exports = class ShardInfoCommand extends Command { memberName: 'shard-info', description: 'Gives some bot info for the Shard you specify.', guarded: true, + clientPermissions: ['EMBED_LINKS'], args: [ { key: 'shard', @@ -27,9 +28,6 @@ module.exports = class ShardInfoCommand extends Command { } async run(msg, args) { - if (msg.channel.type !== 'dm') - if (!msg.channel.permissionsFor(this.client.user).has('EMBED_LINKS')) - return msg.say('This Command requires the `Embed Links` Permission.'); const { shard } = args; const memory = await this.client.shard.broadcastEval('Math.round(process.memoryUsage().heapUsed / 1024 / 1024)'); const uptime = await this.client.shard.fetchClientValues('uptime'); diff --git a/commands/util/uptime.js b/commands/util/uptime.js index 96ee3810..da19b080 100644 --- a/commands/util/uptime.js +++ b/commands/util/uptime.js @@ -1,4 +1,4 @@ -const { Command } = require('discord.js-commando'); +const Command = require('../../structures/Command'); const moment = require('moment'); require('moment-duration-format'); diff --git a/package.json b/package.json index 7b23b104..4a8ec80d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiaobot", - "version": "21.4.6", + "version": "21.4.7", "description": "A Discord Bot", "main": "Shard.js", "scripts": { @@ -30,7 +30,7 @@ }, "homepage": "http://dragonfire535.weebly.com/xiaobot.html", "engines": { - "node": "7.10.0" + "node": "8.0.0" }, "dependencies": { "bufferutil": "^3.0.0", diff --git a/structures/Command.js b/structures/Command.js new file mode 100644 index 00000000..9c81f5fa --- /dev/null +++ b/structures/Command.js @@ -0,0 +1,44 @@ +const { Command } = require('discord.js-commando'); + +class XiaoCommand extends Command { + constructor(client, info) { + super(client, info); + + this.ownerOnly = info.ownerOnly; + this.nsfw = info.nsfw; + this.clientPermissions = info.clientPermissions; + this.allowStaff = info.allowStaff; + this.userPermissions = info.userPermissions; + } + + hasPermission(msg) { + if (this.ownerOnly) { + if (!this.client.isOwner(msg.author)) return 'This Command can only be used by the bot owner.'; + } + if (this.nsfw) { + if (!msg.channel.nsfw) return 'This Command can only be used in NSFW Channels.'; + } + if (msg.channel.type !== 'dm') { + if (this.clientPermissions) { + for (const permission of this.clientPermissions) { + if (!msg.channel.permissionsFor(this.client.user).has(permission)) + return `This Command requires the \`${permission}\` Permission.`; + } + } + const staffRole = msg.guild.settings.get('staffRole'); + if (staffRole && this.allowStaff) { + if (!msg.member.roles.has(staffRole)) + return `This Command can only be used by the \`${msg.guild.roles.get(staffRole).name}\` role.`; + } + if (this.userPermissions && (this.allowStaff ? !msg.member.roles.has(staffRole) : true)) { + for (const permission of this.userPermissions) { + if (!msg.channel.permissionsFor(msg.author).has(permission)) + return `You do not have the \`${permission}\` Permission.`; + } + } + } + return true; + } +} + +module.exports = XiaoCommand; diff --git a/structures/Stats.js b/structures/Stats.js index 1815dbba..778213e4 100644 --- a/structures/Stats.js +++ b/structures/Stats.js @@ -5,7 +5,7 @@ class Stats { static dBots(server_count, id) { snekfetch .post(`https://bots.discord.pw/api/bots/${id}/stats`) - .set({ 'Authorization': DBOTS_KEY }) + .set({ Authorization: DBOTS_KEY }) .send({ server_count }) .then(() => console.log('[Carbon] Successfully posted to Carbon.')) .catch(err => console.error(`[Carbon] Failed to post to Carbon. ${err}`));