stripIndents

This commit is contained in:
Daniel Odendahl Jr
2017-05-03 01:19:44 +00:00
parent 74fa836044
commit 2ee1f3e594
15 changed files with 100 additions and 79 deletions
+9 -8
View File
@@ -1,5 +1,6 @@
const { Command } = require('discord.js-commando'); const { Command } = require('discord.js-commando');
const { RichEmbed } = require('discord.js'); const { RichEmbed } = require('discord.js');
const { stripIndents } = require('common-tags');
const math = require('mathjs'); const math = require('mathjs');
const operations = ['+', '-', '*']; const operations = ['+', '-', '*'];
@@ -63,16 +64,16 @@ module.exports = class MathGameCommand extends Command {
errors: ['time'] errors: ['time']
}); });
if (collected.first().content !== solved) if (collected.first().content !== solved)
return msg.say( return msg.say(stripIndents`
`Aw... Too bad, try again next time! Aw... Too bad, try again next time!
The correct answer is: ${solved}` The correct answer is: ${solved}
); `);
return msg.say(`Good Job! You won! ${solved} is the correct answer!`); return msg.say(`Good Job! You won! ${solved} is the correct answer!`);
} catch (err) { } catch (err) {
return msg.say( return msg.say(stripIndents`
`Aw... Too bad, try again next time! Aw... Too bad, try again next time!
The correct answer is: ${solved}` The correct answer is: ${solved}
); `);
} }
} }
}; };
+9 -8
View File
@@ -1,5 +1,6 @@
const { Command } = require('discord.js-commando'); const { Command } = require('discord.js-commando');
const { RichEmbed } = require('discord.js'); const { RichEmbed } = require('discord.js');
const { stripIndents } = require('common-tags');
const request = require('superagent'); const request = require('superagent');
module.exports = class QuizCommand extends Command { module.exports = class QuizCommand extends Command {
@@ -25,10 +26,10 @@ module.exports = class QuizCommand extends Command {
const answer = body[0].answer.toLowerCase().replace(/(<i>|<\/i>)/g, ''); const answer = body[0].answer.toLowerCase().replace(/(<i>|<\/i>)/g, '');
const embed = new RichEmbed() const embed = new RichEmbed()
.setTitle('You have **15** seconds to answer this question:') .setTitle('You have **15** seconds to answer this question:')
.setDescription( .setDescription(stripIndents`
`**Category: ${body[0].category.title}** **Category: ${body[0].category.title}**
${body[0].question}` ${body[0].question}
); `);
await msg.embed(embed); await msg.embed(embed);
try { try {
const collected = await msg.channel.awaitMessages(res => res.author.id === msg.author.id, { 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(`The correct answer is: ${answer}`);
return msg.say(`Perfect! The correct answer is: ${answer}`); return msg.say(`Perfect! The correct answer is: ${answer}`);
} catch (err) { } catch (err) {
return msg.say( return msg.say(stripIndents`
`Aw... Too bad, try again next time! Aw... Too bad, try again next time!
The Correct Answer was: ${answer}` The Correct Answer was: ${answer}
); `);
} }
} catch (err) { } catch (err) {
return msg.say('An Unknown Error Occurred.'); return msg.say('An Unknown Error Occurred.');
+9 -8
View File
@@ -1,4 +1,5 @@
const { Command } = require('discord.js-commando'); const { Command } = require('discord.js-commando');
const { stripIndents } = require('common-tags');
const slotThing = [':grapes:', ':tangerine:', ':pear:', ':cherries:']; const slotThing = [':grapes:', ':tangerine:', ':pear:', ':cherries:'];
module.exports = class SlotsCommand extends Command { 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 slotTwo = slotThing[Math.floor(Math.random() * slotThing.length)];
const slotThree = slotThing[Math.floor(Math.random() * slotThing.length)]; const slotThree = slotThing[Math.floor(Math.random() * slotThing.length)];
if (slotOne === slotTwo && slotOne === slotThree) if (slotOne === slotTwo && slotOne === slotThree)
return msg.say( return msg.say(stripIndents`
`${slotOne}|${slotTwo}|${slotThree} ${slotOne}|${slotTwo}|${slotThree}
Wow! You won! Great job... er... luck!` Wow! You won! Great job... er... luck!
); `);
return msg.say( return msg.say(stripIndents`
`${slotOne}|${slotTwo}|${slotThree} ${slotOne}|${slotTwo}|${slotThree}
Aww... You lost... Guess it's just bad luck, huh?` Aww... You lost... Guess it's just bad luck, huh?
); `);
} }
}; };
+5 -2
View File
@@ -1,5 +1,6 @@
const { Command } = require('discord.js-commando'); const { Command } = require('discord.js-commando');
const { RichEmbed } = require('discord.js'); const { RichEmbed } = require('discord.js');
const { stripIndents } = require('common-tags');
const moment = require('moment'); const moment = require('moment');
require('moment-duration-format'); require('moment-duration-format');
@@ -30,8 +31,10 @@ module.exports = class GuildInfoCommand extends Command {
.addField('**ID:**', .addField('**ID:**',
msg.guild.id, true) msg.guild.id, true)
.addField('**Created On:**', .addField('**Created On:**',
`${msg.guild.createdAt} stripIndents`
${moment.duration(Date.now() - msg.guild.createdTimestamp).format('y[ years], M[ months], w[ weeks, and ]d[ days]')} ago.`, true) ${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:**', .addField('**Default Channel:**',
msg.guild.defaultChannel, true) msg.guild.defaultChannel, true)
.addField('**Region:**', .addField('**Region:**',
+9 -8
View File
@@ -1,5 +1,6 @@
const { Command } = require('discord.js-commando'); const { Command } = require('discord.js-commando');
const { RichEmbed } = require('discord.js'); const { RichEmbed } = require('discord.js');
const { stripIndents } = require('common-tags');
module.exports = class BanCommand extends Command { module.exports = class BanCommand extends Command {
constructor(client) { 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?'); return msg.say('This member is not bannable. Perhaps they have a higher role than me?');
try { try {
try { try {
await member.send( await member.send(stripIndents`
`You were banned from ${msg.guild.name}! You were banned from ${msg.guild.name}!
Reason: ${reason}.` Reason: ${reason}.
); `);
} catch (err) { } catch (err) {
await msg.say('Failed to send DM to user.'); 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) .setAuthor(msg.author.tag, msg.author.displayAvatarURL)
.setColor(0xFF0000) .setColor(0xFF0000)
.setTimestamp() .setTimestamp()
.setDescription( .setDescription(stripIndents`
`**Member:** ${member.user.tag} (${member.id}) **Member:** ${member.user.tag} (${member.id})
**Action:** Ban **Action:** Ban
**Reason:** ${reason}` **Reason:** ${reason}
); `);
return modlogs.send({embed}); return modlogs.send({embed});
} catch (err) { } catch (err) {
return msg.say('An Unknown Error Occurred.'); return msg.say('An Unknown Error Occurred.');
+9 -8
View File
@@ -1,5 +1,6 @@
const { Command } = require('discord.js-commando'); const { Command } = require('discord.js-commando');
const { RichEmbed } = require('discord.js'); const { RichEmbed } = require('discord.js');
const { stripIndents } = require('common-tags');
module.exports = class KickCommand extends Command { module.exports = class KickCommand extends Command {
constructor(client) { 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?'); return msg.say('This member is not kickable. Perhaps they have a higher role than me?');
try { try {
try { try {
await member.send( await member.send(stripIndents`
`You were kicked from ${msg.guild.name}! You were kicked from ${msg.guild.name}!
Reason: ${reason}.` Reason: ${reason}.
); `);
} catch (err) { } catch (err) {
await msg.say('Failed to send DM.'); await msg.say('Failed to send DM.');
} }
@@ -62,11 +63,11 @@ module.exports = class KickCommand extends Command {
.setAuthor(msg.author.tag, msg.author.displayAvatarURL) .setAuthor(msg.author.tag, msg.author.displayAvatarURL)
.setColor(0xFFA500) .setColor(0xFFA500)
.setTimestamp() .setTimestamp()
.setDescription( .setDescription(stripIndents`
`**Member:** ${member.user.tag} (${member.id}) **Member:** ${member.user.tag} (${member.id})
**Action:** Kick **Action:** Kick
**Reason:** ${reason}` **Reason:** ${reason}
); `);
return modlogs.send({embed}); return modlogs.send({embed});
} catch (err) { } catch (err) {
return msg.say('An Unknown Error Occurred.'); return msg.say('An Unknown Error Occurred.');
+9 -8
View File
@@ -1,5 +1,6 @@
const { Command } = require('discord.js-commando'); const { Command } = require('discord.js-commando');
const { RichEmbed } = require('discord.js'); const { RichEmbed } = require('discord.js');
const { stripIndents } = require('common-tags');
module.exports = class SoftbanCommand extends Command { module.exports = class SoftbanCommand extends Command {
constructor(client) { 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?'); return msg.say('This member is not bannable. Perhaps they have a higher role than me?');
try { try {
try { try {
await member.send( await member.send(stripIndents`
`You were softbanned from ${msg.guild.name}! You were softbanned from ${msg.guild.name}!
Reason: ${reason}.` Reason: ${reason}.
); `);
} catch (err) { } catch (err) {
await msg.say('Failed to send DM to user.'); 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) .setAuthor(msg.author.tag, msg.author.displayAvatarURL)
.setColor(0xFF4500) .setColor(0xFF4500)
.setTimestamp() .setTimestamp()
.setDescription( .setDescription(stripIndents`
`**Member:** ${member.user.tag} (${member.id}) **Member:** ${member.user.tag} (${member.id})
**Action:** Softban **Action:** Softban
**Reason:** ${reason}` **Reason:** ${reason}
); `);
return modlogs.send({embed}); return modlogs.send({embed});
} catch (err) { } catch (err) {
return msg.say('An Unknown Error Occurred.'); return msg.say('An Unknown Error Occurred.');
+5 -4
View File
@@ -1,5 +1,6 @@
const { Command } = require('discord.js-commando'); const { Command } = require('discord.js-commando');
const { RichEmbed } = require('discord.js'); const { RichEmbed } = require('discord.js');
const { stripIndents } = require('common-tags');
module.exports = class UnbanCommand extends Command { module.exports = class UnbanCommand extends Command {
constructor(client) { constructor(client) {
@@ -61,11 +62,11 @@ module.exports = class UnbanCommand extends Command {
.setAuthor(msg.author.tag, msg.author.displayAvatarURL) .setAuthor(msg.author.tag, msg.author.displayAvatarURL)
.setColor(0x00AE86) .setColor(0x00AE86)
.setTimestamp() .setTimestamp()
.setDescription( .setDescription(stripIndents`
`**Member:** ${member.tag} (${member.id}) **Member:** ${member.tag} (${member.id})
**Action:** Unban **Action:** Unban
**Reason:** ${reason}` **Reason:** ${reason}
); `);
return modlogs.send({embed}); return modlogs.send({embed});
} catch (err) { } catch (err) {
return msg.say('An Unknown Error Occurred.'); return msg.say('An Unknown Error Occurred.');
+5 -4
View File
@@ -1,5 +1,6 @@
const { Command } = require('discord.js-commando'); const { Command } = require('discord.js-commando');
const { RichEmbed } = require('discord.js'); const { RichEmbed } = require('discord.js');
const { stripIndents } = require('common-tags');
module.exports = class WarnCommand extends Command { module.exports = class WarnCommand extends Command {
constructor(client) { constructor(client) {
@@ -46,11 +47,11 @@ module.exports = class WarnCommand extends Command {
.setAuthor(msg.author.tag, msg.author.displayAvatarURL) .setAuthor(msg.author.tag, msg.author.displayAvatarURL)
.setColor(0xFFFF00) .setColor(0xFFFF00)
.setTimestamp() .setTimestamp()
.setDescription( .setDescription(stripIndents`
`**Member:** ${member.user.tag} (${member.id}) **Member:** ${member.user.tag} (${member.id})
**Action:** Warn **Action:** Warn
**Reason:** ${reason}` **Reason:** ${reason}
); `);
return modlogs.send({embed}); return modlogs.send({embed});
} catch (err) { } catch (err) {
return msg.say('An Unknown Error Occurred.'); return msg.say('An Unknown Error Occurred.');
+5 -4
View File
@@ -1,4 +1,5 @@
const { Command } = require('discord.js-commando'); const { Command } = require('discord.js-commando');
const { stripIndents } = require('common-tags');
const request = require('superagent'); const request = require('superagent');
module.exports = class StrawpollCommand extends Command { module.exports = class StrawpollCommand extends Command {
@@ -47,10 +48,10 @@ module.exports = class StrawpollCommand extends Command {
title, title,
options options
}); });
return msg.say( return msg.say(stripIndents`
`${body.title} ${body.title}
http://strawpoll.me/${body.id}` http://strawpoll.me/${body.id}
); `);
} catch (err) { } catch (err) {
return msg.say('An Unknown Error Occurred.'); return msg.say('An Unknown Error Occurred.');
} }
+5 -4
View File
@@ -1,4 +1,5 @@
const { Command } = require('discord.js-commando'); const { Command } = require('discord.js-commando');
const { stripIndents } = require('common-tags');
const answers = require('./8ballanswers'); const answers = require('./8ballanswers');
module.exports = class MagicBallCommand extends Command { module.exports = class MagicBallCommand extends Command {
@@ -21,9 +22,9 @@ module.exports = class MagicBallCommand extends Command {
run(msg, args) { run(msg, args) {
const { question } = args; const { question } = args;
const answer = answers[Math.floor(Math.random() * answers.length)]; const answer = answers[Math.floor(Math.random() * answers.length)];
return msg.say( return msg.say(stripIndents`
`Question: ${question} Question: ${question}
:8ball: ${answer} :8ball:` :8ball: ${answer} :8ball:
); `);
} }
}; };
+6 -3
View File
@@ -1,4 +1,5 @@
const { Command } = require('discord.js-commando'); const { Command } = require('discord.js-commando');
const { stripIndents } = require('common-tags');
module.exports = class CowsayCommand extends Command { module.exports = class CowsayCommand extends Command {
constructor(client) { constructor(client) {
@@ -24,13 +25,15 @@ module.exports = class CowsayCommand extends Command {
run(msg, args) { run(msg, args) {
const { text } = args; const { text } = args;
return msg.code(null, return msg.code(null,
`< ${text} > stripIndents`
< ${text} >
\\ ^__^ \\ ^__^
\\ (oO)\\_______ \\ (oO)\\_______
(__)\\ )\\/\\ (__)\\ )\\/\\
U ||----w | U ||----w |
|| ||` || ||
`
); );
} }
}; };
+5 -2
View File
@@ -1,5 +1,6 @@
const { Command } = require('discord.js-commando'); const { Command } = require('discord.js-commando');
const { RichEmbed } = require('discord.js'); const { RichEmbed } = require('discord.js');
const { stripIndents } = require('common-tags');
const moment = require('moment'); const moment = require('moment');
require('moment-duration-format'); require('moment-duration-format');
@@ -60,8 +61,10 @@ module.exports = class UserInfoCommand extends Command {
.addField('**ID:**', .addField('**ID:**',
user.id, true) user.id, true)
.addField('**Joined Discord On:**', .addField('**Joined Discord On:**',
`${user.createdAt} stripIndents`
${moment.duration(Date.now() - user.createdTimestamp).format('y[ years], M[ months], w[ weeks, and ]d[ days]')} ago.`, true) ${user.createdAt}
${moment.duration(Date.now() - user.createdTimestamp).format('y[ years], M[ months], w[ weeks, and ]d[ days]')} ago.
`, true)
.addField('**Joined Server On:**', .addField('**Joined Server On:**',
`${member.joinedAt} `${member.joinedAt}
${moment.duration(Date.now() - member.joinedTimestamp).format('y[ years], M[ months], w[ weeks, and ]d[ days]')} ago.`, true) ${moment.duration(Date.now() - member.joinedTimestamp).format('y[ years], M[ months], w[ weeks, and ]d[ days]')} ago.`, true)
+5 -4
View File
@@ -1,5 +1,6 @@
const { Command } = require('discord.js-commando'); const { Command } = require('discord.js-commando');
const { RichEmbed } = require('discord.js'); const { RichEmbed } = require('discord.js');
const { stripIndents } = require('common-tags');
module.exports = class HelpCommand extends Command { module.exports = class HelpCommand extends Command {
constructor(client) { constructor(client) {
@@ -29,14 +30,14 @@ module.exports = class HelpCommand extends Command {
const showAll = command && command.toLowerCase() === 'all'; const showAll = command && command.toLowerCase() === 'all';
if (command && !showAll) { if (command && !showAll) {
if (commands.length === 1) { if (commands.length === 1) {
return msg.say( return msg.say(stripIndents`
`__Command **${commands[0].name}**:__ *${commands[0].description}* __Command **${commands[0].name}**:__ *${commands[0].description}*
${commands[0].guildOnly ? 'Usable Only in Servers' : 'Usable in Server and DM'} ${commands[0].guildOnly ? 'Usable Only in Servers' : 'Usable in Server and DM'}
**Format:** ${msg.anyUsage(`${commands[0].name}${commands[0].format ? ` ${commands[0].format}` : ''}`)} **Format:** ${msg.anyUsage(`${commands[0].name}${commands[0].format ? ` ${commands[0].format}` : ''}`)}
**Aliases:** ${commands[0].aliases.join(', ') || 'None'} **Aliases:** ${commands[0].aliases.join(', ') || 'None'}
**Group:** ${commands[0].group.name} **Group:** ${commands[0].group.name}
${commands[0].details || ''}` ${commands[0].details || ''}
); `);
} else if (commands.length > 1) { } else if (commands.length > 1) {
return msg.say('Multiple Commands Found. Please be more specific.'); return msg.say('Multiple Commands Found. Please be more specific.');
} else { } else {
+5 -4
View File
@@ -1,4 +1,5 @@
const { Command } = require('discord.js-commando'); const { Command } = require('discord.js-commando');
const { stripIndents } = require('common-tags');
module.exports = class InviteCommand extends Command { module.exports = class InviteCommand extends Command {
constructor(client) { constructor(client) {
@@ -12,11 +13,11 @@ module.exports = class InviteCommand extends Command {
async run(msg) { async run(msg) {
const invite = await this.client.generateInvite('1345846343'); const invite = await this.client.generateInvite('1345846343');
return msg.say( return msg.say(stripIndents`
`Add me to your server with this link: Add me to your server with this link:
${invite} ${invite}
Or, come to my server with this link: Or, come to my server with this link:
${this.client.options.invite}` ${this.client.options.invite}
); `);
} }
}; };