From 0e14ef9a73d2917c694d11bdb155ad141047a15b Mon Sep 17 00:00:00 2001 From: Daniel Odendahl Jr Date: Sun, 14 Oct 2018 13:12:53 +0000 Subject: [PATCH] Square Command --- README.md | 3 ++- commands/image-edit/square.js | 42 +++++++++++++++++++++++++++++++++++ package.json | 2 +- 3 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 commands/image-edit/square.js diff --git a/README.md b/README.md index 23a8dc3e..0a9bf617 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ Xiao is a Discord bot coded in JavaScript with Xiao is no longer available for invite. You can self-host the bot, or use her on the [home server](https://discord.gg/sbMe32W). -## Commands (328) +## Commands (329) ### Utility: * **eval:** Executes JavaScript code. @@ -275,6 +275,7 @@ 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. * **sora-selfie:** Draws an image or a user's avatar behind Sora taking a selfie. +* **square:** Draws an image or a user's avatar as a square. * **thug-life:** Draws "Thug Life" over 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. diff --git a/commands/image-edit/square.js b/commands/image-edit/square.js new file mode 100644 index 00000000..e292fb3d --- /dev/null +++ b/commands/image-edit/square.js @@ -0,0 +1,42 @@ +const Command = require('../../structures/Command'); +const { createCanvas, loadImage } = require('canvas'); +const request = require('node-superfetch'); + +module.exports = class SquareCommand extends Command { + constructor(client) { + super(client, { + name: 'square', + aliases: ['square-avatar', 'square-ava', 'square-image', 'square-img'], + group: 'image-edit', + memberName: 'square', + description: 'Draws an image or a user\'s avatar as a square.', + throttling: { + usages: 1, + duration: 10 + }, + clientPermissions: ['ATTACH_FILES'], + args: [ + { + key: 'image', + prompt: 'Which 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 dimensions = data.width <= data.height ? data.width : data.height; + const canvas = createCanvas(dimensions, dimensions); + const ctx = canvas.getContext('2d'); + ctx.drawImage(data, (canvas.width / 2) - (data.width / 2), (canvas.height / 2) - (data.height / 2)); + return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'square.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 22eecf86..46ea3af4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiao", - "version": "95.0.0", + "version": "95.1.0", "description": "Your personal server companion.", "main": "Xiao.js", "scripts": {