diff --git a/README.md b/README.md index 42c7d744..25e9f75f 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/assets/images/pet/frame_00.png b/assets/images/pet/frame_00.png new file mode 100644 index 00000000..4408b7ed Binary files /dev/null and b/assets/images/pet/frame_00.png differ diff --git a/assets/images/pet/frame_01.png b/assets/images/pet/frame_01.png new file mode 100644 index 00000000..f7a48e9c Binary files /dev/null and b/assets/images/pet/frame_01.png differ diff --git a/assets/images/pet/frame_02.png b/assets/images/pet/frame_02.png new file mode 100644 index 00000000..831b4ea8 Binary files /dev/null and b/assets/images/pet/frame_02.png differ diff --git a/assets/images/pet/frame_03.png b/assets/images/pet/frame_03.png new file mode 100644 index 00000000..831b4ea8 Binary files /dev/null and b/assets/images/pet/frame_03.png differ diff --git a/assets/images/pet/frame_04.png b/assets/images/pet/frame_04.png new file mode 100644 index 00000000..dccab4ed Binary files /dev/null and b/assets/images/pet/frame_04.png differ diff --git a/assets/images/pet/frame_05.png b/assets/images/pet/frame_05.png new file mode 100644 index 00000000..dccab4ed Binary files /dev/null and b/assets/images/pet/frame_05.png differ diff --git a/assets/images/pet/frame_06.png b/assets/images/pet/frame_06.png new file mode 100644 index 00000000..cbb0526c Binary files /dev/null and b/assets/images/pet/frame_06.png differ diff --git a/assets/images/pet/frame_07.png b/assets/images/pet/frame_07.png new file mode 100644 index 00000000..cbb0526c Binary files /dev/null and b/assets/images/pet/frame_07.png differ diff --git a/assets/images/pet/frame_08.png b/assets/images/pet/frame_08.png new file mode 100644 index 00000000..4c553105 Binary files /dev/null and b/assets/images/pet/frame_08.png differ diff --git a/assets/images/pet/frame_09.png b/assets/images/pet/frame_09.png new file mode 100644 index 00000000..65dae359 Binary files /dev/null and b/assets/images/pet/frame_09.png differ diff --git a/commands/edit-image/pet.js b/commands/edit-image/pet.js new file mode 100644 index 00000000..b6b02cf0 --- /dev/null +++ b/commands/edit-image/pet.js @@ -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!`); + } + } +}; diff --git a/package.json b/package.json index 26fb0eec..68109783 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiao", - "version": "124.2.1", + "version": "124.3.0", "description": "Your personal server companion.", "main": "Xiao.js", "scripts": {