A fun command that sends a gif of your profile picture or the person you mentioned profile picture getting petted.
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});
const GIFEncoder = require('gif-encoder-2');
const jimp = require('jimp');
if (context.params.event.content.startsWith('-pet-pet')) {
let user_id = context.params.event.mentions[0]
? context.params.event.mentions[0].id
: context.params.event.author.id;
const size = 128;
const frames = 10;
const hand_images = [
'https://cdn.discordapp.com/attachments/888418826180522034/888418941700038666/pet0.gif',
'https://cdn.discordapp.com/attachments/888418826180522034/888418957122478100/pet1.gif',
'https://cdn.discordapp.com/attachments/888418826180522034/888418965146198096/pet2.gif',
'https://cdn.discordapp.com/attachments/888418826180522034/888418974868590662/pet3.gif',
'https://cdn.discordapp.com/attachments/888418826180522034/888418989070483486/pet4.gif',
'https://cdn.discordapp.com/attachments/888418826180522034/888419004853661748/pet5.gif',
'https://cdn.discordapp.com/attachments/888418826180522034/888419016413167666/pet6.gif',
'https://cdn.discordapp.com/attachments/888418826180522034/888419027079299102/pet7.gif',
'https://cdn.discordapp.com/attachments/888418826180522034/888419038156447794/pet8.gif',
'https://cdn.discordapp.com/attachments/888418826180522034/888419046796697661/pet9.gif',
];
const encoder = new GIFEncoder(size, size);
encoder.setDelay(20);
encoder.start();
encoder.setTransparent();
for (let i = 0; i < frames; i++) {
const j = i < frames / 2 ? i : frames - i;
const width = 0.8 + j * 0.02;
const height = 0.8 - j * 0.05;
const offsetX = (1 - width) * 0.5 + 0.1;
const offsetY = 1 - height - 0.08;
let user = await lib.discord.users['@0.1.5'].retrieve({
user_id: user_id,
});
let avatar_url = user.avatar
? `https://cdn.discordapp.com/avatars/${user.id}/${user.avatar}.png`
: `https://discordapp.com/assets/322c936a8c8be1b803cd94861bdfa868.png`;
let base = await new jimp(size, size);
let avatar = await jimp.read(avatar_url);
avatar.circle();
avatar.resize(size * width, size * height);
let handImage = await jimp.read(`${hand_images[i]}`);
base.composite(avatar, offsetX * size, offsetY * size);
base.composite(handImage, 0, 0);
encoder.addFrame(base.bitmap.data);
}
encoder.finish();
const buffer = encoder.out.getData();
await lib.discord.channels['@0.2.0'].messages.create({
channel_id: context.params.event.channel_id,
content: ``,
file: buffer,
filename: `pet-pet.gif`,
});
}