From 48dab01d86bf0ceba68af2f67d89dbfb5b0afcfb Mon Sep 17 00:00:00 2001 From: Dragon Fire Date: Sat, 13 Jun 2020 19:15:33 -0400 Subject: [PATCH] Deep Fry Command --- README.md | 3 ++- commands/edit-meme/deep-fry.js | 45 ++++++++++++++++++++++++++++++++++ package.json | 2 +- 3 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 commands/edit-meme/deep-fry.js diff --git a/README.md b/README.md index 83b4335c..aaba4358 100644 --- a/README.md +++ b/README.md @@ -227,7 +227,7 @@ in the appropriate channel's topic to use it. ## Commands -Total: 483 +Total: 484 ### Utility: @@ -636,6 +636,7 @@ Total: 483 * **chi-idea:** Sends a "Daddy, I've got an idea!" Takagi-san meme with the text of your choice. * **cursed-sponge:** Sends a cursed sponge duplicated however many times you want. * **dear-liberals:** Sends a "Dear Liberals" meme with words of your choice. +* **deep-fry:** Draws an image or a user's avatar but deep-fried. * **demotivational:** Draws an image or a user's avatar and the text you specify as a demotivational poster. * **dislike:** Sends an "Everyone Disliked That" meme with the image of your choice. * **distracted-boyfriend:** Draws three user's avatars over the "Distracted Boyfriend" meme. diff --git a/commands/edit-meme/deep-fry.js b/commands/edit-meme/deep-fry.js new file mode 100644 index 00000000..90675217 --- /dev/null +++ b/commands/edit-meme/deep-fry.js @@ -0,0 +1,45 @@ +const Command = require('../../structures/Command'); +const { createCanvas, loadImage } = require('canvas'); +const request = require('node-superfetch'); +const { desaturate, contrast } = require('../../util/Canvas'); + +module.exports = class DeepFryCommand extends Command { + constructor(client) { + super(client, { + name: 'deep-fry', + group: 'edit-meme', + memberName: 'deep-fry', + description: 'Draws an image or a user\'s avatar but deep-fried.', + 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 { 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); + desaturate(ctx, -20, 0, 0, data.width, data.height); + contrast(ctx, 0, 0, data.width, data.height); + const attachment = canvas.toBuffer('image/jpeg', { quality: 0.5 }); + if (Buffer.byteLength(attachment) > 8e+6) return msg.reply('Resulting image was above 8 MB.'); + return msg.say({ files: [{ attachment, name: 'deep-fry.jpeg' }] }); + } catch (err) { + return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); + } + } +}; diff --git a/package.json b/package.json index b4e9a620..00040f6c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiao", - "version": "116.23.0", + "version": "116.24.0", "description": "Your personal server companion.", "main": "Xiao.js", "scripts": {