Skip to content

Commit 6cf3211

Browse files
authored
Merge branch 'master' into green-eggs-and-spam
2 parents 426eaca + 852237b commit 6cf3211

File tree

1 file changed

+30
-12
lines changed

1 file changed

+30
-12
lines changed

src/modules/helpchan.ts

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -364,19 +364,27 @@ export class HelpChanModule extends Module {
364364
else askHelpChannel.send(newMessageText);
365365
}
366366

367+
private async getChannelMember(channel: TextChannel) {
368+
return (
369+
HelpUser.findOneOrFail({
370+
channelId: channel.id,
371+
})
372+
.then(helpUser => {
373+
// Clear from the cache in case they've left the server
374+
channel.guild.members.cache.delete(helpUser.userId);
375+
return channel.guild.members.fetch({
376+
user: helpUser.userId,
377+
});
378+
})
379+
// Do nothing, member left the guild
380+
.catch(() => undefined)
381+
);
382+
}
383+
367384
private async markChannelAsDormant(channel: TextChannel) {
368385
this.busyChannels.add(channel.id);
369386

370-
const memberPromise = HelpUser.findOneOrFail({
371-
channelId: channel.id,
372-
})
373-
.then(helpUser =>
374-
channel.guild.members.fetch({
375-
user: helpUser.userId,
376-
}),
377-
)
378-
// Do nothing, member left the guild
379-
.catch(() => undefined);
387+
const memberPromise = this.getChannelMember(channel);
380388

381389
const pinnedPromise = channel.messages.fetchPinned();
382390

@@ -411,13 +419,23 @@ export class HelpChanModule extends Module {
411419

412420
private async checkDormantPossibilities() {
413421
for (const channel of this.getOngoingChannels()) {
414-
const messages = await channel.messages.fetch();
422+
const [messages, member] = await Promise.all([
423+
channel.messages.fetch(),
424+
this.getChannelMember(channel),
425+
]);
415426

416427
const diff =
417428
Date.now() - (messages.first()?.createdAt.getTime() ?? 0);
418429

419-
if (diff > dormantChannelTimeout)
430+
if (!member) {
431+
await channel.send(
432+
'Asker has left the server, closing channel...',
433+
);
434+
}
435+
if (!member || diff > dormantChannelTimeout) {
420436
await this.markChannelAsDormant(channel);
437+
continue;
438+
}
421439
}
422440
}
423441

0 commit comments

Comments
 (0)