From eb932924ad6c864fc9981dfcdeabe336ad5b195f Mon Sep 17 00:00:00 2001 From: Dragon Fire Date: Thu, 2 Jul 2020 17:36:32 -0400 Subject: [PATCH] Sketch and Charcoal Commands --- README.md | 2 ++ commands/edit-image/charcoal.js | 50 +++++++++++++++++++++++++++++++ commands/edit-image/sketch.js | 53 +++++++++++++++++++++++++++++++++ package.json | 2 +- 4 files changed, 106 insertions(+), 1 deletion(-) create mode 100644 commands/edit-image/charcoal.js create mode 100644 commands/edit-image/sketch.js diff --git a/README.md b/README.md index 9c4fbdac..9a5328fb 100644 --- a/README.md +++ b/README.md @@ -581,6 +581,7 @@ Total: 515 * **blur:** Draws an image or a user's avatar but blurred. * **brazzers:** Draws an image with the Brazzers logo in the corner. (NSFW) * **certificate:** Sends a certificate of excellence with the name and reason of your choice. +* **charcoal:** Draws an image or a user's avatar but with charcoal. * **chinese-restaurant:** Sends a Chinese restaurant sign with the text of your choice. * **circle:** Draws an image or a user's avatar as a circle. * **color:** Sends an image of the color you choose. @@ -621,6 +622,7 @@ Total: 515 * **shields-io-badge:** Creates a badge from shields.io. * **silhouette:** Draws a silhouette of an image or a user's avatar. * **simp:** Draws a "simp" stamp over an image or a user's avatar. +* **sketch:** Draws an image or a user's avatar but sketched. * **snapcode:** Responds with the Snapcode of a Snapchat user. * **speed-limit:** Sends a Speed Limit sign with the limit of your choice. * **spongebob-time-card:** Sends a Spongebob Time Card with the text of your choice. diff --git a/commands/edit-image/charcoal.js b/commands/edit-image/charcoal.js new file mode 100644 index 00000000..ab7af14c --- /dev/null +++ b/commands/edit-image/charcoal.js @@ -0,0 +1,50 @@ +const Command = require('../../structures/Command'); +const gm = require('gm').subClass({ imageMagick: true }); +const request = require('node-superfetch'); + +module.exports = class CharcoalCommand extends Command { + constructor(client) { + super(client, { + name: 'charcoal', + group: 'edit-image', + memberName: 'charcoal', + description: 'Draws an image or a user\'s avatar but with charcoal.', + 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 magik = gm(body); + magik.charcoal(5); + magik.setFormat('png'); + const attachment = await this.toBuffer(magik); + if (Buffer.byteLength(attachment) > 8e+6) return msg.reply('Resulting image was above 8 MB.'); + return msg.say({ files: [{ attachment, name: 'sketch.png' }] }); + } catch (err) { + return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); + } + } + + toBuffer(magik) { + return new Promise((res, rej) => { + magik.toBuffer((err, buffer) => { + if (err) return rej(err); + return res(buffer); + }); + }); + } +}; diff --git a/commands/edit-image/sketch.js b/commands/edit-image/sketch.js new file mode 100644 index 00000000..e5836f1b --- /dev/null +++ b/commands/edit-image/sketch.js @@ -0,0 +1,53 @@ +const Command = require('../../structures/Command'); +const gm = require('gm').subClass({ imageMagick: true }); +const request = require('node-superfetch'); + +module.exports = class SketchCommand extends Command { + constructor(client) { + super(client, { + name: 'sketch', + aliases: ['pencil-sketch'], + group: 'edit-image', + memberName: 'sketch', + description: 'Draws an image or a user\'s avatar but sketched.', + 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 magik = gm(body); + magik.colorspace('gray'); + magik.out('-sketch'); + magik.out('0x20+120'); + magik.setFormat('png'); + const attachment = await this.toBuffer(magik); + if (Buffer.byteLength(attachment) > 8e+6) return msg.reply('Resulting image was above 8 MB.'); + return msg.say({ files: [{ attachment, name: 'sketch.png' }] }); + } catch (err) { + return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); + } + } + + toBuffer(magik) { + return new Promise((res, rej) => { + magik.toBuffer((err, buffer) => { + if (err) return rej(err); + return res(buffer); + }); + }); + } +}; diff --git a/package.json b/package.json index 5364df7d..a887e5b3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiao", - "version": "119.2.0", + "version": "119.3.0", "description": "Your personal server companion.", "main": "Xiao.js", "scripts": {