Fixed worker termination and result retrieving
This commit is contained in:
30
bot.js
30
bot.js
@@ -19,22 +19,42 @@ const launch = async () => {
|
||||
await data.sender.send(data.socialChannelID, message)
|
||||
});
|
||||
|
||||
data.client.once('clientReady', async () => {
|
||||
/*data.client.once('clientReady', async () => {
|
||||
await data.sender.send(data.updateChannelID, "I'm now online ! ✅")
|
||||
console.log(`✅ Logged in as ${data.client.user.tag}`);
|
||||
});
|
||||
});*/
|
||||
|
||||
data.client.on('messageCreate', async (message) => {
|
||||
const isGuildOwner = message.guild && message.author.id === message.guild.ownerId;
|
||||
if (message.content === '/login' && isGuildOwner) {
|
||||
await message.reply(data.instagramTokenManager.getOauthUrl());
|
||||
}
|
||||
if (message.content === '/name-card-test' ) {
|
||||
try {
|
||||
const avatarUrl = message.author.displayAvatarURL({ extension: 'png', size: 512 });
|
||||
const username = message.author.displayName;
|
||||
|
||||
const result = await launchWorker({
|
||||
templatePath: data.nameCardTemplate,
|
||||
avatarURL: avatarUrl,
|
||||
username: username,
|
||||
});
|
||||
|
||||
const attachment = new AttachmentBuilder(Buffer.from(result.result), { name: 'namecard.png' });
|
||||
|
||||
const channel = await message.guild.channels.fetch(data.welcomeChannelID);
|
||||
await channel.send({ files: [attachment] });
|
||||
|
||||
} catch (err) {
|
||||
await Logger.error('Failed to generate/send name card:', err);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
data.client.on('guildMemberAdd', async (member) => {
|
||||
try {
|
||||
const avatarUrl = member.user.displayAvatarURL({ extension: 'png', size: 512 });
|
||||
const username = member.displayName;
|
||||
const username = member.displayName || member.user.username;
|
||||
|
||||
const result = await launchWorker({
|
||||
templatePath: data.nameCardTemplate,
|
||||
@@ -43,6 +63,10 @@ const launch = async () => {
|
||||
});
|
||||
|
||||
const attachment = new AttachmentBuilder(Buffer.from(result.result), { name: 'namecard.png' });
|
||||
/*const attachment = new AttachmentBuilder(
|
||||
Buffer.isBuffer(result.result) ? result.result : Buffer.from(result.result),
|
||||
{ name: 'namecard.png' }
|
||||
);*/
|
||||
|
||||
const channel = await member.guild.channels.fetch(data.welcomeChannelID);
|
||||
await channel.send({ files: [attachment] });
|
||||
|
||||
Reference in New Issue
Block a user