tag a user. your and that user's avatar will be inserted into the bonk doge meme. for more, read the intro comment in the script.
/*
INTRO-------------------
run this script in autocode once to create the /bonk command to use this.
this command tags the user to be bonked and sends an image of your profile
picture edited onto the bonk doge, hitting the user that you tagged.
be careful though, the message contains a link to the bonk command, so you might
get bonked back pretty quick haha
METHODS-----------------
with jimp you can edit images pretty easily so maybe how i did it is
self-explanatory and you can tweak this to your liking for other memes too.
otherwise look at jimp's documentation for more image manipulation methods.
*/
console.time(); //accurate timestamps
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});
const jimp = require('jimp');
const event = context.params.event;
//the id of the command gets stored here to enable the link to the command
//in the sent message to quickly let users use the command again
let bonkID = await lib.keyvalue.store['@0.1.16'].get({
key: `bonkID`,
defaultValue: '0'
});
//check íf bonk command needs to be created
if (bonkID == '0') {
console.log(`creating the /bonk command!`);
let command = await lib.discord.commands['@0.0.0'].create({
"name": "bonk",
"description": "bonk someone",
"options": [
{
"type": 6,
"name": "user",
"description": "this user needs to be hit",
"required": true
}
]
});
await lib.keyvalue.store['@0.1.16'].set({
key: `bonkID`,
value: command.id
});
console.log('id of command is ' + command.id);
return
}
//START SCRIPT------------------------------------------------------------------
let userID = event.member? event.member.user.id : event.user.id;
let victimID = event.data.options[0].value;
//this part needs to happen early here because the token is only valid for 3s
console.log(`acknowledging interaction`);
await lib.discord.interactions['@1.0.1'].responses.create({
token: `${context.params.event.token}`,
content: `<@${victimID}> bonk incoming, prepare yourself...`,
response_type: 'CHANNEL_MESSAGE_WITH_SOURCE'
});
//get user objects for avatar urls
let user = await lib.discord.users['@0.2.1'].retrieve({
user_id: userID,
});
let victim = await lib.discord.users['@0.2.1'].retrieve({
user_id: victimID,
});
//background image
let whitebg = 'https://cdn.discordapp.com/attachments/873849829112045588/1021336971718701066/bonkbg.png'
let img = await jimp.read(whitebg);
//layer 1
let victimpfp = await jimp.read(victim.avatar_url);
victimpfp.circle();
victimpfp.resize(90, 90);
img.composite(victimpfp, 198, 51);
//layer 2
let bonkurl = `https://cdn.discordapp.com/attachments/873849829112045588/1021336997127786546/bonk.png`;
let bonk = await jimp.read(bonkurl);
img.composite(bonk, 0, 0);
//layer 3
let userpfp = await jimp.read(user.avatar_url);
userpfp.circle();
userpfp.resize(90, 90);
img.composite(userpfp, 69, 3);
//buffer image
let buffer = await img.getBufferAsync(jimp.MIME_PNG);
//send image
console.log(`sending image`);
await lib.discord.channels['@0.3.2'].messages.create({
channel_id: event.channel_id ,
content: ``,
attachments: [
{
filename: `bonked.png`,
file: Buffer.from(buffer),
}
]
});
console.log(`updating initial response`);
await lib.discord.interactions['@1.0.1'].responses.update({
token: `${event.token}`,
content: `<@${victimID}> `,
});