diff --git a/README.md b/README.md index 763af330..a16f2421 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. @@ -296,6 +296,7 @@ Xiao is a Discord bot coded in JavaScript with * **ifunny:** Draws an image with the iFunny logo. * **illegal:** Makes President Trump make your text illegal. * **invert:** Draws an image or a user's avatar but inverted. +* **kyon-gun:** Draws an image or a user's avatar behind Kyon shooting a gun. * **meme-gen:** Sends a meme with the text and background of your choice. * **minecraft-skin:** Sends the Minecraft skin for a user. * **needs-more-jpeg:** Draws an image or a user's avatar as a low quality JPEG. diff --git a/assets/images/kyon-gun.png b/assets/images/kyon-gun.png new file mode 100644 index 00000000..ad1cdf38 Binary files /dev/null and b/assets/images/kyon-gun.png differ diff --git a/commands/image-edit/kyon-gun.js b/commands/image-edit/kyon-gun.js new file mode 100644 index 00000000..3225f959 --- /dev/null +++ b/commands/image-edit/kyon-gun.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 KyonGunCommand extends Command { + constructor(client) { + super(client, { + name: 'kyon-gun', + aliases: ['kyon-snapped'], + group: 'image-edit', + memberName: 'kyon-gun', + description: 'Draws an image or a user\'s avatar behind Kyon shooting a gun.', + 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', 'kyon-gun.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) - (width / 2), 0, width, base.height); + ctx.drawImage(base, 0, 0); + return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'kyon-gun.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 bf1b3d26..ce47938f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiao", - "version": "98.2.0", + "version": "98.3.0", "description": "Your personal server companion.", "main": "Xiao.js", "scripts": {