diff --git a/README.md b/README.md index 1e65bf1e..418cb002 100644 --- a/README.md +++ b/README.md @@ -231,12 +231,14 @@ on the [home server](https://discord.gg/sbMe32W). ### Image Manipulation: * **achievement:** Sends a Minecraft achievement with the text of your choice. +* **approved:** Draws an "approved" stamp over an image or a user's avatar. * **be-like-bill:** Sends a "Be Like Bill" meme with the name of your choice. * **color:** Sends an image of the color you choose. * **contrast:** Draws an image or a user's avatar but with contrast. * **create-qr-code:** Converts text to a QR Code. * **demotivational-poster:** Draws an image or a user's avatar and the text you specify as a demotivational poster. * **distort:** Draws an image or a user's avatar but distorted. +* **fire:** Draws a fiery border over an image or a user's avatar. * **frame:** Draws a frame around an image or a user's avatar. * **glitch:** Draws an image or a user's avatar but glitched. * **greyscale:** Draws an image or a user's avatar in greyscale. @@ -251,6 +253,7 @@ on the [home server](https://discord.gg/sbMe32W). * **pixelize:** Draws an image or a user's avatar pixelized. * **pokemon-fusion:** Fuses two Generation I Pokémon together. * **rainbow:** Draws a rainbow over an image or a user's avatar. +* **rejected:** Draws a "rejected" stamp over an image or a user's avatar. * **robohash:** Creates a robot based on the text you provide. * **sepia:** Draws an image or a user's avatar in sepia. * **shields-io-badge:** Creates a badge from shields.io. @@ -261,21 +264,18 @@ on the [home server](https://discord.gg/sbMe32W). ### Avatar Manipulation: * **3000-years:** Draws a user's avatar over Pokémon's "It's been 3000 years" meme. -* **approved:** Draws an "approved" stamp over a user's avatar. * **avatar-fusion:** Draws a a user's avatar over a user's avatar. * **bob-ross:** Draws a user's avatar over Bob Ross' canvas. * **challenger:** Draws a user's avatar over Super Smash Bros.'s "Challenger Approaching" screen. * **dexter:** Draws a user's avatar over the screen of Dexter from Pokémon. * **distracted-boyfriend:** Draws three user's avatars over the "Distracted Boyfriend" meme. * **drakeposting:** Draws two user's avatars over the "Drakeposting" meme. -* **fire:** Draws a fiery border over a user's avatar. * **food-broke:** Draws a user's avatar over the "Food Broke" meme. * **hat:** Draws a hat over a user's avatar. * **he-lives-in-you:** Draws a user's avatar over Simba from The Lion King's reflection. * **i-have-the-power:** Draws a user's avatar over He-Man's face. * **look-at-this-photograph:** Draws a user's avatar over Nickelback's photograph. * **look-what-karen-have:** Draws a user's avatar over Karen's piece of paper. -* **rejected:** Draws a "rejected" stamp over a user's avatar. * **rip:** Draws a user's avatar over a gravestone. * **steam-card:** Draws a user's avatar on a Steam Trading Card. * **steam-now-playing:** Draws a user's avatar and the game of your choice over a Steam "now playing" notification. diff --git a/assets/images/approved.png b/assets/images/approved.png index c9a7308d..812bdfd3 100644 Binary files a/assets/images/approved.png and b/assets/images/approved.png differ diff --git a/assets/images/fire.png b/assets/images/fire.png index 03fcfd8b..c170d1ad 100644 Binary files a/assets/images/fire.png and b/assets/images/fire.png differ diff --git a/assets/images/rejected.png b/assets/images/rejected.png index f8c0ff3d..24d2c2e4 100644 Binary files a/assets/images/rejected.png and b/assets/images/rejected.png differ diff --git a/commands/avatar-edit/approved.js b/commands/avatar-edit/approved.js deleted file mode 100644 index ddcd17d1..00000000 --- a/commands/avatar-edit/approved.js +++ /dev/null @@ -1,45 +0,0 @@ -const Command = require('../../structures/Command'); -const { createCanvas, loadImage } = require('canvas'); -const request = require('node-superfetch'); -const path = require('path'); - -module.exports = class ApprovedCommand extends Command { - constructor(client) { - super(client, { - name: 'approved', - aliases: ['approve'], - group: 'avatar-edit', - memberName: 'approved', - description: 'Draws an "approved" stamp over a user\'s avatar.', - throttling: { - usages: 1, - duration: 10 - }, - clientPermissions: ['ATTACH_FILES'], - args: [ - { - key: 'user', - prompt: 'Which user would you like to edit the avatar of?', - type: 'user', - default: msg => msg.author - } - ] - }); - } - - async run(msg, { user }) { - const avatarURL = user.displayAvatarURL({ format: 'png', size: 512 }); - try { - const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'approved.png')); - const { body } = await request.get(avatarURL); - const avatar = await loadImage(body); - const canvas = createCanvas(avatar.width, avatar.height); - const ctx = canvas.getContext('2d'); - ctx.drawImage(avatar, 0, 0); - ctx.drawImage(base, 0, 0, avatar.width, avatar.height); - return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'approved.png' }] }); - } catch (err) { - return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); - } - } -}; diff --git a/commands/avatar-edit/rejected.js b/commands/avatar-edit/rejected.js deleted file mode 100644 index 5d3553ef..00000000 --- a/commands/avatar-edit/rejected.js +++ /dev/null @@ -1,45 +0,0 @@ -const Command = require('../../structures/Command'); -const { createCanvas, loadImage } = require('canvas'); -const request = require('node-superfetch'); -const path = require('path'); - -module.exports = class RejctedCommand extends Command { - constructor(client) { - super(client, { - name: 'rejected', - aliases: ['reject'], - group: 'avatar-edit', - memberName: 'rejected', - description: 'Draws a "rejected" stamp over a user\'s avatar.', - throttling: { - usages: 1, - duration: 10 - }, - clientPermissions: ['ATTACH_FILES'], - args: [ - { - key: 'user', - prompt: 'Which user would you like to edit the avatar of?', - type: 'user', - default: msg => msg.author - } - ] - }); - } - - async run(msg, { user }) { - const avatarURL = user.displayAvatarURL({ format: 'png', size: 512 }); - try { - const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'rejected.png')); - const { body } = await request.get(avatarURL); - const avatar = await loadImage(body); - const canvas = createCanvas(avatar.width, avatar.height); - const ctx = canvas.getContext('2d'); - ctx.drawImage(avatar, 0, 0); - ctx.drawImage(base, 0, 0, avatar.width, avatar.height); - return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'rejected.png' }] }); - } catch (err) { - return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); - } - } -}; diff --git a/commands/image-edit/approved.js b/commands/image-edit/approved.js new file mode 100644 index 00000000..5a2d6206 --- /dev/null +++ b/commands/image-edit/approved.js @@ -0,0 +1,63 @@ +const Command = require('../../structures/Command'); +const { createCanvas, loadImage } = require('canvas'); +const request = require('node-superfetch'); +const path = require('path'); + +module.exports = class ApprovedCommand extends Command { + constructor(client) { + super(client, { + name: 'approved', + aliases: ['approve'], + group: 'image-edit', + memberName: 'approved', + description: 'Draws an "approved" stamp over an image or a user\'s avatar.', + throttling: { + usages: 1, + duration: 10 + }, + clientPermissions: ['ATTACH_FILES'], + args: [ + { + key: 'image', + prompt: 'What image would you like to edit?', + type: 'image', + default: msg => msg.author.displayAvatarURL({ format: 'png', size: 512 }) + } + ] + }); + } + + async run(msg, { image }) { + try { + const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'approved.png')); + const { body } = await request.get(image); + const data = await loadImage(body); + const canvas = createCanvas(data.width, data.height); + const ctx = canvas.getContext('2d'); + ctx.drawImage(data, 0, 0); + const dataRatio = data.width / data.height; + const baseRatio = base.width / base.height; + let width = data.width; + let height = data.height; + let x = 0; + let y = 0; + if (baseRatio < dataRatio) { + height = data.height; + width = base.width * (height / base.height); + x = (data.width - width) / 2; + y = 0; + } else if (baseRatio > dataRatio) { + width = data.width; + height = base.height * (width / base.width); + x = 0; + y = (data.height - height) / 2; + } + ctx.drawImage(base, x, y, width, height); + const attachment = canvas.toBuffer(); + if (Buffer.byteLength(attachment) > 8e+6) return msg.reply('Resulting image was above 8 MB.'); + return msg.say({ files: [{ attachment, name: 'approved.png' }] }); + } catch (err) { + return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); + } + } +}; diff --git a/commands/image-edit/demotivational-poster.js b/commands/image-edit/demotivational-poster.js index 082504b5..05197f2c 100644 --- a/commands/image-edit/demotivational-poster.js +++ b/commands/image-edit/demotivational-poster.js @@ -36,7 +36,7 @@ module.exports = class DemotivationalPosterCommand extends Command { key: 'image', prompt: 'What image would you like to edit?', type: 'image', - default: msg => msg.author.displayAvatarURL({ format: 'png', size: 1024 }) + default: msg => msg.author.displayAvatarURL({ format: 'png', size: 512 }) } ] }); diff --git a/commands/avatar-edit/fire.js b/commands/image-edit/fire.js similarity index 50% rename from commands/avatar-edit/fire.js rename to commands/image-edit/fire.js index ca7f91c2..9300c2f7 100644 --- a/commands/avatar-edit/fire.js +++ b/commands/image-edit/fire.js @@ -9,9 +9,9 @@ module.exports = class FireCommand extends Command { super(client, { name: 'fire', aliases: ['flame', 'hell'], - group: 'avatar-edit', + group: 'image-edit', memberName: 'fire', - description: 'Draws a fiery border over a user\'s avatar.', + description: 'Draws a fiery border over an image or a user\'s avatar.', throttling: { usages: 1, duration: 10 @@ -19,26 +19,27 @@ module.exports = class FireCommand extends Command { clientPermissions: ['ATTACH_FILES'], args: [ { - key: 'user', - prompt: 'Which user would you like to edit the avatar of?', - type: 'user', - default: msg => msg.author + key: 'image', + prompt: 'What image would you like to edit?', + type: 'image', + default: msg => msg.author.displayAvatarURL({ format: 'png', size: 512 }) } ] }); } - async run(msg, { user }) { - const avatarURL = user.displayAvatarURL({ format: 'png', size: 512 }); + async run(msg, { image }) { try { const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'fire.png')); - const { body } = await request.get(avatarURL); - const avatar = await loadImage(body); - const canvas = createCanvas(avatar.width, avatar.height); + const { body } = await request.get(image); + const data = await loadImage(body); + const canvas = createCanvas(data.width, data.height); const ctx = canvas.getContext('2d'); - drawImageWithTint(ctx, avatar, '#fc671e', 0, 0, avatar.width, avatar.height); - ctx.drawImage(base, 0, 0, avatar.width, avatar.height); - return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'fire.png' }] }); + drawImageWithTint(ctx, data, '#fc671e', 0, 0, data.width, data.height); + ctx.drawImage(base, 0, 0, data.width, data.height); + const attachment = canvas.toBuffer(); + if (Buffer.byteLength(attachment) > 8e+6) return msg.reply('Resulting image was above 8 MB.'); + return msg.say({ files: [{ attachment, name: 'fire.png' }] }); } catch (err) { return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); } diff --git a/commands/image-edit/rejected.js b/commands/image-edit/rejected.js new file mode 100644 index 00000000..db2cbd4a --- /dev/null +++ b/commands/image-edit/rejected.js @@ -0,0 +1,63 @@ +const Command = require('../../structures/Command'); +const { createCanvas, loadImage } = require('canvas'); +const request = require('node-superfetch'); +const path = require('path'); + +module.exports = class RejctedCommand extends Command { + constructor(client) { + super(client, { + name: 'rejected', + aliases: ['reject'], + group: 'image-edit', + memberName: 'rejected', + description: 'Draws a "rejected" stamp over an image or a user\'s avatar.', + throttling: { + usages: 1, + duration: 10 + }, + clientPermissions: ['ATTACH_FILES'], + args: [ + { + key: 'image', + prompt: 'What image would you like to edit?', + type: 'image', + default: msg => msg.author.displayAvatarURL({ format: 'png', size: 512 }) + } + ] + }); + } + + async run(msg, { image }) { + try { + const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'rejected.png')); + const { body } = await request.get(image); + const data = await loadImage(body); + const canvas = createCanvas(data.width, data.height); + const ctx = canvas.getContext('2d'); + ctx.drawImage(data, 0, 0); + const dataRatio = data.width / data.height; + const baseRatio = base.width / base.height; + let width = data.width; + let height = data.height; + let x = 0; + let y = 0; + if (baseRatio < dataRatio) { + height = data.height; + width = base.width * (height / base.height); + x = (data.width - width) / 2; + y = 0; + } else if (baseRatio > dataRatio) { + width = data.width; + height = base.height * (width / base.width); + x = 0; + y = (data.height - height) / 2; + } + ctx.drawImage(base, x, y, width, height); + const attachment = canvas.toBuffer(); + if (Buffer.byteLength(attachment) > 8e+6) return msg.reply('Resulting image was above 8 MB.'); + return msg.say({ files: [{ attachment, name: 'rejected.png' }] }); + } catch (err) { + return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); + } + } +}; diff --git a/package.json b/package.json index f7b6ca9e..522d3fd8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiao", - "version": "91.2.2", + "version": "91.2.3", "description": "Your personal server companion.", "main": "Xiao.js", "scripts": {