@@ -32,6 +32,8 @@ If you're not sure how, have a look through [StackOverflow's guide on asking a g
32
32
// A zero-width space (necessary to prevent discord from trimming the leading whitespace), followed by a three non-breaking spaces.
33
33
const indent = '\u200b\u00a0\u00a0\u00a0' ;
34
34
35
+ const closedEmoji = '☑️' ;
36
+
35
37
const helpInfo = ( channel : TextChannel ) =>
36
38
new MessageEmbed ( )
37
39
. setColor ( GREEN )
@@ -92,19 +94,38 @@ export class HelpThreadModule extends Module {
92
94
if ( msg . author . id === this . client . user ! . id ) return ;
93
95
this . updateHelpInfo ( msg . channel ) ;
94
96
let thread = await msg . startThread ( {
95
- name : `[Open] Help ${ msg . member ?. nickname ?? msg . author . username } ` ,
97
+ name : `Help ${ msg . member ?. nickname ?? msg . author . username } ` ,
96
98
autoArchiveDuration : ThreadAutoArchiveDuration . OneDay ,
97
99
} ) ;
98
100
thread . send ( helpThreadWelcomeMessage ( msg . member ! ) ) ;
99
101
await HelpThread . create ( {
100
102
threadId : thread . id ,
101
103
ownerId : msg . author . id ,
104
+ origMessageId : msg . id ,
102
105
} ) . save ( ) ;
103
106
}
104
107
105
108
// Used to differentiate automatic archive from bot archive
106
109
manuallyArchivedThreads = new Set < string > ( ) ;
107
110
111
+ @listener ( { event : 'threadUpdate' } )
112
+ async onThreadReopen ( thread : ThreadChannel , ...a : any [ ] ) {
113
+ if (
114
+ ! isHelpThread ( thread ) ||
115
+ ! thread . archived ||
116
+ ( ( await thread . fetch ( ) ) as ThreadChannel ) . archived
117
+ )
118
+ return ;
119
+ const threadData = ( await HelpThread . findOne ( thread . id ) ) ! ;
120
+ if ( ! threadData . origMessageId ) return ;
121
+ const origMessage = await thread . parent . messages . fetch (
122
+ threadData . origMessageId ,
123
+ ) ;
124
+ origMessage . reactions
125
+ . resolve ( closedEmoji )
126
+ ?. users . remove ( this . client . user ! . id ) ;
127
+ }
128
+
108
129
@listener ( { event : 'threadUpdate' } )
109
130
async onThreadExpire ( thread : ThreadChannel ) {
110
131
if (
@@ -115,8 +136,7 @@ export class HelpThreadModule extends Module {
115
136
return ;
116
137
await thread . send ( { embeds : [ threadExpireEmbed ] } ) ;
117
138
this . manuallyArchivedThreads . add ( thread . id ) ;
118
- await thread . setName ( `[Closed] ${ thread . name . replace ( / \[ .+ ?] / , '' ) } ` ) ;
119
- await thread . setArchived ( true ) ;
139
+ await this . archiveThread ( thread ) ;
120
140
}
121
141
122
142
@command ( {
@@ -139,10 +159,7 @@ export class HelpThreadModule extends Module {
139
159
) {
140
160
await msg . react ( '✅' ) ;
141
161
this . manuallyArchivedThreads . add ( thread . id ) ;
142
- await thread . setName (
143
- `[Closed] ${ thread . name . replace ( / \[ .+ ?] / , '' ) } ` ,
144
- ) ;
145
- await thread . setArchived ( true ) ;
162
+ await this . archiveThread ( thread ) ;
146
163
} else {
147
164
return await sendWithMessageOwnership (
148
165
msg ,
@@ -151,6 +168,16 @@ export class HelpThreadModule extends Module {
151
168
}
152
169
}
153
170
171
+ private async archiveThread ( thread : ThreadChannel ) {
172
+ await thread . setArchived ( true ) ;
173
+ const threadData = ( await HelpThread . findOne ( thread . id ) ) ! ;
174
+ if ( ! threadData . origMessageId ) return ;
175
+ const origMessage = await thread . parent ! . messages . fetch (
176
+ threadData . origMessageId ,
177
+ ) ;
178
+ await origMessage . react ( closedEmoji ) ;
179
+ }
180
+
154
181
private helpInfoLocks = new Map < string , Promise < void > > ( ) ;
155
182
private updateHelpInfo ( channel : TextChannel ) {
156
183
this . helpInfoLocks . set (
@@ -263,7 +290,7 @@ export class HelpThreadModule extends Module {
263
290
HelpThread . update ( thread . id , {
264
291
titleSetTimestamp : Date . now ( ) + '' ,
265
292
} ) ,
266
- msg . channel . setName ( `[Open] ${ username } - ${ title } ` ) ,
293
+ msg . channel . setName ( `${ username } - ${ title } ` ) ,
267
294
] ) ;
268
295
}
269
296
0 commit comments