@@ -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 )
@@ -98,20 +100,39 @@ export class HelpThreadModule extends Module {
98
100
) ;
99
101
this . updateHelpInfo ( msg . channel ) ;
100
102
let thread = await msg . startThread ( {
101
- name : `[Open] Help ${ msg . member ?. nickname ?? msg . author . username } ` ,
103
+ name : `Help ${ msg . member ?. nickname ?? msg . author . username } ` ,
102
104
autoArchiveDuration : ThreadAutoArchiveDuration . OneDay ,
103
105
} ) ;
104
106
thread . send ( helpThreadWelcomeMessage ( msg . member ! ) ) ;
105
107
await HelpThread . create ( {
106
108
threadId : thread . id ,
107
109
ownerId : msg . author . id ,
110
+ origMessageId : msg . id ,
108
111
} ) . save ( ) ;
109
112
console . log ( `Created a new help thread for` , msg . author ) ;
110
113
}
111
114
112
115
// Used to differentiate automatic archive from bot archive
113
116
manuallyArchivedThreads = new Set < string > ( ) ;
114
117
118
+ @listener ( { event : 'threadUpdate' } )
119
+ async onThreadReopen ( thread : ThreadChannel , ...a : any [ ] ) {
120
+ if (
121
+ ! isHelpThread ( thread ) ||
122
+ ! thread . archived ||
123
+ ( ( await thread . fetch ( ) ) as ThreadChannel ) . archived
124
+ )
125
+ return ;
126
+ const threadData = ( await HelpThread . findOne ( thread . id ) ) ! ;
127
+ if ( ! threadData . origMessageId ) return ;
128
+ const origMessage = await thread . parent . messages . fetch (
129
+ threadData . origMessageId ,
130
+ ) ;
131
+ origMessage . reactions
132
+ . resolve ( closedEmoji )
133
+ ?. users . remove ( this . client . user ! . id ) ;
134
+ }
135
+
115
136
@listener ( { event : 'threadUpdate' } )
116
137
async onThreadExpire ( thread : ThreadChannel ) {
117
138
if (
@@ -123,8 +144,7 @@ export class HelpThreadModule extends Module {
123
144
console . log ( `Help thread expired:` , thread ) ;
124
145
await thread . send ( { embeds : [ threadExpireEmbed ] } ) ;
125
146
this . manuallyArchivedThreads . add ( thread . id ) ;
126
- await thread . setName ( `[Closed] ${ thread . name . replace ( / \[ .+ ?] / , '' ) } ` ) ;
127
- await thread . setArchived ( true ) ;
147
+ await this . archiveThread ( thread ) ;
128
148
}
129
149
130
150
@command ( {
@@ -148,10 +168,7 @@ export class HelpThreadModule extends Module {
148
168
console . log ( `Closing help thread:` , thread ) ;
149
169
await msg . react ( '✅' ) ;
150
170
this . manuallyArchivedThreads . add ( thread . id ) ;
151
- await thread . setName (
152
- `[Closed] ${ thread . name . replace ( / \[ .+ ?] / , '' ) } ` ,
153
- ) ;
154
- await thread . setArchived ( true ) ;
171
+ await this . archiveThread ( thread ) ;
155
172
} else {
156
173
return await sendWithMessageOwnership (
157
174
msg ,
@@ -160,6 +177,16 @@ export class HelpThreadModule extends Module {
160
177
}
161
178
}
162
179
180
+ private async archiveThread ( thread : ThreadChannel ) {
181
+ await thread . setArchived ( true ) ;
182
+ const threadData = ( await HelpThread . findOne ( thread . id ) ) ! ;
183
+ if ( ! threadData . origMessageId ) return ;
184
+ const origMessage = await thread . parent ! . messages . fetch (
185
+ threadData . origMessageId ,
186
+ ) ;
187
+ await origMessage . react ( closedEmoji ) ;
188
+ }
189
+
163
190
private helpInfoLocks = new Map < string , Promise < void > > ( ) ;
164
191
private updateHelpInfo ( channel : TextChannel ) {
165
192
this . helpInfoLocks . set (
@@ -272,7 +299,7 @@ export class HelpThreadModule extends Module {
272
299
HelpThread . update ( thread . id , {
273
300
titleSetTimestamp : Date . now ( ) + '' ,
274
301
} ) ,
275
- msg . channel . setName ( `[Open] ${ username } - ${ title } ` ) ,
302
+ msg . channel . setName ( `${ username } - ${ title } ` ) ,
276
303
] ) ;
277
304
}
278
305
0 commit comments