Skip to content

Commit 87ce539

Browse files
committed
wait before locking closed thread to allow reopen
1 parent 01e36d8 commit 87ce539

File tree

1 file changed

+27
-6
lines changed

1 file changed

+27
-6
lines changed

src/modules/helpthread.ts

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ See <#${howToGetHelpChannel}> for info on how to get better help.
8585
// The rate limit for thread naming is 2 time / 10 mins, tracked per thread
8686
const titleSetCooldown = 5 * 60 * 1000;
8787

88+
// Delay before fully closing the thread, in case of hasty closing
89+
const threadCloseDelay = 60 * 1000;
90+
8891
export class HelpThreadModule extends Module {
8992
@listener({ event: 'messageCreate' })
9093
async onNewQuestion(msg: Message) {
@@ -95,7 +98,6 @@ export class HelpThreadModule extends Module {
9598
name: msg.member?.nickname ?? msg.author.username,
9699
autoArchiveDuration: ThreadAutoArchiveDuration.OneDay,
97100
});
98-
thread.setLocked(true);
99101
thread.send(helpThreadWelcomeMessage(msg.member!));
100102
await HelpThread.create({
101103
threadId: thread.id,
@@ -110,8 +112,8 @@ export class HelpThreadModule extends Module {
110112
async onThreadExpire(thread: ThreadChannel) {
111113
if (
112114
!this.isHelpThread(thread) ||
113-
this.manuallyArchivedThreads.delete(thread.id) ||
114-
!((await thread.fetch()) as ThreadChannel).archived
115+
!((await thread.fetch()) as ThreadChannel).archived ||
116+
this.manuallyArchivedThreads.delete(thread.id)
115117
)
116118
return;
117119
await thread.send({ embeds: [threadExpireEmbed] });
@@ -129,13 +131,31 @@ export class HelpThreadModule extends Module {
129131
':warning: This can only be run in a help thread',
130132
);
131133

132-
const threadData = (await HelpThread.findOne(msg.channel.id))!;
134+
let thread: ThreadChannel = msg.channel;
135+
const threadData = (await HelpThread.findOne(thread.id))!;
133136

134137
if (
135138
threadData.ownerId === msg.author.id ||
136139
msg.member?.permissions.has('MANAGE_MESSAGES')
137140
) {
138-
await this.closeThread(msg.channel);
141+
await msg.react('✅');
142+
this.manuallyArchivedThreads.add(thread.id);
143+
await thread.setArchived(true);
144+
thread = (await thread.fetch()) as ThreadChannel;
145+
let archiveTimestamp = thread.archiveTimestamp;
146+
setTimeout(async () => {
147+
thread = (await thread.fetch()) as ThreadChannel;
148+
console.log(
149+
thread.archived,
150+
thread.archivedAt,
151+
archiveTimestamp,
152+
);
153+
if (
154+
thread.archived &&
155+
thread.archiveTimestamp == archiveTimestamp
156+
)
157+
this.closeThread(thread);
158+
}, threadCloseDelay);
139159
} else {
140160
return await sendWithMessageOwnership(
141161
msg,
@@ -145,8 +165,9 @@ export class HelpThreadModule extends Module {
145165
}
146166

147167
private async closeThread(thread: ThreadChannel) {
168+
if (thread.archived) await thread.setArchived(false);
148169
this.manuallyArchivedThreads.add(thread.id);
149-
await thread.setArchived(true);
170+
await thread.edit({ archived: true, locked: true });
150171
await HelpThread.delete(thread.id);
151172
}
152173

0 commit comments

Comments
 (0)