diff --git a/README.md b/README.md index 9f6f8ca3..308ba121 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 (301) +## Commands (302) ### Utility: * **eval**: Executes JavaScript code. @@ -251,6 +251,7 @@ on the [home server](https://discord.gg/sbMe32W). * **shields-io-badge**: Creates a badge from shields.io. * **silhouette**: Draws a silhouette of an image or a user's avatar. * **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. ### Avatar Manipulation: diff --git a/assets/images/to-be-continued.png b/assets/images/to-be-continued.png new file mode 100644 index 00000000..02812c75 Binary files /dev/null and b/assets/images/to-be-continued.png differ diff --git a/commands/image-edit/to-be-continued.js b/commands/image-edit/to-be-continued.js new file mode 100644 index 00000000..c6b86d2a --- /dev/null +++ b/commands/image-edit/to-be-continued.js @@ -0,0 +1,49 @@ +const Command = require('../../structures/Command'); +const { createCanvas, loadImage } = require('canvas'); +const request = require('node-superfetch'); +const path = require('path'); +const { sepia } = require('../../util/Canvas'); + +module.exports = class ToBeContinuedCommand extends Command { + constructor(client) { + super(client, { + name: 'to-be-continued', + group: 'image-edit', + memberName: 'to-be-continued', + description: 'Draws an image with the "To Be Continued..." arrow.', + throttling: { + usages: 1, + duration: 10 + }, + clientPermissions: ['ATTACH_FILES'], + args: [ + { + key: 'image', + prompt: 'What image would you like to edit?', + type: 'image|avatar', + default: msg => msg.author.displayAvatarURL({ format: 'png', size: 512 }) + } + ] + }); + } + + async run(msg, { image }) { + try { + const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'to-be-continued.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); + sepia(ctx, 0, 0, data.width, data.height); + const ratio = base.width / base.height; + const width = canvas.width / 2; + ctx.drawImage(base, canvas.width - base.width, canvas.height - base.height, width, Math.round(width / ratio)); + 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: 'to-be-continued.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 61c3396e..c1bd6355 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiao", - "version": "85.11.1", + "version": "85.12.0", "description": "Your personal server companion.", "main": "Xiao.js", "scripts": {