From 8dd6ec1f9bb35a5c401bb045c89b270433af5b8b Mon Sep 17 00:00:00 2001 From: Daniel Odendahl Jr Date: Fri, 24 Mar 2017 23:23:25 +0000 Subject: [PATCH] Some Args and empty tests --- commands/avataredit/3000years.js | 49 ++++++++++++++-------------- commands/avataredit/beautiful.js | 40 ++++++++++------------- commands/avataredit/bobross.js | 42 +++++++++++------------- commands/avataredit/rip.js | 36 +++++++++----------- commands/avataredit/steamcard.js | 56 ++++++++++++++------------------ commands/botinfo/contact.js | 12 +++---- commands/guildinfo/emoji.js | 6 ++-- commands/guildinfo/guildinfo.js | 42 ++++++++++++------------ commands/random/remind.js | 19 +++++++---- 9 files changed, 141 insertions(+), 161 deletions(-) diff --git a/commands/avataredit/3000years.js b/commands/avataredit/3000years.js index d40bc81d..635933d7 100644 --- a/commands/avataredit/3000years.js +++ b/commands/avataredit/3000years.js @@ -11,37 +11,36 @@ module.exports = class YearsCommand extends commando.Command { group: 'avataredit', memberName: '3000years', description: "It's been 3000 years... (;3000years @User)", - examples: [';3000years @user'] + examples: [';3000years @user'], + args: [ + { + key: 'user', + prompt: 'Which user would you like to edit the avatar of?\n', + type: 'user' + } + ] }); } - async run(message) { + async run(message, args) { if (message.channel.type !== 'dm') { if (!message.channel.permissionsFor(this.client.user).hasPermission(['SEND_MESSAGES', 'READ_MESSAGES', 'ATTACH_FILES'])) return; } console.log(`[Command] ${message.content}`); - if (message.mentions.users.size !== 1) { - message.channel.send(':x: Error! Please mention one user!'); - } - else { - if (!message.mentions.users.first().avatarURL) { - message.channel.send(":x: Error! This user has no avatar!"); - } - else { - let userAvatar = message.mentions.users.first().avatarURL; - userAvatar = userAvatar.replace(".jpg", ".png"); - userAvatar = userAvatar.replace(".gif", ".png"); - let images = []; - images.push(Jimp.read(userAvatar)); - images.push(Jimp.read("./images/3000years.png")); - let [avatar, years] = await Promise.all(images); - avatar.resize(200, 200); - years.blit(avatar, 461, 127); - years.getBuffer(Jimp.MIME_PNG, (err, buff) => { - if (err) throw err; - return message.channel.sendFile(buff); - }); - } - } + let user = args.user; + if (!user.displayAvatarURL) return message.channel.send(":x: Error! This user has no avatar!"); + let userAvatar = user.displayAvatarURL; + userAvatar = userAvatar.replace(".jpg", ".png"); + userAvatar = userAvatar.replace(".gif", ".png"); + let images = []; + images.push(Jimp.read(userAvatar)); + images.push(Jimp.read("./images/3000years.png")); + let [avatar, years] = await Promise.all(images); + avatar.resize(200, 200); + years.blit(avatar, 461, 127); + years.getBuffer(Jimp.MIME_PNG, (err, buff) => { + if (err) return message.channel.send(':x: Error! Something went wrong!'); + return message.channel.sendFile(buff); + }); } }; diff --git a/commands/avataredit/beautiful.js b/commands/avataredit/beautiful.js index 56620168..18c20f64 100644 --- a/commands/avataredit/beautiful.js +++ b/commands/avataredit/beautiful.js @@ -21,29 +21,25 @@ module.exports = class BeautifulCommand extends commando.Command { } console.log(`[Command] ${message.content}`); if (message.mentions.users.size !== 1) { - message.channel.send(':x: Error! Please mention one user!'); + return message.channel.send(':x: Error! Please mention one user!'); } - else { - if (!message.mentions.users.first().avatarURL) { - message.channel.send(":x: Error! This user has no avatar!"); - } - else { - let userAvatar = message.mentions.users.first().avatarURL; - userAvatar = userAvatar.replace(".jpg", ".png"); - userAvatar = userAvatar.replace(".gif", ".png"); - let images = []; - images.push(Jimp.read(userAvatar)); - images.push(Jimp.read("./images/beautiful.jpg")); - let [avatar, beautiful] = await Promise.all(images); - avatar.resize(200, 200); - beautiful.blit(avatar, 432, 42); - avatar.resize(190, 190); - beautiful.blit(avatar, 451, 434); - beautiful.getBuffer(Jimp.MIME_PNG, (err, buff) => { - if (err) throw err; - return message.channel.sendFile(buff); - }); - } + else if (!message.mentions.users.first().avatarURL) { + return message.channel.send(":x: Error! This user has no avatar!"); } + let userAvatar = message.mentions.users.first().avatarURL; + userAvatar = userAvatar.replace(".jpg", ".png"); + userAvatar = userAvatar.replace(".gif", ".png"); + let images = []; + images.push(Jimp.read(userAvatar)); + images.push(Jimp.read("./images/beautiful.jpg")); + let [avatar, beautiful] = await Promise.all(images); + avatar.resize(200, 200); + beautiful.blit(avatar, 432, 42); + avatar.resize(190, 190); + beautiful.blit(avatar, 451, 434); + beautiful.getBuffer(Jimp.MIME_PNG, (err, buff) => { + if (err) return; + return message.channel.sendFile(buff); + }); } }; diff --git a/commands/avataredit/bobross.js b/commands/avataredit/bobross.js index 61f406e8..9117d245 100644 --- a/commands/avataredit/bobross.js +++ b/commands/avataredit/bobross.js @@ -22,30 +22,26 @@ module.exports = class BobRossCommand extends commando.Command { } console.log(`[Command] ${message.content}`); if (message.mentions.users.size !== 1) { - message.channel.send(':x: Error! Please mention one user!'); + return message.channel.send(':x: Error! Please mention one user!'); } - else { - if (!message.mentions.users.first().avatarURL) { - message.channel.send(":x: Error! This user has no avatar!"); - } - else { - let userAvatar = message.mentions.users.first().avatarURL; - userAvatar = userAvatar.replace(".jpg", ".png"); - userAvatar = userAvatar.replace(".gif", ".png"); - let images = []; - images.push(Jimp.read(userAvatar)); - images.push(Jimp.read("./images/BobRoss.png")); - images.push(Jimp.read("./images/BlankWhite.png")); - let [avatar, bob, nothing] = await Promise.all(images); - avatar.rotate(2); - avatar.resize(300, 300); - nothing.composite(avatar, 44, 85); - nothing.composite(bob, 0, 0); - nothing.getBuffer(Jimp.MIME_PNG, (err, buff) => { - if (err) throw err; - return message.channel.sendFile(buff); - }); - } + else if (!message.mentions.users.first().avatarURL) { + return message.channel.send(":x: Error! This user has no avatar!"); } + let userAvatar = message.mentions.users.first().avatarURL; + userAvatar = userAvatar.replace(".jpg", ".png"); + userAvatar = userAvatar.replace(".gif", ".png"); + let images = []; + images.push(Jimp.read(userAvatar)); + images.push(Jimp.read("./images/BobRoss.png")); + images.push(Jimp.read("./images/BlankWhite.png")); + let [avatar, bob, nothing] = await Promise.all(images); + avatar.rotate(2); + avatar.resize(300, 300); + nothing.composite(avatar, 44, 85); + nothing.composite(bob, 0, 0); + nothing.getBuffer(Jimp.MIME_PNG, (err, buff) => { + if (err) return; + return message.channel.sendFile(buff); + }); } }; diff --git a/commands/avataredit/rip.js b/commands/avataredit/rip.js index 464132e8..11b5492e 100644 --- a/commands/avataredit/rip.js +++ b/commands/avataredit/rip.js @@ -22,27 +22,23 @@ module.exports = class RIPCommand extends commando.Command { } console.log(`[Command] ${message.content}`); if (message.mentions.users.size !== 1) { - message.channel.send(':x: Error! Please mention one user!'); + return message.channel.send(':x: Error! Please mention one user!'); } - else { - if (!message.mentions.users.first().avatarURL) { - message.channel.send(":x: Error! This user has no avatar!"); - } - else { - let userAvatar = message.mentions.users.first().avatarURL; - userAvatar = userAvatar.replace(".jpg", ".png"); - userAvatar = userAvatar.replace(".gif", ".png"); - let images = []; - images.push(Jimp.read(userAvatar)); - images.push(Jimp.read("./images/gravestone.jpg")); - let [avatar, gravestone] = await Promise.all(images); - avatar.resize(200, 200); - gravestone.blit(avatar, 60, 65); - gravestone.getBuffer(Jimp.MIME_PNG, (err, buff) => { - if (err) throw err; - return message.channel.sendFile(buff); - }); - } + else if (!message.mentions.users.first().avatarURL) { + return message.channel.send(":x: Error! This user has no avatar!"); } + let userAvatar = message.mentions.users.first().avatarURL; + userAvatar = userAvatar.replace(".jpg", ".png"); + userAvatar = userAvatar.replace(".gif", ".png"); + let images = []; + images.push(Jimp.read(userAvatar)); + images.push(Jimp.read("./images/gravestone.jpg")); + let [avatar, gravestone] = await Promise.all(images); + avatar.resize(200, 200); + gravestone.blit(avatar, 60, 65); + gravestone.getBuffer(Jimp.MIME_PNG, (err, buff) => { + if (err) return; + return message.channel.sendFile(buff); + }); } }; diff --git a/commands/avataredit/steamcard.js b/commands/avataredit/steamcard.js index f87b789c..84fb88a3 100644 --- a/commands/avataredit/steamcard.js +++ b/commands/avataredit/steamcard.js @@ -20,38 +20,32 @@ module.exports = class SteamCardCommand extends commando.Command { if (!message.channel.permissionsFor(this.client.user).hasPermission(['SEND_MESSAGES', 'READ_MESSAGES', 'ATTACH_FILES'])) return; } console.log(`[Command] ${message.content}`); - if (message.channel.type !== 'dm') { - if (message.mentions.users.size !== 1) { - message.channel.send(':x: Error! Please mention one user!'); - } - else { - if (!message.mentions.users.first().avatarURL) { - message.channel.send(":x: Error! This user has no avatar!"); - } - else { - let userDisplayName = message.guild.member(message.mentions.users.first()).displayName; - let userAvatar = message.mentions.users.first().avatarURL; - userAvatar = userAvatar.replace(".jpg", ".png"); - userAvatar = userAvatar.replace(".gif", ".png"); - let images = []; - images.push(Jimp.read(userAvatar)); - images.push(Jimp.read("./images/SteamCard.png")); - images.push(Jimp.read("./images/SteamCardBlank.png")); - let [avatar, steamcard, nothing] = await Promise.all(images); - let font = await Jimp.loadFont(Jimp.FONT_SANS_32_WHITE); - avatar.resize(450, 450); - nothing.composite(avatar, 25, 25); - nothing.composite(steamcard, 0, 0); - nothing.print(font, 38, 20, userDisplayName); - nothing.getBuffer(Jimp.MIME_PNG, (err, buff) => { - if (err) throw err; - return message.channel.sendFile(buff); - }); - } - } + if (message.channel.type === 'dm') { + return message.channel.send(':x: Error! This command does not work in DM!'); } - else { - message.channel.send(':x: Error! This command does not work in DM!'); + else if (message.mentions.users.size !== 1) { + return message.channel.send(':x: Error! Please mention one user!'); } + else if (!message.mentions.users.first().avatarURL) { + return message.channel.send(":x: Error! This user has no avatar!"); + } + let userDisplayName = message.guild.member(message.mentions.users.first()).displayName; + let userAvatar = message.mentions.users.first().avatarURL; + userAvatar = userAvatar.replace(".jpg", ".png"); + userAvatar = userAvatar.replace(".gif", ".png"); + let images = []; + images.push(Jimp.read(userAvatar)); + images.push(Jimp.read("./images/SteamCard.png")); + images.push(Jimp.read("./images/SteamCardBlank.png")); + let [avatar, steamcard, nothing] = await Promise.all(images); + let font = await Jimp.loadFont(Jimp.FONT_SANS_32_WHITE); + avatar.resize(450, 450); + nothing.composite(avatar, 25, 25); + nothing.composite(steamcard, 0, 0); + nothing.print(font, 38, 20, userDisplayName); + nothing.getBuffer(Jimp.MIME_PNG, (err, buff) => { + if (err) return; + return message.channel.sendFile(buff); + }); } }; diff --git a/commands/botinfo/contact.js b/commands/botinfo/contact.js index 8efff2e3..e6819cd0 100644 --- a/commands/botinfo/contact.js +++ b/commands/botinfo/contact.js @@ -28,14 +28,10 @@ module.exports = class ContactCommand extends commando.Command { if (message.author.id === banlist.banned[banID]) { return message.channel.send("Sorry, you've been banned from using this command."); } - else { - if (!messageToReport) { - return message.channel.send(':x: Error! Please do not report nothing!'); - } - else { - this.client.users.get(config.owner).send(`**${message.author.username}#${message.author.discriminator} (${message.author.id}):**\n${messageToReport}`); - return message.channel.send('Message Sent! Thanks for your support!'); - } + else if (!messageToReport) { + return message.channel.send(':x: Error! Please do not report nothing!'); } + this.client.users.get(config.owner).send(`**${message.author.username}#${message.author.discriminator} (${message.author.id}):**\n${messageToReport}`); + return message.channel.send('Message Sent! Thanks for your support!'); } }; diff --git a/commands/guildinfo/emoji.js b/commands/guildinfo/emoji.js index 1c4d8403..4ca5949b 100644 --- a/commands/guildinfo/emoji.js +++ b/commands/guildinfo/emoji.js @@ -21,11 +21,9 @@ module.exports = class EmojiCommand extends commando.Command { if (!message.channel.permissionsFor(this.client.user).hasPermission(['SEND_MESSAGES', 'READ_MESSAGES'])) return; } console.log(`[Command] ${message.content}`); - if (message.channel.type !== 'dm') { - return message.channel.send(message.guild.emojis.map(e => e).join(" ")); - } - else { + if (message.channel.type === 'dm') { return message.channel.send(":x: Error! This command does not work in DM!"); } + return message.channel.send(message.guild.emojis.map(e => e).join(" ")); } }; diff --git a/commands/guildinfo/guildinfo.js b/commands/guildinfo/guildinfo.js index dd243191..c4979f66 100644 --- a/commands/guildinfo/guildinfo.js +++ b/commands/guildinfo/guildinfo.js @@ -1,5 +1,7 @@ const commando = require('discord.js-commando'); const Discord = require('discord.js'); +const moment = require('moment'); +require('moment-duration-format'); module.exports = class GuildInfoCommand extends commando.Command { constructor(Client) { @@ -22,28 +24,26 @@ module.exports = class GuildInfoCommand extends commando.Command { if (!message.channel.permissionsFor(this.client.user).hasPermission(['SEND_MESSAGES', 'READ_MESSAGES', 'EMBED_LINKS'])) return; } console.log(`[Command] ${message.content}`); - if (message.channel.type !== 'dm') { - const embed = new Discord.RichEmbed() - .setColor(0x00AE86) - .setThumbnail(message.guild.iconURL) - .addField('**Name:**', - message.guild.name, true) - .addField('**ID:**', - message.guild.id, true) - .addField('**Created On:**', - message.guild.createdAt, true) - .addField('**Default Channel:**', - message.guild.defaultChannel, true) - .addField('**Region:**', - message.guild.region, true) - .addField('**Owner:**', - `${message.guild.owner.user.username}#${message.guild.owner.user.discriminator}`, true) - .addField("**Users:**", - message.guild.memberCount, true); - return message.channel.sendEmbed(embed); - } - else { + if (message.channel.type === 'dm') { return message.channel.send(":x: Error! This command does not work in DM!"); } + const embed = new Discord.RichEmbed() + .setColor(0x00AE86) + .setThumbnail(message.guild.iconURL) + .addField('**Name:**', + message.guild.name, true) + .addField('**ID:**', + message.guild.id, true) + .addField('**Created On:**', + `${message.guild.createdAt} (${moment.duration(message.guild.createdTimestamp - Date.now()).format('y[ years], M[ months], w[ weeks, and ]d[ days]')} ago)`, true) + .addField('**Default Channel:**', + message.guild.defaultChannel, true) + .addField('**Region:**', + message.guild.region, true) + .addField('**Owner:**', + `${message.guild.owner.user.username}#${message.guild.owner.user.discriminator}`, true) + .addField("**Users:**", + message.guild.memberCount, true); + return message.channel.sendEmbed(embed); } }; diff --git a/commands/random/remind.js b/commands/random/remind.js index 4298df5d..e7b5cc05 100644 --- a/commands/random/remind.js +++ b/commands/random/remind.js @@ -22,12 +22,17 @@ module.exports = class RemindCommand extends commando.Command { } console.log(`[Command] ${message.content}`); let remindMe = message.content.split(" ").slice(1).join(" "); - let remindTime = sherlock.parse(remindMe); - let time = remindTime.startDate.getTime() - Date.now(); - let preRemind = await message.channel.send(`I will remind you '${remindTime.eventTitle}' ${moment().add(time, 'ms').fromNow()}.`); - const remindMessage = await new Promise(resolve => { - setTimeout(() => resolve(message.channel.send(`${message.author} you wanted me to remind you of: '${remindTime.eventTitle}'`)), time); - }); - return [preRemind, remindMessage]; + try { + let remindTime = sherlock.parse(remindMe); + let time = remindTime.startDate.getTime() - Date.now(); + let preRemind = await message.channel.send(`I will remind you '${remindTime.eventTitle}' ${moment().add(time, 'ms').fromNow()}.`); + const remindMessage = await new Promise(resolve => { + setTimeout(() => resolve(message.channel.send(`${message.author} you wanted me to remind you of: '${remindTime.eventTitle}'`)), time); + }); + return [preRemind, remindMessage]; + } + catch (err) { + return message.channel.send(":x: Error! Something went wrong! Perhaps you didn't enter a valid time with your data?"); + } } };