diff --git a/commands/analyze/what-anime.js b/commands/analyze/what-anime.js index 14895541..4e8bfced 100644 --- a/commands/analyze/what-anime.js +++ b/commands/analyze/what-anime.js @@ -15,7 +15,7 @@ module.exports = class WhatAnimeCommand extends Command { { key: 'screenshot', prompt: 'What screenshot do you want to scan?', - type: 'image|avatar', + type: 'image', default: msg => msg.author.displayAvatarURL({ format: 'png', size: 512 }) } ] diff --git a/commands/image-edit/contrast.js b/commands/image-edit/contrast.js index 2c66564c..57be4551 100644 --- a/commands/image-edit/contrast.js +++ b/commands/image-edit/contrast.js @@ -19,7 +19,7 @@ module.exports = class ContrastCommand extends Command { { key: 'image', prompt: 'What image would you like to edit?', - type: 'image|avatar', + type: 'image', default: msg => msg.author.displayAvatarURL({ format: 'png', size: 512 }) } ] diff --git a/commands/image-edit/demotivational-poster.js b/commands/image-edit/demotivational-poster.js index 71d683d7..bcc5ecb1 100644 --- a/commands/image-edit/demotivational-poster.js +++ b/commands/image-edit/demotivational-poster.js @@ -35,7 +35,7 @@ module.exports = class DemotivationalPosterCommand extends Command { { key: 'image', prompt: 'What image would you like to edit?', - type: 'image|avatar', + type: 'image', default: msg => msg.author.displayAvatarURL({ format: 'png', size: 1024 }) } ] diff --git a/commands/image-edit/distort.js b/commands/image-edit/distort.js index 88eb557a..c2866e8e 100644 --- a/commands/image-edit/distort.js +++ b/commands/image-edit/distort.js @@ -25,7 +25,7 @@ module.exports = class DistortCommand extends Command { { key: 'image', prompt: 'What image would you like to edit?', - type: 'image|avatar', + type: 'image', default: msg => msg.author.displayAvatarURL({ format: 'png', size: 512 }) } ] diff --git a/commands/image-edit/frame.js b/commands/image-edit/frame.js index acfd7928..54993c8d 100644 --- a/commands/image-edit/frame.js +++ b/commands/image-edit/frame.js @@ -20,7 +20,7 @@ module.exports = class FrameCommand extends Command { { key: 'image', prompt: 'What image would you like to edit?', - type: 'image|avatar', + type: 'image', default: msg => msg.author.displayAvatarURL({ format: 'png', size: 512 }) } ] diff --git a/commands/image-edit/glitch.js b/commands/image-edit/glitch.js index b5193fda..cd6595c5 100644 --- a/commands/image-edit/glitch.js +++ b/commands/image-edit/glitch.js @@ -19,7 +19,7 @@ module.exports = class GlitchCommand extends Command { { key: 'image', prompt: 'What image would you like to edit?', - type: 'image|avatar', + type: 'image', default: msg => msg.author.displayAvatarURL({ format: 'png', size: 512 }) } ] diff --git a/commands/image-edit/greyscale.js b/commands/image-edit/greyscale.js index 348b22b7..165e5304 100644 --- a/commands/image-edit/greyscale.js +++ b/commands/image-edit/greyscale.js @@ -20,7 +20,7 @@ module.exports = class GreyscaleCommand extends Command { { key: 'image', prompt: 'What image would you like to edit?', - type: 'image|avatar', + type: 'image', default: msg => msg.author.displayAvatarURL({ format: 'png', size: 512 }) } ] diff --git a/commands/image-edit/ifunny.js b/commands/image-edit/ifunny.js index 7cb35b25..0c0bf800 100644 --- a/commands/image-edit/ifunny.js +++ b/commands/image-edit/ifunny.js @@ -19,7 +19,7 @@ module.exports = class IfunnyCommand extends Command { { key: 'image', prompt: 'What image would you like to edit?', - type: 'image|avatar', + type: 'image', default: msg => msg.author.displayAvatarURL({ format: 'png', size: 512 }) } ] diff --git a/commands/image-edit/invert.js b/commands/image-edit/invert.js index fb0368e9..9a1624cf 100644 --- a/commands/image-edit/invert.js +++ b/commands/image-edit/invert.js @@ -19,7 +19,7 @@ module.exports = class InvertCommand extends Command { { key: 'image', prompt: 'What image would you like to edit?', - type: 'image|avatar', + type: 'image', default: msg => msg.author.displayAvatarURL({ format: 'png', size: 512 }) } ] diff --git a/commands/image-edit/needs-more-jpeg.js b/commands/image-edit/needs-more-jpeg.js index 349a7e2b..530c1df1 100644 --- a/commands/image-edit/needs-more-jpeg.js +++ b/commands/image-edit/needs-more-jpeg.js @@ -19,7 +19,7 @@ module.exports = class NeedsMoreJpegCommand extends Command { { key: 'image', prompt: 'What image would you like to edit?', - type: 'image|avatar', + type: 'image', default: msg => msg.author.displayAvatarURL({ format: 'png', size: 512 }) }, { diff --git a/commands/image-edit/pixelize.js b/commands/image-edit/pixelize.js index aebc33fd..eacbc95a 100644 --- a/commands/image-edit/pixelize.js +++ b/commands/image-edit/pixelize.js @@ -19,7 +19,7 @@ module.exports = class PixelizeCommand extends Command { { key: 'image', prompt: 'What image would you like to edit?', - type: 'image|avatar', + type: 'image', default: msg => msg.author.displayAvatarURL({ format: 'png', size: 512 }) } ] diff --git a/commands/image-edit/rainbow.js b/commands/image-edit/rainbow.js index 11ea1d26..fb5fcabd 100644 --- a/commands/image-edit/rainbow.js +++ b/commands/image-edit/rainbow.js @@ -20,7 +20,7 @@ module.exports = class RainbowCommand extends Command { { key: 'image', prompt: 'What image would you like to edit?', - type: 'image|avatar', + type: 'image', default: msg => msg.author.displayAvatarURL({ format: 'png', size: 512 }) } ] diff --git a/commands/image-edit/sepia.js b/commands/image-edit/sepia.js index 7d4dab06..ec1152b1 100644 --- a/commands/image-edit/sepia.js +++ b/commands/image-edit/sepia.js @@ -19,7 +19,7 @@ module.exports = class SepiaCommand extends Command { { key: 'image', prompt: 'What image would you like to edit?', - type: 'image|avatar', + type: 'image', default: msg => msg.author.displayAvatarURL({ format: 'png', size: 512 }) } ] diff --git a/commands/image-edit/silhouette.js b/commands/image-edit/silhouette.js index 831ce14a..f6394feb 100644 --- a/commands/image-edit/silhouette.js +++ b/commands/image-edit/silhouette.js @@ -19,7 +19,7 @@ module.exports = class SilhouetteCommand extends Command { { key: 'image', prompt: 'What image would you like to edit?', - type: 'image|avatar', + type: 'image', default: msg => msg.author.displayAvatarURL({ format: 'png', size: 512 }) } ] diff --git a/commands/image-edit/tint.js b/commands/image-edit/tint.js index 53bf2f9a..8f3a61f7 100644 --- a/commands/image-edit/tint.js +++ b/commands/image-edit/tint.js @@ -25,7 +25,7 @@ module.exports = class TintCommand extends Command { { key: 'image', prompt: 'What image would you like to edit?', - type: 'image|avatar', + type: 'image', default: msg => msg.author.displayAvatarURL({ format: 'png', size: 512 }) } ] diff --git a/commands/image-edit/to-be-continued.js b/commands/image-edit/to-be-continued.js index 7b77a316..09224d71 100644 --- a/commands/image-edit/to-be-continued.js +++ b/commands/image-edit/to-be-continued.js @@ -20,7 +20,7 @@ module.exports = class ToBeContinuedCommand extends Command { { key: 'image', prompt: 'What image would you like to edit?', - type: 'image|avatar', + type: 'image', default: msg => msg.author.displayAvatarURL({ format: 'png', size: 512 }) } ] diff --git a/package.json b/package.json index 8a4b6e5f..fc765e06 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiao", - "version": "90.1.0", + "version": "90.1.1", "description": "Your personal server companion.", "main": "Xiao.js", "scripts": { diff --git a/types/avatar.js b/types/avatar.js deleted file mode 100644 index 9b297bf5..00000000 --- a/types/avatar.js +++ /dev/null @@ -1,16 +0,0 @@ -const { ArgumentType } = require('discord.js-commando'); - -module.exports = class AvatarArgumentType extends ArgumentType { - constructor(client) { - super(client, 'avatar'); - } - - validate(value, msg, arg) { - return this.client.registry.types.get('user').validate(value, msg, arg); - } - - async parse(value, msg, arg) { - const user = await this.client.registry.types.get('user').parse(value, msg, arg); - return user.displayAvatarURL({ format: 'png', size: 512 }); - } -}; diff --git a/types/image.js b/types/image.js index 8a1f0114..23aaf4ba 100644 --- a/types/image.js +++ b/types/image.js @@ -5,18 +5,25 @@ module.exports = class ImageArgumentType extends ArgumentType { super(client, 'image'); } - validate(value, msg) { + validate(value, msg, arg) { const attachment = msg.attachments.first(); - if (!attachment || !attachment.height || !attachment.width) return false; - if (attachment.size > 8e+6) return 'Please provide an image under 8 MB.'; - return true; + if (attachment) { + if (!attachment.height || !attachment.width) return false; + if (attachment.size > 8e+6) return 'Please provide an image under 8 MB.'; + return true; + } + return this.client.registry.types.get('user').validate(value, msg, arg); } - parse(value, msg) { - return msg.attachments.first().url; + async parse(value, msg, arg) { + const attachment = msg.attachments.first(); + if (attachment) return attachment.url; + const user = await this.client.registry.types.get('user').parse(value, msg, arg); + return user.displayAvatarURL({ format: 'png', size: 512 }); } - isEmpty(value, msg) { - return msg.attachments.size === 0; + isEmpty(value, msg, arg) { + if (msg.attachments.size) return false; + return this.client.registry.types.get('user').isEmpty(value, msg, arg); } }; diff --git a/util/Canvas.js b/util/Canvas.js index d2d36b2f..ce33ea3b 100644 --- a/util/Canvas.js +++ b/util/Canvas.js @@ -88,9 +88,11 @@ module.exports = class CanvasUtil { } static shortenText(ctx, text, maxWidth) { - let shorten; - if (ctx.measureText(text).width > maxWidth) shorten = true; - while (ctx.measureText(text).width > maxWidth) text = text.substr(0, text.length - 1); + let shorten = false; + while (ctx.measureText(text).width > maxWidth) { + if (!shorten) shorten = true; + text = text.substr(0, text.length - 1); + } return shorten ? `${text}...` : text; } }; diff --git a/util/Util.js b/util/Util.js index 0ea2ec2d..c96446b7 100644 --- a/util/Util.js +++ b/util/Util.js @@ -60,7 +60,7 @@ module.exports = class Util { static today(timeZone) { const now = new Date(); - if (timeZone) now.setUTCHours(now.getUTCHours() + timeZone); + if (timeZone) now.setUTCHours(timeZone); now.setHours(0); now.setMinutes(0); now.setSeconds(0); @@ -74,13 +74,13 @@ module.exports = class Util { return today; } - static async awaitPlayers(msg, max, min, { text = 'join game', time = 30000, dmCheck = false } = {}) { + static async awaitPlayers(msg, max, min, { time = 30000, dmCheck = false } = {}) { const joined = []; joined.push(msg.author.id); const filter = res => { if (res.author.bot) return false; if (joined.includes(res.author.id)) return false; - if (res.content.toLowerCase() !== text.toLowerCase()) return false; + if (res.content.toLowerCase() !== 'join game') return false; joined.push(res.author.id); res.react(SUCCESS_EMOJI_ID || '✅').catch(() => null); return true;