Square Command

This commit is contained in:
Daniel Odendahl Jr
2018-10-14 13:12:53 +00:00
parent 8bc0fb2457
commit 0e14ef9a73
3 changed files with 45 additions and 2 deletions
+2 -1
View File
@@ -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.
+42
View File
@@ -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!`);
}
}
};
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "xiao",
"version": "95.0.0",
"version": "95.1.0",
"description": "Your personal server companion.",
"main": "Xiao.js",
"scripts": {