Pet Command

This commit is contained in:
Dragon Fire
2020-12-25 19:43:43 -05:00
parent 1c181402f3
commit 5608f252ab
13 changed files with 63 additions and 2 deletions
+2 -1
View File
@@ -259,7 +259,7 @@ in the appropriate channel's topic to use it.
## Commands
Total: 572
Total: 573
### Utility:
@@ -669,6 +669,7 @@ Total: 572
* **newspaper:** Creates a fake newspaper with the headline and body of your choice.
* **noise:** Draws an image or a user's avatar but with noise.
* **oil-painting:** Draws an image or a user's avatar but with oil paints.
* **pet:** Pets an image or a user's avatar.
* **pixelize:** Draws an image or a user's avatar pixelized.
* **pokemon-fusion:** Fuses two Generation I Pokémon together.
* **police-tape:** Draws police tape over an image or a user's avatar.
Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

+60
View File
@@ -0,0 +1,60 @@
const Command = require('../../structures/Command');
const { createCanvas, loadImage } = require('canvas');
const GIFEncoder = require('gifencoder');
const request = require('node-superfetch');
const path = require('path');
const { streamToArray } = require('../../util/Util');
const { centerImagePart } = require('../../util/Canvas');
const frameCount = 8;
module.exports = class PetCommand extends Command {
constructor(client) {
super(client, {
name: 'pet',
group: 'edit-image',
memberName: 'pet',
description: 'Pets an image or a user\'s avatar.',
throttling: {
usages: 1,
duration: 30
},
clientPermissions: ['ATTACH_FILES'],
args: [
{
key: 'image',
prompt: 'What image would you like to edit?',
type: 'image',
default: msg => msg.author.displayAvatarURL({ format: 'png', size: 128 })
}
]
});
}
async run(msg, { image }) {
try {
const { body } = await request.get(image);
const data = await loadImage(body);
const encoder = new GIFEncoder(112, 112);
const canvas = createCanvas(112, 112);
const ctx = canvas.getContext('2d');
const stream = encoder.createReadStream();
encoder.start();
encoder.setRepeat(0);
encoder.setDelay(200);
encoder.setQuality(200);
for (let i = 0; i < frameCount; i++) {
const frameID = `frame-${i.toString().padStart(2, '0')}.png`;
const frame = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'pet', frameID));
const { x, y, width, height } = centerImagePart(data, 75, 75, 27, 38);
ctx.drawImage(data, x, y, width, height);
ctx.drawImage(frame, 0, 0);
encoder.addFrame(ctx);
}
encoder.finish();
const buffer = await streamToArray(stream);
return msg.say({ files: [{ attachment: Buffer.concat(buffer), name: 'pet.gif' }] });
} 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": "124.2.1",
"version": "124.3.0",
"description": "Your personal server companion.",
"main": "Xiao.js",
"scripts": {