This is a fun command where you can make a Fake Tweet image by using !tweet <your text> , you can also do this by mentioning a friend (!tweet @mention <text>) . Result example- https://ibb.co/RNgPRJw
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});
const jimp = require('jimp');
module.exports = async (event, context) => {
const pfp = context.params.event.mentions.length
? context.params.event.mentions[0].avatar
: context.params.event.author.avatar;
const ID = context.params.event.mentions.length
? context.params.event.mentions[0].id
: context.params.event.author.id;
const author = context.params.event.mentions.length
? context.params.event.mentions[0].username
: context.params.event.author.username;
const hash = context.params.event.mentions.length
? context.params.event.mentions[0].discriminator
: context.params.event.author.discriminator;
let tweet = event.content.split(' ');
if (!tweet[1]) {
return lib.discord.channels['@0.1.1'].messages.create({
channel_id: event.channel_id,
content: `You have to type something!`,
});
}
if (context.params.event.mentions[0]) {
tweet = tweet.slice(2).join(' ');
} else {
tweet = tweet.slice(1).join(' ');
}
kooer = author;
let bannerURL =
'https://media.discordapp.net/attachments/930469924684566541/1025639306032840744/Template_twitter.jpg';
let avatarURL = `https://cdn.discordapp.com/avatars/${ID}/${pfp}.png?size=128`;
let img = await jimp.read(bannerURL);
let avatar = await jimp.read(
event.author.avatar
? avatarURL
: 'https://discord.com/assets/1f0bfc0865d324c2587920a7d80c609b.png'
); // Default to the Discord logo if no avatar supplied
img.resize(916, 720);
avatar.circle();
avatar.resize(127, 127);
img.composite(avatar, 68, 45);
await jimp.loadFont(jimp.FONT_SANS_64_BLACK).then((font) => {
img.print(
font,
216,
65,
{
text: kooer,
alignmentX: jimp.HORIZONTAL_ALIGN_LEFT,
alignmentY: jimp.VERTICAL_ALIGN_TOP,
},
870,
38
);
});
await jimp.loadFont(jimp.FONT_SANS_32_BLACK).then((font) => {
img.print(
font,
68,
180,
{
text: tweet,
alignmentX: jimp.HORIZONTAL_ALIGN_LEFT,
alignmentY: jimp.VERTICAL_ALIGN_TOP,
},
870,
300
);
});
username = `@${author}#${hash}`;
await jimp.loadFont(jimp.FONT_SANS_16_BLACK).then((font) => {
img.print(
font,
218,
127,
{
text: username,
alignmentX: jimp.HORIZONTAL_ALIGN_LEFT,
alignmentY: jimp.VERTICAL_ALIGN_TOP,
},
870,
300
);
});
let buffer = await img.getBufferAsync(jimp.MIME_PNG);
return lib.discord.channels['@0.1.1'].messages.create({
channel_id: event.channel_id,
content: ``,
filename: 'tweet.png',
file: buffer,
});
};