diff --git a/README.md b/README.md index 142e8569..867c15f2 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,7 @@ Xiao is a Discord bot coded in JavaScript with 7. Run `npm i -g pm2` to install PM2. 8. Run `pm2 start Xiao.js --name xiao` to run the bot. -## Commands (332) +## Commands (333) ### Utility: * **eval:** Executes JavaScript code. @@ -280,6 +280,7 @@ Xiao is a Discord bot coded in JavaScript with * **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. +* **brazzers:** Draws an image with the Brazzers logo in the corner. * **circle:** Draws an image or a user's avatar as a circle. * **color:** Sends an image of the color you choose. * **contrast:** Draws an image or a user's avatar but with contrast. diff --git a/assets/images/brazzers.png b/assets/images/brazzers.png new file mode 100644 index 00000000..9ef37ee7 Binary files /dev/null and b/assets/images/brazzers.png differ diff --git a/commands/image-edit/brazzers.js b/commands/image-edit/brazzers.js new file mode 100644 index 00000000..faf49e16 --- /dev/null +++ b/commands/image-edit/brazzers.js @@ -0,0 +1,48 @@ +const Command = require('../../structures/Command'); +const { createCanvas, loadImage } = require('canvas'); +const request = require('node-superfetch'); +const path = require('path'); + +module.exports = class BrazzersCommand extends Command { + constructor(client) { + super(client, { + name: 'brazzers', + group: 'image-edit', + memberName: 'brazzers', + description: 'Draws an image with the Brazzers logo in the corner.', + 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', 'brazzers.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 ratio = base.width / base.height; + const width = data.width / 4; + const height = Math.round(width / ratio); + ctx.drawImage(base, data.width - width, data.height - height, 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: 'brazzers.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 97ecb7ac..eef0d9da 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiao", - "version": "101.1.2", + "version": "101.2.0", "description": "Your personal server companion.", "main": "Xiao.js", "scripts": {