mirror of
https://github.com/cloudmaker97/FS25-Discord-Bot.git
synced 2025-12-06 08:28:33 +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);
|
new DiscordService(discordClient);
|
||||||
} catch (exception) {
|
} catch (exception) {
|
||||||
appLogger.error(`Restarting the discord service, an error occurred`, exception);
|
appLogger.error(`Restarting the discord service, an error occurred`, exception);
|
||||||
} finally {
|
|
||||||
setTimeout(() => {
|
|
||||||
startDiscordService();
|
startDiscordService();
|
||||||
}, 5000);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -41,15 +41,28 @@ export default class DiscordEmbed {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.discordAppClient.channels.fetch(this.appConfiguration.discord.channelId as Snowflake).then(async channel => {
|
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 => {
|
this.generateEmbedFromStatusFeed(this.serverStatsFeed).then(embedMessage => {
|
||||||
if (this.firstMessageId !== null) {
|
if (this.firstMessageId !== null) {
|
||||||
(channel as TextChannel).messages.fetch(this.firstMessageId).then(message => {
|
(channel as TextChannel).messages.fetch(this.firstMessageId).then(message => {
|
||||||
message.edit({embeds: [embedMessage]});
|
message.edit({embeds: [embedMessage]});
|
||||||
|
}).catch(() => {
|
||||||
|
this.appLogger.warn('Message not found, sending new message');
|
||||||
|
sendInitialMessage(embedMessage);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
(channel as TextChannel).send({embeds: [embedMessage]}).then(message => {
|
sendInitialMessage(embedMessage);
|
||||||
this.firstMessageId = message.id;
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
@ -95,7 +108,7 @@ export default class DiscordEmbed {
|
||||||
embed.setTimestamp(new Date());
|
embed.setTimestamp(new Date());
|
||||||
embed.setThumbnail(config.application.serverMapUrl);
|
embed.setThumbnail(config.application.serverMapUrl);
|
||||||
|
|
||||||
let playerListString: string = '';
|
let playerListString: string;
|
||||||
if(serverStats.getPlayerList().length === 0) {
|
if(serverStats.getPlayerList().length === 0) {
|
||||||
playerListString = config.translation.discordEmbed.noPlayersOnline;
|
playerListString = config.translation.discordEmbed.noPlayersOnline;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue