mirror of
https://github.com/cloudmaker97/FS25-Discord-Bot.git
synced 2025-12-06 00:18:34 +00:00
Resend the embedded message when it's manually deleted by a user #1
This commit is contained in:
parent
8434a32c34
commit
40b1058104
2 changed files with 18 additions and 8 deletions
|
|
@ -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);
|
||||
startDiscordService();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Reference in a new issue