diff --git a/README.md b/README.md index 869536d1..2af029d8 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ Xiao is a Discord bot coded in JavaScript with The bot is no longer available for invite. You can self-host the bot, or use her on the [home server](https://discord.gg/sbMe32W). -## Commands (312) +## Commands (313) ### Utility: * **eval:** Executes JavaScript code. @@ -262,6 +262,7 @@ on the [home server](https://discord.gg/sbMe32W). * **sepia:** Draws an image or a user's avatar in sepia. * **shields-io-badge:** Creates a badge from shields.io. * **silhouette:** Draws a silhouette of an image or a user's avatar. +* **sora-selfie:** Draws an image or a user's avatar behind Sora taking a selfie. * **tint:** Draws an image or a user's avatar but tinted a specific color. * **to-be-continued:** Draws an image with the "To Be Continued..." arrow. diff --git a/assets/images/sora-selfie.png b/assets/images/sora-selfie.png new file mode 100644 index 00000000..0ff37fd3 Binary files /dev/null and b/assets/images/sora-selfie.png differ diff --git a/commands/image-edit/sora-selfie.js b/commands/image-edit/sora-selfie.js new file mode 100644 index 00000000..c57dc1a2 --- /dev/null +++ b/commands/image-edit/sora-selfie.js @@ -0,0 +1,47 @@ +const Command = require('../../structures/Command'); +const { createCanvas, loadImage } = require('canvas'); +const request = require('node-superfetch'); +const path = require('path'); + +module.exports = class SoraSelfieCommand extends Command { + constructor(client) { + super(client, { + name: 'sora-selfie', + group: 'image-edit', + memberName: 'sora-selfie', + description: 'Draws an image or a user\'s avatar behind Sora taking a selfie.', + 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', 'sora-selfie.png')); + const { body } = await request.get(image); + const data = await loadImage(body); + const canvas = createCanvas(base.width, base.height); + const ctx = canvas.getContext('2d'); + ctx.fillStyle = 'black'; + ctx.fillRect(0, 0, base.width, base.height); + const ratio = data.width / data.height; + const width = Math.round(base.height * ratio); + ctx.drawImage(data, (base.width / 2) - (data.width / 2), 0, width, base.height); + ctx.drawImage(base, 0, 0); + return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'sora-selfie.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 9b2f0366..cf846cb9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiao", - "version": "91.6.1", + "version": "91.7.0", "description": "Your personal server companion.", "main": "Xiao.js", "scripts": {