Resend the embedded message when it's manually deleted by a user #1

This commit is contained in:
Dennis Heinrich 2024-11-17 01:07:12 +01:00
parent 8434a32c34
commit 40b1058104
2 changed files with 18 additions and 8 deletions

View file

@ -25,10 +25,7 @@ function startDiscordService(): void {
new DiscordService(discordClient);
} catch (exception) {
appLogger.error(`Restarting the discord service, an error occurred`, exception);
} finally {
setTimeout(() => {
startDiscordService();
}, 5000);
}
}

View file

@ -41,15 +41,28 @@ export default class DiscordEmbed {
return;
}
this.discordAppClient.channels.fetch(this.appConfiguration.discord.channelId as Snowflake).then(async channel => {
/**
* Send the initial message to the channel (if the first message id is not set) or
* the message is meanwhile deleted
* @param embedMessage
*/
let sendInitialMessage = (embedMessage: EmbedBuilder) => {
// noinspection JSAnnotator
(channel as TextChannel).send({embeds: [embedMessage]}).then(message => {
this.firstMessageId = message.id;
});
};
this.generateEmbedFromStatusFeed(this.serverStatsFeed).then(embedMessage => {
if (this.firstMessageId !== null) {
(channel as TextChannel).messages.fetch(this.firstMessageId).then(message => {
message.edit({embeds: [embedMessage]});
}).catch(() => {
this.appLogger.warn('Message not found, sending new message');
sendInitialMessage(embedMessage);
});
} else {
(channel as TextChannel).send({embeds: [embedMessage]}).then(message => {
this.firstMessageId = message.id;
})
sendInitialMessage(embedMessage);
}
});
});
@ -95,7 +108,7 @@ export default class DiscordEmbed {
embed.setTimestamp(new Date());
embed.setThumbnail(config.application.serverMapUrl);
let playerListString: string = '';
let playerListString: string;
if(serverStats.getPlayerList().length === 0) {
playerListString = config.translation.discordEmbed.noPlayersOnline;
} else {