From 2ee1f3e59413a8ac909478f3fbd98eed9f0c0af9 Mon Sep 17 00:00:00 2001 From: Daniel Odendahl Jr Date: Wed, 3 May 2017 01:19:44 +0000 Subject: [PATCH] stripIndents --- commands/games/mathgame.js | 17 +++++++++-------- commands/games/quiz.js | 17 +++++++++-------- commands/games/slots.js | 17 +++++++++-------- commands/guildinfo/guildinfo.js | 7 +++++-- commands/moderation/ban.js | 17 +++++++++-------- commands/moderation/kick.js | 17 +++++++++-------- commands/moderation/softban.js | 17 +++++++++-------- commands/moderation/unban.js | 9 +++++---- commands/moderation/warn.js | 9 +++++---- commands/random/strawpoll.js | 9 +++++---- commands/response/8ball.js | 9 +++++---- commands/textedit/cowsay.js | 9 ++++++--- commands/userinfo/userinfo.js | 7 +++++-- commands/util/help.js | 9 +++++---- commands/util/invite.js | 9 +++++---- 15 files changed, 100 insertions(+), 79 deletions(-) diff --git a/commands/games/mathgame.js b/commands/games/mathgame.js index 7eee2344..8aca0191 100644 --- a/commands/games/mathgame.js +++ b/commands/games/mathgame.js @@ -1,5 +1,6 @@ const { Command } = require('discord.js-commando'); const { RichEmbed } = require('discord.js'); +const { stripIndents } = require('common-tags'); const math = require('mathjs'); const operations = ['+', '-', '*']; @@ -63,16 +64,16 @@ module.exports = class MathGameCommand extends Command { errors: ['time'] }); if (collected.first().content !== solved) - return msg.say( - `Aw... Too bad, try again next time! - The correct answer is: ${solved}` - ); + return msg.say(stripIndents` + Aw... Too bad, try again next time! + The correct answer is: ${solved} + `); return msg.say(`Good Job! You won! ${solved} is the correct answer!`); } catch (err) { - return msg.say( - `Aw... Too bad, try again next time! - The correct answer is: ${solved}` - ); + return msg.say(stripIndents` + Aw... Too bad, try again next time! + The correct answer is: ${solved} + `); } } }; diff --git a/commands/games/quiz.js b/commands/games/quiz.js index fe22fd92..2bfcaff2 100644 --- a/commands/games/quiz.js +++ b/commands/games/quiz.js @@ -1,5 +1,6 @@ const { Command } = require('discord.js-commando'); const { RichEmbed } = require('discord.js'); +const { stripIndents } = require('common-tags'); const request = require('superagent'); module.exports = class QuizCommand extends Command { @@ -25,10 +26,10 @@ module.exports = class QuizCommand extends Command { const answer = body[0].answer.toLowerCase().replace(/(|<\/i>)/g, ''); const embed = new RichEmbed() .setTitle('You have **15** seconds to answer this question:') - .setDescription( - `**Category: ${body[0].category.title}** - ${body[0].question}` - ); + .setDescription(stripIndents` + **Category: ${body[0].category.title}** + ${body[0].question} + `); await msg.embed(embed); try { const collected = await msg.channel.awaitMessages(res => res.author.id === msg.author.id, { @@ -40,10 +41,10 @@ module.exports = class QuizCommand extends Command { return msg.say(`The correct answer is: ${answer}`); return msg.say(`Perfect! The correct answer is: ${answer}`); } catch (err) { - return msg.say( - `Aw... Too bad, try again next time! - The Correct Answer was: ${answer}` - ); + return msg.say(stripIndents` + Aw... Too bad, try again next time! + The Correct Answer was: ${answer} + `); } } catch (err) { return msg.say('An Unknown Error Occurred.'); diff --git a/commands/games/slots.js b/commands/games/slots.js index 2b0d26e4..62fe0184 100644 --- a/commands/games/slots.js +++ b/commands/games/slots.js @@ -1,4 +1,5 @@ const { Command } = require('discord.js-commando'); +const { stripIndents } = require('common-tags'); const slotThing = [':grapes:', ':tangerine:', ':pear:', ':cherries:']; module.exports = class SlotsCommand extends Command { @@ -16,13 +17,13 @@ module.exports = class SlotsCommand extends Command { const slotTwo = slotThing[Math.floor(Math.random() * slotThing.length)]; const slotThree = slotThing[Math.floor(Math.random() * slotThing.length)]; if (slotOne === slotTwo && slotOne === slotThree) - return msg.say( - `${slotOne}|${slotTwo}|${slotThree} - Wow! You won! Great job... er... luck!` - ); - return msg.say( - `${slotOne}|${slotTwo}|${slotThree} - Aww... You lost... Guess it's just bad luck, huh?` - ); + return msg.say(stripIndents` + ${slotOne}|${slotTwo}|${slotThree} + Wow! You won! Great job... er... luck! + `); + return msg.say(stripIndents` + ${slotOne}|${slotTwo}|${slotThree} + Aww... You lost... Guess it's just bad luck, huh? + `); } }; diff --git a/commands/guildinfo/guildinfo.js b/commands/guildinfo/guildinfo.js index 3f15c2f3..87da041b 100644 --- a/commands/guildinfo/guildinfo.js +++ b/commands/guildinfo/guildinfo.js @@ -1,5 +1,6 @@ const { Command } = require('discord.js-commando'); const { RichEmbed } = require('discord.js'); +const { stripIndents } = require('common-tags'); const moment = require('moment'); require('moment-duration-format'); @@ -30,8 +31,10 @@ module.exports = class GuildInfoCommand extends Command { .addField('**ID:**', msg.guild.id, true) .addField('**Created On:**', - `${msg.guild.createdAt} - ${moment.duration(Date.now() - msg.guild.createdTimestamp).format('y[ years], M[ months], w[ weeks, and ]d[ days]')} ago.`, true) + stripIndents` + ${msg.guild.createdAt} + ${moment.duration(Date.now() - msg.guild.createdTimestamp).format('y[ years], M[ months], w[ weeks, and ]d[ days]')} ago. + `, true) .addField('**Default Channel:**', msg.guild.defaultChannel, true) .addField('**Region:**', diff --git a/commands/moderation/ban.js b/commands/moderation/ban.js index de9a02c2..3283501d 100644 --- a/commands/moderation/ban.js +++ b/commands/moderation/ban.js @@ -1,5 +1,6 @@ const { Command } = require('discord.js-commando'); const { RichEmbed } = require('discord.js'); +const { stripIndents } = require('common-tags'); module.exports = class BanCommand extends Command { constructor(client) { @@ -50,10 +51,10 @@ module.exports = class BanCommand extends Command { return msg.say('This member is not bannable. Perhaps they have a higher role than me?'); try { try { - await member.send( - `You were banned from ${msg.guild.name}! - Reason: ${reason}.` - ); + await member.send(stripIndents` + You were banned from ${msg.guild.name}! + Reason: ${reason}. + `); } catch (err) { await msg.say('Failed to send DM to user.'); } @@ -66,11 +67,11 @@ module.exports = class BanCommand extends Command { .setAuthor(msg.author.tag, msg.author.displayAvatarURL) .setColor(0xFF0000) .setTimestamp() - .setDescription( - `**Member:** ${member.user.tag} (${member.id}) + .setDescription(stripIndents` + **Member:** ${member.user.tag} (${member.id}) **Action:** Ban - **Reason:** ${reason}` - ); + **Reason:** ${reason} + `); return modlogs.send({embed}); } catch (err) { return msg.say('An Unknown Error Occurred.'); diff --git a/commands/moderation/kick.js b/commands/moderation/kick.js index a5230b7c..8e71c07b 100644 --- a/commands/moderation/kick.js +++ b/commands/moderation/kick.js @@ -1,5 +1,6 @@ const { Command } = require('discord.js-commando'); const { RichEmbed } = require('discord.js'); +const { stripIndents } = require('common-tags'); module.exports = class KickCommand extends Command { constructor(client) { @@ -47,10 +48,10 @@ module.exports = class KickCommand extends Command { return msg.say('This member is not kickable. Perhaps they have a higher role than me?'); try { try { - await member.send( - `You were kicked from ${msg.guild.name}! - Reason: ${reason}.` - ); + await member.send(stripIndents` + You were kicked from ${msg.guild.name}! + Reason: ${reason}. + `); } catch (err) { await msg.say('Failed to send DM.'); } @@ -62,11 +63,11 @@ module.exports = class KickCommand extends Command { .setAuthor(msg.author.tag, msg.author.displayAvatarURL) .setColor(0xFFA500) .setTimestamp() - .setDescription( - `**Member:** ${member.user.tag} (${member.id}) + .setDescription(stripIndents` + **Member:** ${member.user.tag} (${member.id}) **Action:** Kick - **Reason:** ${reason}` - ); + **Reason:** ${reason} + `); return modlogs.send({embed}); } catch (err) { return msg.say('An Unknown Error Occurred.'); diff --git a/commands/moderation/softban.js b/commands/moderation/softban.js index 743bbff4..b4e1179a 100644 --- a/commands/moderation/softban.js +++ b/commands/moderation/softban.js @@ -1,5 +1,6 @@ const { Command } = require('discord.js-commando'); const { RichEmbed } = require('discord.js'); +const { stripIndents } = require('common-tags'); module.exports = class SoftbanCommand extends Command { constructor(client) { @@ -49,10 +50,10 @@ module.exports = class SoftbanCommand extends Command { return msg.say('This member is not bannable. Perhaps they have a higher role than me?'); try { try { - await member.send( - `You were softbanned from ${msg.guild.name}! - Reason: ${reason}.` - ); + await member.send(stripIndents` + You were softbanned from ${msg.guild.name}! + Reason: ${reason}. + `); } catch (err) { await msg.say('Failed to send DM to user.'); } @@ -66,11 +67,11 @@ module.exports = class SoftbanCommand extends Command { .setAuthor(msg.author.tag, msg.author.displayAvatarURL) .setColor(0xFF4500) .setTimestamp() - .setDescription( - `**Member:** ${member.user.tag} (${member.id}) + .setDescription(stripIndents` + **Member:** ${member.user.tag} (${member.id}) **Action:** Softban - **Reason:** ${reason}` - ); + **Reason:** ${reason} + `); return modlogs.send({embed}); } catch (err) { return msg.say('An Unknown Error Occurred.'); diff --git a/commands/moderation/unban.js b/commands/moderation/unban.js index 21fa7dbb..ec76cb1e 100644 --- a/commands/moderation/unban.js +++ b/commands/moderation/unban.js @@ -1,5 +1,6 @@ const { Command } = require('discord.js-commando'); const { RichEmbed } = require('discord.js'); +const { stripIndents } = require('common-tags'); module.exports = class UnbanCommand extends Command { constructor(client) { @@ -61,11 +62,11 @@ module.exports = class UnbanCommand extends Command { .setAuthor(msg.author.tag, msg.author.displayAvatarURL) .setColor(0x00AE86) .setTimestamp() - .setDescription( - `**Member:** ${member.tag} (${member.id}) + .setDescription(stripIndents` + **Member:** ${member.tag} (${member.id}) **Action:** Unban - **Reason:** ${reason}` - ); + **Reason:** ${reason} + `); return modlogs.send({embed}); } catch (err) { return msg.say('An Unknown Error Occurred.'); diff --git a/commands/moderation/warn.js b/commands/moderation/warn.js index 5dd49019..53992fc6 100644 --- a/commands/moderation/warn.js +++ b/commands/moderation/warn.js @@ -1,5 +1,6 @@ const { Command } = require('discord.js-commando'); const { RichEmbed } = require('discord.js'); +const { stripIndents } = require('common-tags'); module.exports = class WarnCommand extends Command { constructor(client) { @@ -46,11 +47,11 @@ module.exports = class WarnCommand extends Command { .setAuthor(msg.author.tag, msg.author.displayAvatarURL) .setColor(0xFFFF00) .setTimestamp() - .setDescription( - `**Member:** ${member.user.tag} (${member.id}) + .setDescription(stripIndents` + **Member:** ${member.user.tag} (${member.id}) **Action:** Warn - **Reason:** ${reason}` - ); + **Reason:** ${reason} + `); return modlogs.send({embed}); } catch (err) { return msg.say('An Unknown Error Occurred.'); diff --git a/commands/random/strawpoll.js b/commands/random/strawpoll.js index c2546dce..d2729ae3 100644 --- a/commands/random/strawpoll.js +++ b/commands/random/strawpoll.js @@ -1,4 +1,5 @@ const { Command } = require('discord.js-commando'); +const { stripIndents } = require('common-tags'); const request = require('superagent'); module.exports = class StrawpollCommand extends Command { @@ -47,10 +48,10 @@ module.exports = class StrawpollCommand extends Command { title, options }); - return msg.say( - `${body.title} - http://strawpoll.me/${body.id}` - ); + return msg.say(stripIndents` + ${body.title} + http://strawpoll.me/${body.id} + `); } catch (err) { return msg.say('An Unknown Error Occurred.'); } diff --git a/commands/response/8ball.js b/commands/response/8ball.js index 5e4edc1a..1afb1083 100644 --- a/commands/response/8ball.js +++ b/commands/response/8ball.js @@ -1,4 +1,5 @@ const { Command } = require('discord.js-commando'); +const { stripIndents } = require('common-tags'); const answers = require('./8ballanswers'); module.exports = class MagicBallCommand extends Command { @@ -21,9 +22,9 @@ module.exports = class MagicBallCommand extends Command { run(msg, args) { const { question } = args; const answer = answers[Math.floor(Math.random() * answers.length)]; - return msg.say( - `Question: ${question} - :8ball: ${answer} :8ball:` - ); + return msg.say(stripIndents` + Question: ${question} + :8ball: ${answer} :8ball: + `); } }; diff --git a/commands/textedit/cowsay.js b/commands/textedit/cowsay.js index 92ef466a..ddb3d7d0 100644 --- a/commands/textedit/cowsay.js +++ b/commands/textedit/cowsay.js @@ -1,4 +1,5 @@ const { Command } = require('discord.js-commando'); +const { stripIndents } = require('common-tags'); module.exports = class CowsayCommand extends Command { constructor(client) { @@ -24,13 +25,15 @@ module.exports = class CowsayCommand extends Command { run(msg, args) { const { text } = args; - return msg.code(null, - `< ${text} > + return msg.code(null, + stripIndents` + < ${text} > \\ ^__^ \\ (oO)\\_______ (__)\\ )\\/\\ U ||----w | - || ||` + || || + ` ); } }; diff --git a/commands/userinfo/userinfo.js b/commands/userinfo/userinfo.js index f5087b4b..877b4237 100644 --- a/commands/userinfo/userinfo.js +++ b/commands/userinfo/userinfo.js @@ -1,5 +1,6 @@ const { Command } = require('discord.js-commando'); const { RichEmbed } = require('discord.js'); +const { stripIndents } = require('common-tags'); const moment = require('moment'); require('moment-duration-format'); @@ -60,8 +61,10 @@ module.exports = class UserInfoCommand extends Command { .addField('**ID:**', user.id, true) .addField('**Joined Discord On:**', - `${user.createdAt} - ${moment.duration(Date.now() - user.createdTimestamp).format('y[ years], M[ months], w[ weeks, and ]d[ days]')} ago.`, true) + stripIndents` + ${user.createdAt} + ${moment.duration(Date.now() - user.createdTimestamp).format('y[ years], M[ months], w[ weeks, and ]d[ days]')} ago. + `, true) .addField('**Joined Server On:**', `${member.joinedAt} ${moment.duration(Date.now() - member.joinedTimestamp).format('y[ years], M[ months], w[ weeks, and ]d[ days]')} ago.`, true) diff --git a/commands/util/help.js b/commands/util/help.js index 0e9e2a0d..220d0d8e 100644 --- a/commands/util/help.js +++ b/commands/util/help.js @@ -1,5 +1,6 @@ const { Command } = require('discord.js-commando'); const { RichEmbed } = require('discord.js'); +const { stripIndents } = require('common-tags'); module.exports = class HelpCommand extends Command { constructor(client) { @@ -29,14 +30,14 @@ module.exports = class HelpCommand extends Command { const showAll = command && command.toLowerCase() === 'all'; if (command && !showAll) { if (commands.length === 1) { - return msg.say( - `__Command **${commands[0].name}**:__ *${commands[0].description}* + return msg.say(stripIndents` + __Command **${commands[0].name}**:__ *${commands[0].description}* ${commands[0].guildOnly ? 'Usable Only in Servers' : 'Usable in Server and DM'} **Format:** ${msg.anyUsage(`${commands[0].name}${commands[0].format ? ` ${commands[0].format}` : ''}`)} **Aliases:** ${commands[0].aliases.join(', ') || 'None'} **Group:** ${commands[0].group.name} - ${commands[0].details || ''}` - ); + ${commands[0].details || ''} + `); } else if (commands.length > 1) { return msg.say('Multiple Commands Found. Please be more specific.'); } else { diff --git a/commands/util/invite.js b/commands/util/invite.js index 537d3861..d2a0be31 100644 --- a/commands/util/invite.js +++ b/commands/util/invite.js @@ -1,4 +1,5 @@ const { Command } = require('discord.js-commando'); +const { stripIndents } = require('common-tags'); module.exports = class InviteCommand extends Command { constructor(client) { @@ -12,11 +13,11 @@ module.exports = class InviteCommand extends Command { async run(msg) { const invite = await this.client.generateInvite('1345846343'); - return msg.say( - `Add me to your server with this link: + return msg.say(stripIndents` + Add me to your server with this link: ${invite} Or, come to my server with this link: - ${this.client.options.invite}` - ); + ${this.client.options.invite} + `); } };