Sends an image along with a goodbye message when someone leaves your server.
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});
const jimp = require('jimp');
const avatarBorderColor = 0x5fc2ffff;
const channelID = `${process.env.GOODBYE_CHANNEL_ID}`;
const bannerURL =
'https://cdn.discordapp.com/attachments/890358551682355210/903072140591501392/FreeVector-Rain-Background.jpg';
const avatarURL = `https://cdn.discordapp.com/avatars/${context.params.event.user.id}/${context.params.event.user.avatar}.png?size=128`;
let img = await jimp.read(bannerURL);
let avatar = await jimp.read(
'https://polybit-apps.s3.amazonaws.com/stdlib/users/discord/profile/image.png?1621007833204'
);
if (context.params.event.user.avatar) {
try {
avatar = await jimp.read(avatarURL);
} catch (e) {
console.log(
`Could not read the URL passed to JIMP. Make sure you're not using test data!`
);
}
}
let avatarRing = await new jimp(256 + 32, 256 + 32, avatarBorderColor);
avatarRing.circle();
img.resize(1024, 400);
avatar.circle();
avatar.resize(256, 256);
img.composite(avatarRing, 200 - 150 - 16, 80 - 16);
img.composite(avatar, 200 - 150, 80);
await jimp.loadFont(jimp.FONT_SANS_64_WHITE).then((font) => {
img.print(
font,
350,
150,
{
text: `Goodbye ${context.params.event.user.username} :(`,
},
400,
80
);
});
await jimp.loadFont(jimp.FONT_SANS_32_WHITE).then((font) => {
img.print(
font,
670,
350,
{
text: `Made by ROLD_GOLD`,
},
400,
80
);
});
let buffer = await img.getBufferAsync(jimp.MIME_PNG);
return lib.discord.channels['@0.1.1'].messages.create({
channel_id: `${channelID}`,
content: `Sad to see you go ${context.params.event.user.username}! π`,
filename: 'goodbye.png',
file: buffer,
});