Spent too much time trying to fix main thread offload crash
This commit is contained in:
36
bot.js
36
bot.js
@@ -2,6 +2,7 @@ import {data} from "./wwwroot/core/appData.js";
|
||||
import JsonManager from "./wwwroot/core/utils/jsonManager.js";
|
||||
import {Logger} from "./wwwroot/core/logging/logger.js";
|
||||
import {launchWorker} from "./wwwroot/core/namecards/workerLauncher.js";
|
||||
import {AttachmentBuilder} from "discord.js";
|
||||
|
||||
const launch = async () => {
|
||||
try{
|
||||
@@ -18,16 +19,37 @@ 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', (message) => {
|
||||
data.client.on('messageCreate', async (message) => {
|
||||
const isGuildOwner = message.guild && message.author.id === message.guild.ownerId;
|
||||
if (message.content === '/login' && isGuildOwner) {
|
||||
message.reply(data.instagramTokenManager.getOauthUrl());
|
||||
}
|
||||
|
||||
if (message.content === '/name-card-test') {
|
||||
try {
|
||||
const member = message.member;
|
||||
const avatarUrl = message.author.displayAvatarURL({ extension: 'png', size: 512 });
|
||||
const username = member.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({ content: `Welcome ${username}!`, files: [attachment] });
|
||||
console.log('Name card sent!');
|
||||
} catch (err) {
|
||||
console.error('Failed to generate/send name card:', err);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
data.client.on('guildMemberAdd', async member => {
|
||||
@@ -37,7 +59,9 @@ const launch = async () => {
|
||||
avatarURL: member.user.avatarURL,
|
||||
displayName: member.user.displayName,
|
||||
}).then(buffer => {
|
||||
//Send name card here...
|
||||
const attachment = new AttachmentBuilder(buffer, { name: 'namecard.png' });
|
||||
const channel = member.guild.channels.cache.get(data.welcomeChannelID);
|
||||
channel.send({ files: [attachment] });
|
||||
console.log('Name card sent!');
|
||||
}).catch(console.error);
|
||||
} catch (err) {
|
||||
@@ -45,7 +69,7 @@ const launch = async () => {
|
||||
}
|
||||
});
|
||||
|
||||
process.on('SIGINT', async () => {
|
||||
/*process.on('SIGINT', async () => {
|
||||
try {
|
||||
await data.sender.send(data.updateChannelID, "I'm shutting down, now. Bye! 👋")
|
||||
} catch (error) {
|
||||
@@ -54,7 +78,7 @@ const launch = async () => {
|
||||
await data.client.destroy();
|
||||
process.exit(0);
|
||||
}
|
||||
});
|
||||
});*/
|
||||
|
||||
await data.client.login(process.env.DISCORD_TOKEN);
|
||||
data.instagramPoller.start(600000);
|
||||
|
||||
Reference in New Issue
Block a user