diff --git a/XiaoBot.js b/XiaoBot.js index 11e918ae..97b282b9 100644 --- a/XiaoBot.js +++ b/XiaoBot.js @@ -68,14 +68,12 @@ client.on('warn', console.warn); client.on('commandError', (command, err) => console.error(command.name, err)); client.on('guildCreate', async guild => { - console.log(`[GUILD] I have joined ${guild.name}! (${guild.id})`); const guilds = await client.shard.fetchClientValues('guilds.size'); const count = guilds.reduce((prev, val) => prev + val, 0); postStats(count, client.user.id); }); client.on('guildDelete', async guild => { - console.log(`[GUILD] I have left ${guild.name}... (${guild.id})`); const guilds = await client.shard.fetchClientValues('guilds.size'); const count = guilds.reduce((prev, val) => prev + val, 0); postStats(count, client.user.id); diff --git a/assets/json/horoscope.json b/assets/json/horoscope.json new file mode 100644 index 00000000..5f58712a --- /dev/null +++ b/assets/json/horoscope.json @@ -0,0 +1,14 @@ +[ + "capricorn", + "aquarius", + "pisces", + "aries", + "taurus", + "gemini", + "cancer", + "leo", + "virgo", + "libra", + "scorpio", + "sagittarius" +] diff --git a/assets/json/tag.json b/assets/json/tag.json index 3a8c5f26..35ab2af4 100644 --- a/assets/json/tag.json +++ b/assets/json/tag.json @@ -41,5 +41,7 @@ "angery": "https://cdn.discordapp.com/attachments/256055608279695360/308701431165091840/angerey.png", "banana": "https://cdn.discordapp.com/attachments/256055608279695360/308771979010244618/vfy6JExK7Ryhi.gif", "yuno gasai": "https://cdn.discordapp.com/attachments/256055608279695360/308658394766508033/ff79c3c19cf7e6fdc00c1c26c204c3f6.jpg", - "why": "https://www.youtube.com/watch?v=sluHwh3hJhI" + "why": "https://www.youtube.com/watch?v=sluHwh3hJhI", + "it's joke": "https://i.imgur.com/Gmsx9Ma.jpg", + "xd": "https://i.imgur.com/qdKDbRc.jpg" } diff --git a/commands/avatar-edit/3000-years.js b/commands/avatar-edit/3000-years.js index f8f71c34..12c88370 100644 --- a/commands/avatar-edit/3000-years.js +++ b/commands/avatar-edit/3000-years.js @@ -13,7 +13,7 @@ module.exports = class YearsCommand extends Command { description: 'Draws a user\'s avatar over Pokémon\'s "It\'s been 3000 years" meme.', throttling: { usages: 1, - duration: 30 + duration: 15 }, clientPermissions: ['ATTACH_FILES'], args: [ @@ -41,7 +41,7 @@ module.exports = class YearsCommand extends Command { const avatar = await loadImage(body); ctx.drawImage(base, 0, 0); ctx.drawImage(avatar, 461, 127, 200, 200); - return msg.say({ files: [{ attachment: canvas.toBuffer(), name: '3000-years.png' }] }); + return msg.say({ files: [canvas.toBuffer()] }); } catch (err) { return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); } diff --git a/commands/avatar-edit/approved.js b/commands/avatar-edit/approved.js index 0e0f8db3..26fe0804 100644 --- a/commands/avatar-edit/approved.js +++ b/commands/avatar-edit/approved.js @@ -13,7 +13,7 @@ module.exports = class ApprovedCommand extends Command { description: 'Draws an "approved" stamp over a user\'s avatar.', throttling: { usages: 1, - duration: 30 + duration: 15 }, clientPermissions: ['ATTACH_FILES'], args: [ @@ -41,7 +41,7 @@ module.exports = class ApprovedCommand extends Command { const avatar = await loadImage(body); ctx.drawImage(avatar, 0, 0, 256, 256); ctx.drawImage(base, 0, 0, 256, 256); - return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'approved.png' }] }); + return msg.say({ files: [canvas.toBuffer()] }); } catch (err) { return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); } diff --git a/commands/avatar-edit/avatar-fusion.js b/commands/avatar-edit/avatar-fusion.js index b3046c10..70c868d5 100644 --- a/commands/avatar-edit/avatar-fusion.js +++ b/commands/avatar-edit/avatar-fusion.js @@ -12,7 +12,7 @@ module.exports = class AvatarFusionCommand extends Command { description: 'Draws a a user\'s avatar over a user\'s avatar.', throttling: { usages: 1, - duration: 30 + duration: 15 }, clientPermissions: ['ATTACH_FILES'], args: [ @@ -51,7 +51,7 @@ module.exports = class AvatarFusionCommand extends Command { ctx.globalAlpha = 0.5; ctx.drawImage(baseAvatar, 0, 0, 256, 256); ctx.drawImage(overlayAvatar, 0, 0, 256, 256); - return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'avatar-fusion.png' }] }); + return msg.say({ files: [canvas.toBuffer()] }); } catch (err) { return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); } diff --git a/commands/avatar-edit/beautiful.js b/commands/avatar-edit/beautiful.js index 663c30ac..84c5f264 100644 --- a/commands/avatar-edit/beautiful.js +++ b/commands/avatar-edit/beautiful.js @@ -13,7 +13,7 @@ module.exports = class BeautifulCommand extends Command { description: 'Draws a user\'s avatar over Gravity Falls\' "Oh, this? This is beautiful." meme.', throttling: { usages: 1, - duration: 30 + duration: 15 }, clientPermissions: ['ATTACH_FILES'], args: [ @@ -42,7 +42,7 @@ module.exports = class BeautifulCommand extends Command { ctx.drawImage(base, 0, 0); ctx.drawImage(avatar, 341, 35, 117, 135); ctx.drawImage(avatar, 343, 301, 117, 135); - return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'beautiful.png' }] }); + return msg.say({ files: [canvas.toBuffer()] }); } catch (err) { return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); } diff --git a/commands/avatar-edit/bob-ross.js b/commands/avatar-edit/bob-ross.js index 8b7ed095..1e1592df 100644 --- a/commands/avatar-edit/bob-ross.js +++ b/commands/avatar-edit/bob-ross.js @@ -13,7 +13,7 @@ module.exports = class BobRossCommand extends Command { description: 'Draws a user\'s avatar over Bob Ross\' canvas.', throttling: { usages: 1, - duration: 30 + duration: 15 }, clientPermissions: ['ATTACH_FILES'], args: [ @@ -45,7 +45,7 @@ module.exports = class BobRossCommand extends Command { ctx.drawImage(avatar, 69, 102, 256, 256); ctx.rotate(-3 * (Math.PI / 180)); ctx.drawImage(base, 0, 0); - return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'bob-ross.png' }] }); + return msg.say({ files: [canvas.toBuffer()] }); } catch (err) { return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); } diff --git a/commands/avatar-edit/card.js b/commands/avatar-edit/card.js index 4164e2dc..2f4c0816 100644 --- a/commands/avatar-edit/card.js +++ b/commands/avatar-edit/card.js @@ -15,34 +15,33 @@ module.exports = class CardCommand extends Command { group: 'avatar-edit', memberName: 'card', description: 'Draws a trading card of random rarity based on a user\'s profile.', - guildOnly: true, throttling: { usages: 1, - duration: 30 + duration: 15 }, clientPermissions: ['ATTACH_FILES'], args: [ { - key: 'member', + key: 'user', prompt: 'Which user would you like to edit the avatar of?', - type: 'member', + type: 'user', default: '' } ] }); } - async run(msg, { member }) { - if (!member) member = msg.member; - const avatarURL = member.user.displayAvatarURL({ + async run(msg, { user }) { + if (!user) user = msg.author; + const avatarURL = user.displayAvatarURL({ format: 'png', size: 256 }); try { - const cardID = Math.floor(Math.random() * ((9999 - 1000) + 1)) + 1000; + const cardID = Math.floor(Math.random() * (9999 - 1000 + 1)) + 1000; let rarity; if (cardID < 5000) rarity = 'C'; - else if (cardID < 8000) rarity = 'U'; + else if (cardID < 9000) rarity = 'U'; else rarity = 'R'; const canvas = createCanvas(390, 544); const ctx = canvas.getContext('2d'); @@ -55,18 +54,16 @@ module.exports = class CardCommand extends Command { ctx.drawImage(base, 0, 0); ctx.font = '18px Noto'; ctx.fillStyle = 'black'; - ctx.fillText(member.displayName, 30, 62); + ctx.fillText(user.username, 30, 62); ctx.fillText('Discord Join Date:', 148, 400); - ctx.fillText(member.user.createdAt.toDateString(), 148, 420); - ctx.fillText('Role:', 148, 457); - ctx.fillText(member.highestRole.name !== '@everyone' ? member.highestRole.name : 'None', 148, 477); + ctx.fillText(user.createdAt.toDateString(), 148, 420); ctx.fillText(rarity, 73, 411); ctx.fillText(cardID, 60, 457); ctx.fillText(version.split('.')[0], 68, 502); ctx.font = '14px Noto'; - ctx.fillText(member.id, 30, 355); - ctx.fillText(`#${member.user.discriminator}`, 313, 355); - return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'card.png' }] }); + ctx.fillText(user.id, 30, 355); + ctx.fillText(`#${user.discriminator}`, 313, 355); + return msg.say({ files: [canvas.toBuffer()] }); } catch (err) { return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); } diff --git a/commands/avatar-edit/challenger.js b/commands/avatar-edit/challenger.js index bf5c6761..495c6c71 100644 --- a/commands/avatar-edit/challenger.js +++ b/commands/avatar-edit/challenger.js @@ -12,7 +12,7 @@ module.exports = class ChallengerCommand extends Command { description: 'Draws a user\'s avatar over Super Smash Bros.\'s "Challenger Approaching" screen.', throttling: { usages: 1, - duration: 30 + duration: 15 }, clientPermissions: ['ATTACH_FILES'], args: [ @@ -40,7 +40,7 @@ module.exports = class ChallengerCommand extends Command { const avatar = await loadImage(body); ctx.drawImage(base, 0, 0); ctx.drawImage(avatar, 484, 98, 256, 256); - return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'challenger.png' }] }); + return msg.say({ files: [canvas.toBuffer()] }); } catch (err) { return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); } diff --git a/commands/avatar-edit/dexter.js b/commands/avatar-edit/dexter.js index 84e6b462..670e2edc 100644 --- a/commands/avatar-edit/dexter.js +++ b/commands/avatar-edit/dexter.js @@ -12,7 +12,7 @@ module.exports = class DexterCommand extends Command { description: 'Draws a user\'s avatar over Dexter from Pokémon\'s screen.', throttling: { usages: 1, - duration: 30 + duration: 15 }, clientPermissions: ['ATTACH_FILES'], args: [ @@ -42,7 +42,7 @@ module.exports = class DexterCommand extends Command { ctx.rotate(-11 * (Math.PI / 180)); ctx.drawImage(avatar, 234, 274, 225, 225); ctx.rotate(11 * (Math.PI / 180)); - return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'dexter.png' }] }); + return msg.say({ files: [canvas.toBuffer()] }); } catch (err) { return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); } diff --git a/commands/avatar-edit/greyscale.js b/commands/avatar-edit/greyscale.js index d85aa30c..9df9d39f 100644 --- a/commands/avatar-edit/greyscale.js +++ b/commands/avatar-edit/greyscale.js @@ -12,7 +12,7 @@ module.exports = class GreyscaleCommand extends Command { description: 'Draws a user\'s avatar in greyscale.', throttling: { usages: 1, - duration: 30 + duration: 15 }, clientPermissions: ['ATTACH_FILES'], args: [ @@ -47,7 +47,7 @@ module.exports = class GreyscaleCommand extends Command { data[i + 2] = brightness; } ctx.putImageData(imgData, 0, 0); - return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'greyscale.png' }] }); + return msg.say({ files: [canvas.toBuffer()] }); } catch (err) { return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); } diff --git a/commands/avatar-edit/invert.js b/commands/avatar-edit/invert.js index 9d5be671..a2921258 100644 --- a/commands/avatar-edit/invert.js +++ b/commands/avatar-edit/invert.js @@ -11,7 +11,7 @@ module.exports = class InvertCommand extends Command { description: 'Draws a user\'s avatar inverted.', throttling: { usages: 1, - duration: 30 + duration: 15 }, clientPermissions: ['ATTACH_FILES'], args: [ @@ -45,7 +45,7 @@ module.exports = class InvertCommand extends Command { data[i + 2] = 255 - data[i + 2]; } ctx.putImageData(imgData, 0, 0); - return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'invert.png' }] }); + return msg.say({ files: [canvas.toBuffer()] }); } catch (err) { return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); } diff --git a/commands/avatar-edit/rainbow.js b/commands/avatar-edit/rainbow.js index 0fe9eac9..1cf4da60 100644 --- a/commands/avatar-edit/rainbow.js +++ b/commands/avatar-edit/rainbow.js @@ -13,7 +13,7 @@ module.exports = class RainbowCommand extends Command { description: 'Draws a rainbow over a user\'s avatar.', throttling: { usages: 1, - duration: 30 + duration: 15 }, clientPermissions: ['ATTACH_FILES'], args: [ @@ -41,7 +41,7 @@ module.exports = class RainbowCommand extends Command { const avatar = await loadImage(body); ctx.drawImage(avatar, 0, 0, 256, 256); ctx.drawImage(base, 0, 0, 256, 256); - return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'rainbow.png' }] }); + return msg.say({ files: [canvas.toBuffer()] }); } catch (err) { return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); } diff --git a/commands/avatar-edit/rejected.js b/commands/avatar-edit/rejected.js index c508f73e..98bbbe2a 100644 --- a/commands/avatar-edit/rejected.js +++ b/commands/avatar-edit/rejected.js @@ -13,7 +13,7 @@ module.exports = class RejctedCommand extends Command { description: 'Draws a "rejected" stamp over a user\'s avatar.', throttling: { usages: 1, - duration: 30 + duration: 15 }, clientPermissions: ['ATTACH_FILES'], args: [ @@ -41,7 +41,7 @@ module.exports = class RejctedCommand extends Command { const avatar = await loadImage(body); ctx.drawImage(avatar, 0, 0, 256, 256); ctx.drawImage(base, 0, 0, 256, 256); - return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'rejected.png' }] }); + return msg.say({ files: [canvas.toBuffer()] }); } catch (err) { return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); } diff --git a/commands/avatar-edit/rip.js b/commands/avatar-edit/rip.js index ea287983..a0a37bb8 100644 --- a/commands/avatar-edit/rip.js +++ b/commands/avatar-edit/rip.js @@ -13,7 +13,7 @@ module.exports = class RIPCommand extends Command { description: 'Draws a user\'s avatar over a gravestone.', throttling: { usages: 1, - duration: 30 + duration: 15 }, clientPermissions: ['ATTACH_FILES'], args: [ @@ -50,7 +50,7 @@ module.exports = class RIPCommand extends Command { data[i + 2] = brightness; } ctx.putImageData(imgData, 158, 51); - return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'rip.png' }] }); + return msg.say({ files: [canvas.toBuffer()] }); } catch (err) { return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); } diff --git a/commands/avatar-edit/simba.js b/commands/avatar-edit/simba.js index 50e22383..e637e889 100644 --- a/commands/avatar-edit/simba.js +++ b/commands/avatar-edit/simba.js @@ -12,7 +12,7 @@ module.exports = class SimbaCommand extends Command { description: 'Draws a user\'s avatar over Simba from The Lion King\'s reflection.', throttling: { usages: 1, - duration: 30 + duration: 15 }, clientPermissions: ['ATTACH_FILES'], args: [ @@ -42,7 +42,7 @@ module.exports = class SimbaCommand extends Command { ctx.rotate(-24 * (Math.PI / 180)); ctx.drawImage(avatar, 75, 160, 130, 150); ctx.rotate(24 * (Math.PI / 180)); - return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'simba.png' }] }); + return msg.say({ files: [canvas.toBuffer()] }); } catch (err) { return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); } diff --git a/commands/avatar-edit/steam-card.js b/commands/avatar-edit/steam-card.js index ac065e33..3afc2242 100644 --- a/commands/avatar-edit/steam-card.js +++ b/commands/avatar-edit/steam-card.js @@ -13,10 +13,9 @@ module.exports = class SteamCardCommand extends Command { group: 'avatar-edit', memberName: 'steam-card', description: 'Draws a user\'s avatar over a Steam Trading Card.', - guildOnly: true, throttling: { usages: 1, - duration: 30 + duration: 15 }, clientPermissions: ['ATTACH_FILES'], args: [ @@ -48,7 +47,7 @@ module.exports = class SteamCardCommand extends Command { ctx.drawImage(base, 0, 0); ctx.font = '30px Noto'; ctx.fillText(member.displayName, 35, 48); - return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'steam-card.png' }] }); + return msg.say({ files: [canvas.toBuffer()] }); } catch (err) { return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); } diff --git a/commands/avatar-edit/steam-now-playing.js b/commands/avatar-edit/steam-now-playing.js index 463cc61d..56b6cc73 100644 --- a/commands/avatar-edit/steam-now-playing.js +++ b/commands/avatar-edit/steam-now-playing.js @@ -17,7 +17,7 @@ module.exports = class SteamNowPlayingCommand extends Command { guildOnly: true, throttling: { usages: 1, - duration: 30 + duration: 15 }, clientPermissions: ['ATTACH_FILES'], args: [ @@ -57,7 +57,7 @@ module.exports = class SteamNowPlayingCommand extends Command { if (ctx.measureText(game).width > 160) shorten = true; while (ctx.measureText(game).width > 160) game = game.substr(0, game.length - 1); ctx.fillText(shorten ? `${game}...` : game, 63, 54); - return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'steam-now-playing.png' }] }); + return msg.say({ files: [canvas.toBuffer()] }); } catch (err) { return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); } diff --git a/commands/avatar-edit/thug-life.js b/commands/avatar-edit/thug-life.js index b7ad95c3..813761bd 100644 --- a/commands/avatar-edit/thug-life.js +++ b/commands/avatar-edit/thug-life.js @@ -12,7 +12,7 @@ module.exports = class ThugLifeCommand extends Command { description: 'Draws "Thug Life" over a user\'s avatar.', throttling: { usages: 1, - duration: 30 + duration: 15 }, clientPermissions: ['ATTACH_FILES'], args: [ @@ -49,7 +49,7 @@ module.exports = class ThugLifeCommand extends Command { data[i + 2] = brightness; } ctx.putImageData(imgData, 0, 0); - return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'thug-life.png' }] }); + return msg.say({ files: [canvas.toBuffer()] }); } catch (err) { return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); } diff --git a/commands/avatar-edit/triggered.js b/commands/avatar-edit/triggered.js index b505c244..86a24aca 100644 --- a/commands/avatar-edit/triggered.js +++ b/commands/avatar-edit/triggered.js @@ -12,7 +12,7 @@ module.exports = class TriggeredCommand extends Command { description: 'Draws a user\'s avatar over a Triggered meme.', throttling: { usages: 1, - duration: 30 + duration: 15 }, clientPermissions: ['ATTACH_FILES'], args: [ @@ -46,7 +46,7 @@ module.exports = class TriggeredCommand extends Command { for (let i = 0; i < data.length; i += 4) data[i] = Math.max(255, data[i]); ctx.putImageData(imgData, 0, 0); ctx.drawImage(base, 0, 0); - return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'triggered.png' }] }); + return msg.say({ files: [canvas.toBuffer()] }); } catch (err) { return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); } diff --git a/commands/avatar-edit/wanted.js b/commands/avatar-edit/wanted.js index 5b803b3b..b25db25c 100644 --- a/commands/avatar-edit/wanted.js +++ b/commands/avatar-edit/wanted.js @@ -12,7 +12,7 @@ module.exports = class WantedCommand extends Command { description: 'Draws a user\'s avatar over a wanted poster.', throttling: { usages: 1, - duration: 30 + duration: 15 }, clientPermissions: ['ATTACH_FILES'], args: [ @@ -40,7 +40,7 @@ module.exports = class WantedCommand extends Command { const avatar = await loadImage(body); ctx.drawImage(base, 0, 0); ctx.drawImage(avatar, 150, 360, 430, 430); - return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'wanted.png' }] }); + return msg.say({ files: [canvas.toBuffer()] }); } catch (err) { return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); } diff --git a/commands/avatar-edit/yu-gi-oh-token.js b/commands/avatar-edit/yu-gi-oh-token.js index f04f9a3a..b1ed40fe 100644 --- a/commands/avatar-edit/yu-gi-oh-token.js +++ b/commands/avatar-edit/yu-gi-oh-token.js @@ -12,7 +12,7 @@ module.exports = class YuGiOhTokenCommand extends Command { description: 'Draws a user\'s avatar over a blank Yu-Gi-Oh! Token card.', throttling: { usages: 1, - duration: 30 + duration: 15 }, clientPermissions: ['ATTACH_FILES'], args: [ @@ -40,7 +40,7 @@ module.exports = class YuGiOhTokenCommand extends Command { const avatar = await loadImage(body); ctx.drawImage(base, 0, 0); ctx.drawImage(avatar, 45, 102, 293, 294); - return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'yu-gi-oh-token.png' }] }); + return msg.say({ files: [canvas.toBuffer()] }); } catch (err) { return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); } diff --git a/commands/games/battle.js b/commands/games/battle.js index 5b4569da..032a0895 100644 --- a/commands/games/battle.js +++ b/commands/games/battle.js @@ -90,7 +90,7 @@ module.exports = class BattleCommand extends Command { } else if (choice === 'special') { const hit = Math.floor(Math.random() * 4) + 1; if (hit === 1) { - const damage = Math.floor(Math.random() * (((guard ? 300 : 150) - 100) + 1)) + 100; + const damage = Math.floor(Math.random() * ((guard ? 300 : 150) - 100 + 1)) + 100; await msg.say(`${user} deals **${damage}** damage!`); dealDamage(damage); reset(); diff --git a/commands/games/math-game.js b/commands/games/math-game.js index 17f000d5..f64d4db3 100644 --- a/commands/games/math-game.js +++ b/commands/games/math-game.js @@ -2,13 +2,7 @@ const Command = require('../../structures/Command'); const { stripIndents } = require('common-tags'); const { list } = require('../../structures/Util'); const difficulties = ['easy', 'medium', 'hard', 'extreme', 'impossible']; -const operations = ['addition', 'subtraction', 'multiplication', 'division']; -const operationDisplay = { - addition: '+', - subtraction: '-', - multiplication: '*', - division: '÷' -}; +const operations = ['+', '-', '*']; const maxValues = { easy: 10, medium: 100, @@ -26,16 +20,6 @@ module.exports = class MathGameCommand extends Command { description: 'See how fast you can answer a math problem in a given time limit.', clientPermissions: ['EMBED_LINKS'], args: [ - { - key: 'operation', - prompt: `Which operation should be used for the game? Either ${list(operations, 'or')}.`, - type: 'string', - validate: operation => { - if (operations.includes(operation.toLowerCase())) return true; - return `Invalid operation, please enter either ${list(operations, 'or')}.`; - }, - parse: operation => operation.toLowerCase() - }, { key: 'difficulty', prompt: `What should the difficulty of the game be? Either ${list(difficulties, 'or')}.`, @@ -50,17 +34,25 @@ module.exports = class MathGameCommand extends Command { }); } - async run(msg, { operation, difficulty }) { + async run(msg, { difficulty }) { const value1 = Math.floor(Math.random() * maxValues[difficulty]) + 1; const value2 = Math.floor(Math.random() * maxValues[difficulty]) + 1; + const operation = operations[Math.floor(Math.random() * operations.length)]; let answer; - if (operation === 'addition') answer = value1 + value2; - else if (operation === 'subtraction') answer = value1 - value2; - else if (operation === 'multiplication') answer = value1 * value2; - else if (operation === 'division') answer = value1 / value2; + switch (operation) { + case '+': + answer = value1 + value2; + break; + case '-': + answer = value1 - value2; + break; + case '*': + answer = value1 * value2; + break; + } await msg.say(stripIndents` **You have 10 seconds to answer this question.** - ${value1} ${operationDisplay[operation]} ${value2} + ${value1} ${operation} ${value2} `); const msgs = await msg.channel.awaitMessages(res => res.author.id === msg.author.id, { max: 1, diff --git a/commands/games/tic-tac-toe.js b/commands/games/tic-tac-toe.js index e5054ae2..d5357412 100644 --- a/commands/games/tic-tac-toe.js +++ b/commands/games/tic-tac-toe.js @@ -12,8 +12,7 @@ module.exports = class TicTacToeCommand extends Command { { key: 'opponent', prompt: 'What user would you like to challenge?', - type: 'user', - default: '' + type: 'user' } ] }); @@ -22,21 +21,19 @@ module.exports = class TicTacToeCommand extends Command { } async run(msg, { opponent }) { // eslint-disable-line complexity - if (!opponent) opponent = this.client.user; + if (opponent.bot) return msg.say('Bots may not be played against.'); if (opponent.id === msg.author.id) return msg.say('You may not play against yourself.'); if (this.playing.has(msg.channel.id)) return msg.say('Only one game may be occurring per channel.'); this.playing.add(msg.channel.id); try { - if (!opponent.bot) { - await msg.say(`${opponent}, do you accept this challenge?`); - const verify = await msg.channel.awaitMessages(res => res.author.id === opponent.id, { - max: 1, - time: 30000 - }); - if (!verify.size || !['yes', 'y'].includes(verify.first().content.toLowerCase())) { - this.playing.delete(msg.channel.id); - return msg.say('Looks like they declined...'); - } + await msg.say(`${opponent}, do you accept this challenge?`); + const verify = await msg.channel.awaitMessages(res => res.author.id === opponent.id, { + max: 1, + time: 30000 + }); + if (!verify.size || !['yes', 'y'].includes(verify.first().content.toLowerCase())) { + this.playing.delete(msg.channel.id); + return msg.say('Looks like they declined...'); } const sides = ['0', '1', '2', '3', '4', '5', '6', '7', '8']; const taken = []; @@ -45,29 +42,23 @@ module.exports = class TicTacToeCommand extends Command { while (!winner && taken.length < 9) { const user = userTurn ? msg.author : opponent; const sign = userTurn ? 'X' : 'O'; - let choice; - if (!opponent.bot || (opponent.bot && userTurn)) { - await msg.code(null, stripIndents` - ${sides[0]} | ${sides[1]} | ${sides[2]} - ————————— - ${sides[3]} | ${sides[4]} | ${sides[5]} - ————————— - ${sides[6]} | ${sides[7]} | ${sides[8]} - `); - await msg.say(`${user}, which side do you pick?`); - const turn = await msg.channel.awaitMessages(res => res.author.id === user.id, { - max: 1, - time: 30000 - }); - if (!turn.size) { - await msg.say('Time!'); - break; - } - choice = turn.first().content; - } else { - const filter = sides.filter(side => !['X', 'O'].includes(side)); - choice = filter[Math.floor(Math.random() * filter.length)]; + await msg.code(null, stripIndents` + ${sides[0]} | ${sides[1]} | ${sides[2]} + ————————— + ${sides[3]} | ${sides[4]} | ${sides[5]} + ————————— + ${sides[6]} | ${sides[7]} | ${sides[8]} + `); + await msg.say(`${user}, which side do you pick?`); + const turn = await msg.channel.awaitMessages(res => res.author.id === user.id, { + max: 1, + time: 30000 + }); + if (!turn.size) { + await msg.say('Time!'); + break; } + const choice = turn.first().content; if (taken.includes(choice)) { await msg.say('That spot is already taken!'); } else if (!sides.includes(choice)) { diff --git a/commands/games/typing-game.js b/commands/games/typing-game.js index 6bd6e06a..cc984585 100644 --- a/commands/games/typing-game.js +++ b/commands/games/typing-game.js @@ -1,6 +1,7 @@ const Command = require('../../structures/Command'); const { stripIndents } = require('common-tags'); const { list } = require('../../structures/Util'); +const sentences = require('../../assets/json/typing-game'); const difficulties = ['easy', 'medium', 'hard', 'extreme', 'impossible']; const times = { easy: 25000, @@ -9,7 +10,6 @@ const times = { extreme: 10000, impossible: 5000 }; -const sentences = require('../../assets/json/typing-game'); module.exports = class TypingGameCommand extends Command { constructor(client) { diff --git a/commands/guild-info/emoji.js b/commands/guild-info/emoji.js index c8eb39c6..1e10abe2 100644 --- a/commands/guild-info/emoji.js +++ b/commands/guild-info/emoji.js @@ -13,6 +13,6 @@ module.exports = class EmojiCommand extends Command { run(msg) { if (!msg.guild.emojis.size) return msg.say('This server has no custom emoji.'); - return msg.say(msg.guild.emojis.map(e => e).join('')); + return msg.say(msg.guild.emojis.map(emoji => emoji.toString()).join('')); } }; diff --git a/commands/guild-info/server-info.js b/commands/guild-info/server-info.js index 7a87fefb..fb0c66ca 100644 --- a/commands/guild-info/server-info.js +++ b/commands/guild-info/server-info.js @@ -33,7 +33,7 @@ module.exports = class GuildInfoCommand extends Command { .addField('❯ Verification Level', verificationLevels[msg.guild.verificationLevel], true) .addField('❯ Owner', - msg.guild.owner ? msg.guild.owner.user.username : 'None', true) + msg.guild.owner ? msg.guild.owner.user.tag : 'None', true) .addField('❯ Members', msg.guild.memberCount, true); return msg.embed(embed); diff --git a/commands/image-edit/achievement.js b/commands/image-edit/achievement.js index d7eacb7a..8b95c1fa 100644 --- a/commands/image-edit/achievement.js +++ b/commands/image-edit/achievement.js @@ -32,7 +32,7 @@ module.exports = class AchievementCommand extends Command { h: 'Achievement Get!', t: text }); - return msg.say({ files: [{ attachment: body, name: 'achievement.png' }] }); + return msg.say({ files: [body] }); } catch (err) { return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); } diff --git a/commands/image-edit/color.js b/commands/image-edit/color.js index 698f6d2e..2aca5d5d 100644 --- a/commands/image-edit/color.js +++ b/commands/image-edit/color.js @@ -5,6 +5,7 @@ module.exports = class ColorCommand extends Command { constructor(client) { super(client, { name: 'color', + aliases: ['colour'], group: 'image-edit', memberName: 'color', description: 'Sends an image of the color you choose.', @@ -12,7 +13,7 @@ module.exports = class ColorCommand extends Command { args: [ { key: 'color', - prompt: 'What color do you want to view? This can be HTML (#colorcode) or a name.', + prompt: 'What color do you want to view? This can be #colorcode or a name.', type: 'string', parse: color => color.toLowerCase() } @@ -25,6 +26,6 @@ module.exports = class ColorCommand extends Command { const ctx = canvas.getContext('2d'); ctx.fillStyle = color; ctx.fillRect(0, 0, 250, 250); - return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'color.png' }] }); + return msg.say({ files: [canvas.toBuffer()] }); } }; diff --git a/commands/moderation/unban.js b/commands/moderation/unban.js index 68727298..ee6c80a7 100644 --- a/commands/moderation/unban.js +++ b/commands/moderation/unban.js @@ -32,7 +32,7 @@ module.exports = class UnbanCommand extends Command { async run(msg, { id, reason }) { const bans = await msg.guild.fetchBans(); - if (!bans.has(id)) return msg.say('This ID is not in the Guild Banlist.'); + if (!bans.has(id)) return msg.say('This ID is not in the server banlist.'); const member = bans.get(id).user; await msg.say(`Are you sure you want to unban ${member.tag} (${member.id})?`); const msgs = await msg.channel.awaitMessages(res => res.author.id === msg.author.id, { diff --git a/commands/random-res/fortune.js b/commands/random-res/fortune.js index cff2bc12..635d5a34 100644 --- a/commands/random-res/fortune.js +++ b/commands/random-res/fortune.js @@ -18,10 +18,11 @@ module.exports = class FortuneCommand extends Command { const { body } = await snekfetch .get('http://fortunecookieapi.herokuapp.com/v1/cookie') .query({ limit: 1 }); + const data = body[0]; return msg.say(stripIndents` - ${body[0].fortune.message} - ${body[0].lotto.numbers.join(', ')} - ${body[0].lesson.chinese} (${body[0].lesson.pronunciation}): ${body[0].lesson.english} + ${data.fortune.message} + ${data.lotto.numbers.join(', ')} + ${data.lesson.chinese} (${data.lesson.pronunciation}): ${data.lesson.english} `); } catch (err) { return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); diff --git a/commands/random-res/ship.js b/commands/random-res/ship.js index 5e5b2834..7f3309c4 100644 --- a/commands/random-res/ship.js +++ b/commands/random-res/ship.js @@ -5,6 +5,7 @@ module.exports = class ShipCommand extends Command { constructor(client) { super(client, { name: 'ship', + aliases: ['rate'], group: 'random-res', memberName: 'ship', description: 'Ships things/people together.', diff --git a/commands/random/horoscope.js b/commands/random/horoscope.js index d2310699..02e80931 100644 --- a/commands/random/horoscope.js +++ b/commands/random/horoscope.js @@ -2,20 +2,7 @@ const Command = require('../../structures/Command'); const { MessageEmbed } = require('discord.js'); const snekfetch = require('snekfetch'); const { list } = require('../../structures/Util'); -const signs = [ - 'capricorn', - 'aquarius', - 'pisces', - 'aries', - 'taurus', - 'gemini', - 'cancer', - 'leo', - 'virgo', - 'libra', - 'scorpio', - 'sagittarius' -]; +const signs = require('../../assets/json/horoscope'); module.exports = class HoroscopeCommand extends Command { constructor(client) { diff --git a/commands/random/soundboard.js b/commands/random/soundboard.js index 2c58a20e..7cac4ca4 100644 --- a/commands/random/soundboard.js +++ b/commands/random/soundboard.js @@ -15,7 +15,7 @@ module.exports = class SoundboardCommand extends Command { guildOnly: true, throttling: { usages: 1, - duration: 30 + duration: 15 }, args: [ { diff --git a/commands/search/anime.js b/commands/search/anime.js index 4ddb344d..ce2eb05d 100644 --- a/commands/search/anime.js +++ b/commands/search/anime.js @@ -29,21 +29,22 @@ module.exports = class AnimeCommand extends Command { .query({ 'filter[text]': query }); const body = JSON.parse(text); if (!body.meta.count) return msg.say('Could not find any results.'); + const data = body.data[0].attributes; const embed = new MessageEmbed() .setColor(0xF75239) .setAuthor('Kitsu.io', 'https://i.imgur.com/VnIpwgF.png') - .setURL(`https://kitsu.io/anime/${body.data[0].attributes.slug}`) - .setThumbnail(body.data[0].attributes.posterImage ? body.data[0].attributes.posterImage.original : null) - .setTitle(body.data[0].attributes.canonicalTitle) - .setDescription(shorten(body.data[0].attributes.synopsis)) + .setURL(`https://kitsu.io/anime/${data.slug}`) + .setThumbnail(data.posterImage ? data.posterImage.original : null) + .setTitle(data.canonicalTitle) + .setDescription(shorten(data.synopsis)) .addField('❯ Type', - `${body.data[0].attributes.showType} - ${body.data[0].attributes.status}`, true) + `${data.showType} - ${data.status}`, true) .addField('❯ Episodes', - body.data[0].attributes.episodeCount || 'N/A', true) + data.episodeCount || 'N/A', true) .addField('❯ Start Date', - body.data[0].attributes.startDate ? new Date(body.data[0].attributes.startDate).toDateString() : 'N/A', true) + data.startDate ? new Date(data.startDate).toDateString() : 'N/A', true) .addField('❯ End Date', - body.data[0].attributes.endDate ? new Date(body.data[0].attributes.endDate).toDateString() : 'N/A', true); + data.endDate ? new Date(data.endDate).toDateString() : 'N/A', true); return msg.embed(embed); } catch (err) { return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); diff --git a/commands/search/bulbapedia.js b/commands/search/bulbapedia.js index 49cefc9c..246a62f7 100644 --- a/commands/search/bulbapedia.js +++ b/commands/search/bulbapedia.js @@ -37,13 +37,14 @@ module.exports = class BulbapediaCommand extends Command { redirects: '', formatversion: 2 }); - if (body.query.pages[0].missing) return msg.say('Could not find any results.'); + const data = body.query.pages[0]; + if (data.missing) return msg.say('Could not find any results.'); const embed = new MessageEmbed() .setColor(0x3E7614) - .setTitle(body.query.pages[0].title) + .setTitle(data.title) .setAuthor('Bulbapedia', 'https://i.imgur.com/09eYo5T.png') - .setThumbnail(body.query.pages[0].thumbnail ? body.query.pages[0].thumbnail.source : null) - .setDescription(shorten(body.query.pages[0].extract.replace(/\n/g, '\n\n'))); + .setThumbnail(data.thumbnail ? data.thumbnail.source : null) + .setDescription(shorten(data.extract.replace(/\n/g, '\n\n'))); return msg.embed(embed); } catch (err) { return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); diff --git a/commands/search/define.js b/commands/search/define.js index 208b1f1f..8ed98527 100644 --- a/commands/search/define.js +++ b/commands/search/define.js @@ -33,10 +33,11 @@ module.exports = class DefineCommand extends Command { api_key: WORDNIK_KEY }); if (!body.length) return msg.say('Could not find any results.'); + const data = body[0]; const embed = new MessageEmbed() .setColor(0x9797FF) - .setTitle(body[0].word) - .setDescription(body[0].text); + .setTitle(data.word) + .setDescription(data.text); return msg.embed(embed); } catch (err) { return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); diff --git a/commands/search/itunes.js b/commands/search/itunes.js index 0185070b..cb9a0439 100644 --- a/commands/search/itunes.js +++ b/commands/search/itunes.js @@ -47,20 +47,21 @@ module.exports = class iTunesCommand extends Command { }); const body = JSON.parse(text); if (!body.resultCount) return msg.say('Could not find any results.'); + const data = body.results[0]; const embed = new MessageEmbed() .setColor(0xFEFEFE) .setAuthor('iTunes', 'https://i.imgur.com/TbqzJFs.jpg') - .setURL(body.results[0].trackViewUrl) - .setThumbnail(body.results[0].artworkUrl100) - .setTitle(body.results[0].trackName) + .setURL(data.trackViewUrl) + .setThumbnail(data.artworkUrl100) + .setTitle(data.trackName) .addField('❯ Artist', - body.results[0].artistName, true) + data.artistName, true) .addField('❯ Album', - body.results[0].collectionName, true) + data.collectionName, true) .addField('❯ Release Date', - new Date(body.results[0].releaseDate).toDateString(), true) + new Date(data.releaseDate).toDateString(), true) .addField('❯ Genre', - body.results[0].primaryGenreName, true); + data.primaryGenreName, true); return msg.embed(embed); } catch (err) { return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); diff --git a/commands/search/kickstarter.js b/commands/search/kickstarter.js index c2559dde..7521f8be 100644 --- a/commands/search/kickstarter.js +++ b/commands/search/kickstarter.js @@ -29,21 +29,22 @@ module.exports = class KickstarterCommand extends Command { term: query }); if (!body.projects.length) return msg.say('Could not find any results.'); + const data = body.projects[0]; const embed = new MessageEmbed() .setColor(0x14E06E) - .setTitle(body.projects[0].name) - .setURL(body.projects[0].urls.web.project) + .setTitle(data.name) + .setURL(data.urls.web.project) .setAuthor('Kickstarter', 'https://i.imgur.com/7mJF4qJ.png') - .setDescription(body.projects[0].blurb) - .setThumbnail(body.projects[0].photo ? body.projects[0].photo.full : null) + .setDescription(data.blurb) + .setThumbnail(data.photo ? data.photo.full : null) .addField('❯ Goal', - `${body.projects[0].currency_symbol}${body.projects[0].goal.toLocaleString()}`, true) + `${data.currency_symbol}${data.goal.toLocaleString()}`, true) .addField('❯ Pledged', - `${body.projects[0].currency_symbol}${body.projects[0].pledged.toLocaleString()}`, true) + `${data.currency_symbol}${data.pledged.toLocaleString()}`, true) .addField('❯ Backers', - body.projects[0].backers_count, true) + data.backers_count, true) .addField('❯ Creator', - body.projects[0].creator.name, true); + data.creator.name, true); return msg.embed(embed); } catch (err) { return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); diff --git a/commands/search/manga.js b/commands/search/manga.js index 441bd2b9..85e1e16b 100644 --- a/commands/search/manga.js +++ b/commands/search/manga.js @@ -29,21 +29,22 @@ module.exports = class MangaCommand extends Command { .query({ 'filter[text]': query }); const body = JSON.parse(text); if (!body.meta.count) return msg.say('Could not find any results.'); + const data = body.data[0].attributes; const embed = new MessageEmbed() .setColor(0xF75239) .setAuthor('Kitsu.io', 'https://i.imgur.com/VnIpwgF.png') - .setURL(`https://kitsu.io/manga/${body.data[0].attributes.slug}`) - .setThumbnail(body.data[0].attributes.posterImage ? body.data[0].attributes.posterImage.original : null) - .setTitle(body.data[0].attributes.canonicalTitle) - .setDescription(shorten(body.data[0].attributes.synopsis)) + .setURL(`https://kitsu.io/manga/${data.slug}`) + .setThumbnail(data.posterImage ? data.posterImage.original : null) + .setTitle(data.canonicalTitle) + .setDescription(shorten(data.synopsis)) .addField('❯ Type', - `${body.data[0].attributes.subtype} - ${body.data[0].attributes.status}`, true) + `${data.subtype} - ${data.status}`, true) .addField('❯ Volumes / Chapters', - `${body.data[0].attributes.volumeCount || 'N/A'} / ${body.data[0].attributes.chapterCount || 'N/A'}`, true) + `${data.volumeCount || 'N/A'} / ${data.chapterCount || 'N/A'}`, true) .addField('❯ Start Date', - body.data[0].attributes.startDate ? new Date(body.data[0].attributes.startDate).toDateString() : 'N/A', true) + data.startDate ? new Date(data.startDate).toDateString() : 'N/A', true) .addField('❯ End Date', - body.data[0].attributes.endDate ? new Date(body.data[0].attributes.endDate).toDateString() : 'N/A', true); + data.endDate ? new Date(data.endDate).toDateString() : 'N/A', true); return msg.embed(embed); } catch (err) { return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); diff --git a/commands/search/map.js b/commands/search/map.js index 420eab39..687f8918 100644 --- a/commands/search/map.js +++ b/commands/search/map.js @@ -40,7 +40,7 @@ module.exports = class MapCommand extends Command { size: '500x500', key: GOOGLE_KEY }); - return msg.say({ files: [{ attachment: body, name: 'map.png' }] }); + return msg.say({ files: [body] }); } catch (err) { return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); } diff --git a/commands/search/mdn.js b/commands/search/mdn.js index e4afe5a2..af912c4b 100644 --- a/commands/search/mdn.js +++ b/commands/search/mdn.js @@ -27,12 +27,13 @@ module.exports = class MDNCommand extends Command { .get('https://developer.mozilla.org/en-US/search.json') .query({ q: query }); if (!body.documents.length) return msg.say('Could not find any results.'); + const data = body.documents[0]; const embed = new MessageEmbed() .setColor(0x066FAD) .setAuthor('MDN', 'https://i.imgur.com/ClMfs9l.png') - .setURL(body.documents[0].url) - .setTitle(body.documents[0].title) - .setDescription(body.documents[0].excerpt); + .setURL(data.url) + .setTitle(data.title) + .setDescription(data.excerpt); return msg.embed(embed); } catch (err) { return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); diff --git a/commands/search/osu.js b/commands/search/osu.js index 547264c9..8a749cac 100644 --- a/commands/search/osu.js +++ b/commands/search/osu.js @@ -32,34 +32,35 @@ module.exports = class OsuCommand extends Command { type: 'string' }); if (!body.length) return msg.say('Could not find any results.'); + const data = body[0]; const embed = new MessageEmbed() .setColor(0xFF66AA) .setAuthor('osu!', 'https://i.imgur.com/EmnUp00.png') .setURL('https://osu.ppy.sh/') .addField('❯ Username', - body[0].username, true) + data.username, true) .addField('❯ ID', - body[0].user_id, true) + data.user_id, true) .addField('❯ Level', - body[0].level || 'N/A', true) + data.level || 'N/A', true) .addField('❯ Accuracy', - body[0].accuracy || 'N/A', true) + data.accuracy || 'N/A', true) .addField('❯ Rank', - body[0].pp_rank || 'N/A', true) + data.pp_rank || 'N/A', true) .addField('❯ Play Count', - body[0].playcount || 'N/A', true) + data.playcount || 'N/A', true) .addField('❯ Country', - body[0].country || 'N/A', true) + data.country || 'N/A', true) .addField('❯ Ranked Score', - body[0].ranked_score || 'N/A', true) + data.ranked_score || 'N/A', true) .addField('❯ Total Score', - body[0].total_score || 'N/A', true) + data.total_score || 'N/A', true) .addField('❯ SS', - body[0].count_rank_ss || 'N/A', true) + data.count_rank_ss || 'N/A', true) .addField('❯ S', - body[0].count_rank_s || 'N/A', true) + data.count_rank_s || 'N/A', true) .addField('❯ A', - body[0].count_rank_a || 'N/A', true); + data.count_rank_a || 'N/A', true); return msg.embed(embed); } catch (err) { return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); diff --git a/commands/search/steam.js b/commands/search/steam.js index 336b2337..a6c4db26 100644 --- a/commands/search/steam.js +++ b/commands/search/steam.js @@ -30,19 +30,20 @@ module.exports = class SteamCommand extends Command { term: query }); if (!body.total) return msg.say('Could not find any results.'); - const current = body.items[0].price ? body.items[0].price.final / 100 : 0.00; - const original = body.items[0].price ? body.items[0].price.initial / 100 : 0.00; + const data = body.items[0]; + const current = data.price ? data.price.final / 100 : 0.00; + const original = data.price ? data.price.initial / 100 : 0.00; const price = current === original ? `$${current}` : `~~$${original}~~ $${current}`; const embed = new MessageEmbed() .setColor(0x101D2F) .setAuthor('Steam', 'https://i.imgur.com/vL8b4D5.png') - .setTitle(body.items[0].name) - .setURL(`http://store.steampowered.com/app/${body.items[0].id}`) - .setImage(body.items[0].tiny_image) + .setTitle(data.name) + .setURL(`http://store.steampowered.com/app/${data.id}`) + .setImage(data.tiny_image) .addField('❯ Price', price, true) .addField('❯ Metascore', - body.items[0].metascore || 'N/A', true); + data.metascore || 'N/A', true); return msg.embed(embed); } catch (err) { return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); diff --git a/commands/search/urban.js b/commands/search/urban.js index d66cc142..ed838325 100644 --- a/commands/search/urban.js +++ b/commands/search/urban.js @@ -27,14 +27,15 @@ module.exports = class UrbanCommand extends Command { .get('http://api.urbandictionary.com/v0/define') .query({ term: query }); if (!body.list.length) return msg.say('Could not find any results.'); + const data = body.list[0]; const embed = new MessageEmbed() .setColor(0x32A8F0) .setAuthor('Urban Dictionary', 'https://i.imgur.com/fzFuuL7.png') - .setURL(body.list[0].permalink) - .setTitle(body.list[0].word) - .setDescription(shorten(body.list[0].definition)) + .setURL(data.permalink) + .setTitle(data.word) + .setDescription(shorten(data.definition)) .addField('❯ Example', - shorten(body.list[0].example, 1000) || 'None'); + shorten(data.example, 1000) || 'None'); return msg.embed(embed); } catch (err) { return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); diff --git a/commands/search/vocaloid.js b/commands/search/vocaloid.js index 3fc8386d..f22ecf3b 100644 --- a/commands/search/vocaloid.js +++ b/commands/search/vocaloid.js @@ -35,18 +35,19 @@ module.exports = class VocaloidCommand extends Command { fields: 'ThumbUrl,Lyrics' }); if (!body.totalCount) return msg.say('Could not find any results.'); - const { minutes, seconds } = duration(body.items[0].lengthSeconds * 1000); + const data = body.items[0]; + const { minutes, seconds } = duration(data.lengthSeconds * 1000); const embed = new MessageEmbed() .setColor(0x86D2D0) .setAuthor('VocaDB', 'https://i.imgur.com/9Tx9UIc.jpg') - .setTitle(body.items[0].name) - .setURL(`http://vocadb.net/S/${body.items[0].id}`) - .setDescription(body.items[0].lyrics.length ? shorten(body.items[0].lyrics[0].value) : 'N/A') - .setThumbnail(body.items[0].thumbUrl) + .setTitle(data.name) + .setURL(`http://vocadb.net/S/${data.id}`) + .setDescription(data.lyrics.length ? shorten(data.lyrics[0].value) : 'N/A') + .setThumbnail(data.thumbUrl) .addField('❯ Artist', - body.items[0].artistString) + data.artistString) .addField('❯ Publish Date', - new Date(body.items[0].publishDate).toDateString(), true) + new Date(data.publishDate).toDateString(), true) .addField('❯ Length', `${minutes}:${seconds}`, true); return msg.embed(embed); diff --git a/commands/search/wattpad.js b/commands/search/wattpad.js index a7c12c9d..aa784a89 100644 --- a/commands/search/wattpad.js +++ b/commands/search/wattpad.js @@ -32,25 +32,26 @@ module.exports = class WattpadCommand extends Command { }) .set({ Authorization: `Basic ${WATTPAD_KEY}` }); if (!body.stories.length) return msg.say('Could not find any results.'); + const data = body.stories[0]; const embed = new MessageEmbed() .setColor(0xF89C34) .setAuthor('Wattpad', 'https://i.imgur.com/Rw9vRQB.png') - .setURL(body.stories[0].url) - .setTitle(body.stories[0].title) - .setDescription(shorten(body.stories[0].description)) - .setThumbnail(body.stories[0].cover) + .setURL(data.url) + .setTitle(data.title) + .setDescription(shorten(data.description)) + .setThumbnail(data.cover) .addField('❯ Created On', - new Date(body.stories[0].createDate).toDateString(), true) + new Date(data.createDate).toDateString(), true) .addField('❯ Author', - body.stories[0].user, true) + data.user, true) .addField('❯ Parts', - body.stories[0].numParts, true) + data.numParts, true) .addField('❯ Reads', - body.stories[0].readCount, true) + data.readCount, true) .addField('❯ Votes', - body.stories[0].voteCount, true) + data.voteCount, true) .addField('❯ Comments', - body.stories[0].commentCount, true); + data.commentCount, true); return msg.embed(embed); } catch (err) { return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); diff --git a/commands/search/wikia.js b/commands/search/wikia.js index 6468465e..8ebb82a2 100644 --- a/commands/search/wikia.js +++ b/commands/search/wikia.js @@ -40,13 +40,14 @@ module.exports = class WikiaCommand extends Command { const { body } = await snekfetch .get(`http://${wiki}.wikia.com/api/v1/Articles/AsSimpleJson/`) .query({ id: search.body.items[0].id }); + const data = body.sections[0]; const embed = new MessageEmbed() .setColor(0x002D54) - .setTitle(body.sections[0].title) + .setTitle(data.title) .setURL(search.body.items[0].url) .setAuthor('Wikia', 'https://i.imgur.com/WzXWJka.png') - .setDescription(shorten(body.sections[0].content.map(section => section.text).join('\n\n'))) - .setThumbnail(body.sections[0].images.length ? body.sections[0].images[0].src : null); + .setDescription(shorten(data.content.map(section => section.text).join('\n\n'))) + .setThumbnail(data.images.length ? data.images[0].src : null); return msg.embed(embed); } catch (err) { return msg.say('Could not find any results.'); diff --git a/commands/search/wikipedia.js b/commands/search/wikipedia.js index 2fa70c63..cd92311c 100644 --- a/commands/search/wikipedia.js +++ b/commands/search/wikipedia.js @@ -36,13 +36,14 @@ module.exports = class WikipediaCommand extends Command { redirects: '', formatversion: 2 }); - if (body.query.pages[0].missing) return msg.say('Could not find any results.'); + const data = body.query.pages[0]; + if (data.missing) return msg.say('Could not find any results.'); const embed = new MessageEmbed() .setColor(0xE7E7E7) - .setTitle(body.query.pages[0].title) + .setTitle(data.title) .setAuthor('Wikipedia', 'https://i.imgur.com/a4eeEhh.png') - .setThumbnail(body.query.pages[0].thumbnail ? body.query.pages[0].thumbnail.source : null) - .setDescription(shorten(body.query.pages[0].extract.replace(/\n/g, '\n\n'))); + .setThumbnail(data.thumbnail ? data.thumbnail.source : null) + .setDescription(shorten(data.extract.replace(/\n/g, '\n\n'))); return msg.embed(embed); } catch (err) { return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); diff --git a/commands/search/youtube.js b/commands/search/youtube.js index b77dda0e..3b124d67 100644 --- a/commands/search/youtube.js +++ b/commands/search/youtube.js @@ -33,13 +33,14 @@ module.exports = class YouTubeCommand extends Command { key: GOOGLE_KEY }); if (!body.items.length) return msg.say('Could not find any results.'); + const data = body.items[0]; const embed = new MessageEmbed() .setColor(0xDD2825) - .setTitle(body.items[0].snippet.title) - .setDescription(body.items[0].snippet.description) - .setAuthor(`YouTube - ${body.items[0].snippet.channelTitle}`, 'https://i.imgur.com/hkUafwu.png') - .setURL(`https://www.youtube.com/watch?v=${body.items[0].id.videoId}`) - .setThumbnail(body.items[0].snippet.thumbnails.default.url); + .setTitle(data.snippet.title) + .setDescription(data.snippet.description) + .setAuthor(`YouTube - ${data.snippet.channelTitle}`, 'https://i.imgur.com/hkUafwu.png') + .setURL(`https://www.youtube.com/watch?v=${data.id.videoId}`) + .setThumbnail(data.snippet.thumbnails.default.url); return msg.embed(embed); } catch (err) { return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); diff --git a/commands/search/yu-gi-oh.js b/commands/search/yu-gi-oh.js index 281f151b..f5ecc003 100644 --- a/commands/search/yu-gi-oh.js +++ b/commands/search/yu-gi-oh.js @@ -28,26 +28,27 @@ module.exports = class YuGiOhCommand extends Command { if (body.status === 'fail') return msg.say('Could not find any results.'); const image = await snekfetch .get(`http://yugiohprices.com/api/card_image/${query}`); + const { data } = body; const embed = new MessageEmbed() .setColor(0xBE5F1F) - .setTitle(body.data.name) - .setDescription(body.data.text) + .setTitle(data.name) + .setDescription(data.text) .setAuthor('Yu-Gi-Oh!', 'https://i.imgur.com/7gPm9Rr.png') .setThumbnail(image.headers.location) .addField('❯ Card Type', - body.data.card_type, true); - if (body.data.card_type === 'monster') { + data.card_type, true); + if (data.card_type === 'monster') { embed .addField('❯ Type', - body.data.type, true) + data.type, true) .addField('❯ Attribute', - body.data.family, true) + data.family, true) .addField('❯ Level', - body.data.level, true) + data.level, true) .addField('❯ ATK', - body.data.atk, true) + data.atk, true) .addField('❯ DEF', - body.data.def, true); + data.def, true); } return msg.embed(embed); } catch (err) { diff --git a/commands/text-edit/embed.js b/commands/text-edit/embed.js index 5ecf7d2b..429baeae 100644 --- a/commands/text-edit/embed.js +++ b/commands/text-edit/embed.js @@ -21,7 +21,7 @@ module.exports = class EmbedCommand extends Command { run(msg, { text }) { const embed = new MessageEmbed() - .setAuthor(msg.author.tag, msg.author.displayAvatarURL) + .setAuthor(msg.author.tag, msg.author.displayAvatarURL()) .setColor(0x00AE86) .setTimestamp() .setDescription(text); diff --git a/package.json b/package.json index 014552d9..93260af8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiaobot", - "version": "40.6.0", + "version": "41.0.0", "description": "Your personal server companion.", "main": "Shard.js", "scripts": { diff --git a/structures/Util.js b/structures/Util.js index db3032f4..7c44b859 100644 --- a/structures/Util.js +++ b/structures/Util.js @@ -8,13 +8,11 @@ class Util { .post(`https://bots.discord.pw/api/bots/${id}/stats`) .set({ Authorization: DBOTS_KEY }) .send({ server_count: count }) - .then(() => console.log('[DBOTS] Successfully posted to Discord Bots.')) .catch(err => console.error(`[DBOTS] Failed to post to Discord Bots. ${err}`)); snekfetch .post(`https://discordbots.org/api/bots/${id}/stats`) .set({ Authorization: DBOTSORG_KEY }) .send({ server_count: count }) - .then(() => console.log('[DBOTSORG] Successfully posted to Discord Bots Org.')) .catch(err => console.error(`[DBOTSORG] Failed to post to Discord Bots Org. ${err}`)); } @@ -34,8 +32,8 @@ class Util { } static list(arr, conj = 'and') { - const { length } = arr; - return `${arr.slice(0, -1).join(', ')}${length > 1 ? `${length > 2 ? ',' : ''} ${conj} ` : ''}${arr.slice(-1)}`; + const len = arr.length; + return `${arr.slice(0, -1).join(', ')}${len > 1 ? `${len > 2 ? ',' : ''} ${conj} ` : ''}${arr.slice(-1)}`; } static shorten(text, maxLen = 2000) {