Generate an ID card image based on a user, no setup required. Just do !idcard.
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});
const jimp = require('jimp');
module.exports = async (event, context) => {
if (context.params.event.content.startsWith(`!idcard`)) {
const ID = context.params.event.mentions[0]
? context.params.event.mentions[0].id
: context.params.event.author.id;
const joined = await lib.discord.guilds['@0.1.0'].members.retrieve({
user_id: ID, // required
guild_id: context.params.event.guild_id,
});
let retrieve = await lib.discord.guilds['@0.1.1'].retrieve({
guild_id: `${context.params.event.guild_id}`,
});
let timeout = await lib.utils.kv['@0.1.16'].get({
key: `timeout`,
defaultValue: false,
});
let member = event.author.id;
if (event.mentions.length >= 1) {
member = event.mentions[0].id;
}
let user = await lib.discord.users['@0.1.4'].retrieve({
user_id: member,
});
let img = await jimp.read(
'https://cdn.discordapp.com/attachments/897689463692599340/902207899206549554/a90ffea51f484716d1a0a9ac33d30a96_1.jpg'
);
let avatar_jimp = await jimp.read(user.avatar_url);
avatar_jimp;
avatar_jimp.resize(275, 275);
img.composite(avatar_jimp, 125, 200);
await jimp.loadFont(jimp.FONT_SANS_16_BLACK).then((font) => {
img.print(
font,
515,
255,
{
text: `${user.username}`,
},
300,
2
);
});
await jimp.loadFont(jimp.FONT_SANS_16_BLACK).then((font) => {
img.print(
font,
515,
175,
{
text: `${user.id}`,
},
300,
2
);
});
await jimp.loadFont(jimp.FONT_SANS_32_BLACK).then((font) => {
img.print(
font,
435,
330,
{
text: retrieve.name,
},
300,
2
);
});
await jimp.loadFont(jimp.FONT_SANS_16_BLACK).then((font) => {
img.print(
font,
510,
200,
{
text: `${new Date(joined.joined_at)}`,
},
300,
2
);
});
let buffer = await img.getBufferAsync(jimp.MIME_PNG);
await lib.discord.channels['@0.1.1'].messages.create({
channel_id: event.channel_id,
content: ``,
filename: 'idcard.png',
file: buffer,
});
}
};