mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-03 23:36:43 +02:00
Sora Selfie Command
This commit is contained in:
@@ -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 |
@@ -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
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "xiao",
|
||||
"version": "91.6.1",
|
||||
"version": "91.7.0",
|
||||
"description": "Your personal server companion.",
|
||||
"main": "Xiao.js",
|
||||
"scripts": {
|
||||
|
||||
Reference in New Issue
Block a user