Skip to content

Commit de5123c

Browse files
committed
Bugfix: don't mistake any embed for a status embed
When changing the channel status, the bot will update a previous embed if it's in the bottom 5 messages, rather than sending a new message. However, we were detecting *any* embed from the bot, rather than only status messages, so it would also replace playground links, for example. This detects status embeds by comparing their titles. In order to do that, it adds a title to the dormant embed. This isn't *necessary*; the following code would work instead: const isStatusEmbed = (embed: MessageEmbed) => ( embed.title === this.AVAILABLE_EMBED.title || embed.title === this.OCCUPIED_EMBED_BASE.title || embed.description === this.DORMANT_EMBED.description ); However, this way is both cleaner code-wise, and I think it's nice for all the status embeds to have the same format.
1 parent 4816e50 commit de5123c

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/modules/helpchan.ts

+12-2
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ export class HelpChanModule extends Module {
9292
}
9393

9494
DORMANT_EMBED = new MessageEmbed()
95+
.setTitle('💤 Dormant Help Channel')
9596
.setColor(TS_BLUE)
9697
.setDescription(DORMANT_MESSAGE);
9798

@@ -336,16 +337,25 @@ export class HelpChanModule extends Module {
336337
}
337338

338339
private async updateStatusEmbed(channel: TextChannel, embed: MessageEmbed) {
340+
const isStatusEmbed = (embed: MessageEmbed) =>
341+
[
342+
this.AVAILABLE_EMBED.title,
343+
this.OCCUPIED_EMBED_BASE.title,
344+
this.DORMANT_EMBED.title,
345+
].includes(embed.title);
346+
339347
let lastMessage = channel.messages.cache
340348
.array()
341349
.reverse()
342-
.find(m => m.author.id === this.client.user?.id);
350+
.filter(m => m.author.id === this.client.user?.id)
351+
.find(m => m.embeds.some(isStatusEmbed));
343352

344353
if (!lastMessage)
345354
lastMessage = (await channel.messages.fetch({ limit: 5 }))
346355
.array()
347356
.reverse()
348-
.find(m => m.author.id === this.client.user?.id);
357+
.filter(m => m.author.id === this.client.user?.id)
358+
.find(m => m.embeds.some(isStatusEmbed));
349359

350360
if (lastMessage) {
351361
// If there is a last message (the status message) by the bot, edit it

0 commit comments

Comments
 (0)