Skip to content

Commit 6a5cda2

Browse files
committed
Also update the status for the !claim command
Pull updateStatusEmbed out into a helper function while we're at it, used for changing the status from dormant to available, too. Occupied => dormant doesn't need to update the status since it always adds a new message. Maybe it doesn't need to when someone deletes their question, though..
1 parent 3ff4e46 commit 6a5cda2

File tree

1 file changed

+26
-37
lines changed

1 file changed

+26
-37
lines changed

src/modules/helpchan.ts

Lines changed: 26 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -203,27 +203,9 @@ export class HelpChanModule extends Module {
203203

204204
this.busyChannels.add(msg.channel.id);
205205

206-
let lastMessage = msg.channel.messages.cache
207-
.array()
208-
.reverse()
209-
.find(m => m.author.id === this.client.user?.id);
210-
211-
if (!lastMessage)
212-
lastMessage = (await msg.channel.messages.fetch({ limit: 5 }))
213-
.array()
214-
.reverse()
215-
.find(m => m.author.id === this.client.user?.id);
216-
217206
let embed = this.occupiedEmbed(msg.author);
218207

219-
if (lastMessage) {
220-
// If there is a last message (the available message) by the bot, edit it
221-
await lastMessage.edit(embed);
222-
} else {
223-
// Otherwise, just send a new message
224-
await msg.channel.send(embed);
225-
}
226-
208+
await this.updateStatusEmbed(msg.channel, embed);
227209
await msg.pin();
228210
await this.addCooldown(msg.member, msg.channel);
229211
await this.moveChannel(msg.channel, categories.ongoing);
@@ -292,24 +274,7 @@ export class HelpChanModule extends Module {
292274
);
293275
if (dormant && dormant instanceof TextChannel) {
294276
await this.moveChannel(dormant, categories.ask);
295-
296-
let lastMessage = dormant.messages.cache
297-
.array()
298-
.reverse()
299-
.find(m => m.author.id === this.client.user?.id);
300-
301-
if (!lastMessage)
302-
lastMessage = (await dormant.messages.fetch({ limit: 5 }))
303-
.array()
304-
.find(m => m.author.id === this.client.user?.id);
305-
306-
if (lastMessage) {
307-
// If there is a last message (the dormant message) by the bot, just edit it
308-
await lastMessage.edit(this.AVAILABLE_EMBED);
309-
} else {
310-
// Otherwise, just send a new message
311-
await dormant.send(this.AVAILABLE_EMBED);
312-
}
277+
await this.updateStatusEmbed(dormant, this.AVAILABLE_EMBED);
313278
} else {
314279
const chan = await guild.channels.create(
315280
this.getChannelName(guild),
@@ -369,6 +334,27 @@ export class HelpChanModule extends Module {
369334
}
370335
}
371336

337+
private async updateStatusEmbed(channel: TextChannel, embed: MessageEmbed) {
338+
let lastMessage = channel.messages.cache
339+
.array()
340+
.reverse()
341+
.find(m => m.author.id === this.client.user?.id);
342+
343+
if (!lastMessage)
344+
lastMessage = (await channel.messages.fetch({ limit: 5 }))
345+
.array()
346+
.reverse()
347+
.find(m => m.author.id === this.client.user?.id);
348+
349+
if (lastMessage) {
350+
// If there is a last message (the status message) by the bot, edit it
351+
await lastMessage.edit(embed);
352+
} else {
353+
// Otherwise, just send a new message
354+
await channel.send(embed);
355+
}
356+
}
357+
372358
private async addCooldown(member: GuildMember, channel: TextChannel) {
373359
await member.roles.add(askCooldownRoleId);
374360
const helpUser = new HelpUser();
@@ -463,7 +449,10 @@ export class HelpChanModule extends Module {
463449
.setAuthor(member.displayName, member.user.displayAvatarURL())
464450
.setDescription(msgContent),
465451
);
452+
466453
await toPin.pin();
454+
const occupied = this.updateOccupiedEmbed(msg.author);
455+
await this.updateStatusEmbed(claimedChannel, occupied);
467456
await this.addCooldown(member, claimedChannel);
468457
await this.moveChannel(claimedChannel, categories.ongoing);
469458
await claimedChannel.send(

0 commit comments

Comments
 (0)