From 10f2ac3c22ef1d0edba49b8892733fe2defd645e Mon Sep 17 00:00:00 2001 From: Dragon Fire Date: Mon, 29 Jun 2020 13:20:04 -0400 Subject: [PATCH] Magik Command --- README.md | 3 ++- commands/edit-image/magik.js | 51 ++++++++++++++++++++++++++++++++++++ package.json | 13 ++++----- 3 files changed, 60 insertions(+), 7 deletions(-) create mode 100644 commands/edit-image/magik.js diff --git a/README.md b/README.md index e8240eba..cc72c4ff 100644 --- a/README.md +++ b/README.md @@ -227,7 +227,7 @@ in the appropriate channel's topic to use it. ## Commands -Total: 504 +Total: 505 ### Utility: @@ -585,6 +585,7 @@ Total: 504 * **ifunny:** Draws an image with the iFunny logo. * **invert:** Draws an image or a user's avatar but inverted. * **jeopardy-question:** Sends a Jeopardy Question with the text of your choice. +* **magik:** Draws an image or a user's avatar but with liquid rescale from ImageMagick. * **minecraft-skin:** Sends the Minecraft skin for a user. * **mirror:** Draws an image or a user's avatar but mirrored on the X/Y axis (or both). * **needs-more-jpeg:** Draws an image or a user's avatar as a low quality JPEG. diff --git a/commands/edit-image/magik.js b/commands/edit-image/magik.js new file mode 100644 index 00000000..a83e656e --- /dev/null +++ b/commands/edit-image/magik.js @@ -0,0 +1,51 @@ +const Command = require('../../structures/Command'); +const gm = require('gm').subClass({ imageMagick: true }); +const request = require('node-superfetch'); + +module.exports = class MagikCommand extends Command { + constructor(client) { + super(client, { + name: 'magik', + aliases: ['magick', 'liquid-rescale'], + group: 'edit-image', + memberName: 'magik', + description: 'Draws an image or a user\'s avatar but with liquid rescale from ImageMagick.', + 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); + gm.out('-liquid-rescale 75%x75%'); + gm.implode(0.25); + const attachment = await this.toBuffer(gm); + if (Buffer.byteLength(attachment) > 8e+6) return msg.reply('Resulting image was above 8 MB.'); + return msg.say({ files: [{ attachment, name: 'magik.png' }] }); + } catch (err) { + return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); + } + } + + toBuffer(gm) { + return new Promise((res, rej) => { + gm.toBuffer('PNG', (err, buffer) => { + if (err) return rej(err); + return res(buffer); + }); + }); + } +}; diff --git a/package.json b/package.json index ac74fb1b..1dac145e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiao", - "version": "117.0.0", + "version": "117.1.0", "description": "Your personal server companion.", "main": "Xiao.js", "scripts": { @@ -40,27 +40,28 @@ "cloc": "^2.5.1", "common-tags": "^1.8.0", "custom-translate": "^2.2.8", - "didyoumean2": "^4.0.0", + "didyoumean2": "^4.1.0", "discord.js": "^12.2.0", "discord.js-commando": "github:discordjs/Commando", "dotenv": "^8.2.0", "gifencoder": "^2.0.1", - "mathjs": "^7.0.1", - "moment": "^2.26.0", + "gm": "^1.23.1", + "mathjs": "^7.0.2", + "moment": "^2.27.0", "moment-duration-format": "^2.3.2", "moment-timezone": "^0.5.31", "node-superfetch": "^0.1.10", "pokersolver": "^2.1.3", "random-js": "^2.1.0", "rss-parser": "^3.8.0", - "winston": "^3.2.1" + "winston": "^3.3.3" }, "optionalDependencies": { "bufferutil": "^4.0.1", "utf-8-validate": "^5.0.2" }, "devDependencies": { - "eslint": "^7.2.0", + "eslint": "^7.3.1", "eslint-config-amber": "^2.0.3", "eslint-plugin-json": "^2.1.1" },