Sora Selfie Command

This commit is contained in:
Daniel Odendahl Jr
2018-09-19 17:35:01 +00:00
parent 6047e1dba1
commit 06c09d3cc0
4 changed files with 50 additions and 2 deletions
+2 -1
View File
@@ -15,7 +15,7 @@ Xiao is a Discord bot coded in JavaScript with
The bot is no longer available for invite. You can self-host the bot, or use her
on the [home server](https://discord.gg/sbMe32W).
## Commands (312)
## Commands (313)
### Utility:
* **eval:** Executes JavaScript code.
@@ -262,6 +262,7 @@ on the [home server](https://discord.gg/sbMe32W).
* **sepia:** Draws an image or a user's avatar in sepia.
* **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.
* **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.
Binary file not shown.

After

Width:  |  Height:  |  Size: 421 KiB

+47
View File
@@ -0,0 +1,47 @@
const Command = require('../../structures/Command');
const { createCanvas, loadImage } = require('canvas');
const request = require('node-superfetch');
const path = require('path');
module.exports = class SoraSelfieCommand extends Command {
constructor(client) {
super(client, {
name: 'sora-selfie',
group: 'image-edit',
memberName: 'sora-selfie',
description: 'Draws an image or a user\'s avatar behind Sora taking a selfie.',
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 base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'sora-selfie.png'));
const { body } = await request.get(image);
const data = await loadImage(body);
const canvas = createCanvas(base.width, base.height);
const ctx = canvas.getContext('2d');
ctx.fillStyle = 'black';
ctx.fillRect(0, 0, base.width, base.height);
const ratio = data.width / data.height;
const width = Math.round(base.height * ratio);
ctx.drawImage(data, (base.width / 2) - (data.width / 2), 0, width, base.height);
ctx.drawImage(base, 0, 0);
return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'sora-selfie.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": "91.6.1",
"version": "91.7.0",
"description": "Your personal server companion.",
"main": "Xiao.js",
"scripts": {