Skip to content

Commit 9b38037

Browse files
authored
Merge pull request #189 from tjjfvi/helper-close
Allow helpers to close threads
2 parents 17e47eb + 38730f0 commit 9b38037

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

src/modules/helpthread.ts

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,15 @@ Consider rephrasing the question to maximize your chance of getting a good answe
2929
If you're not sure how, have a look through [StackOverflow's guide on asking a good question](https://stackoverflow.com/help/how-to-ask).
3030
`);
3131

32+
const helperCloseEmbed = (member: GuildMember) =>
33+
new MessageEmbed().setColor(BLOCKQUOTE_GREY).setDescription(`
34+
Because your issue seemed to be resolved, this thread was closed by ${member}.
35+
36+
If your issue is not resolved, **you can post another message here and the thread will automatically re-open**.
37+
38+
*If you have a different question, just ask in <#${generalHelpChannel}>.*
39+
`);
40+
3241
// A zero-width space (necessary to prevent discord from trimming the leading whitespace), followed by a three non-breaking spaces.
3342
const indent = '\u200b\u00a0\u00a0\u00a0';
3443

@@ -141,8 +150,12 @@ export class HelpThreadModule extends Module {
141150
this.manuallyArchivedThreads.delete(thread.id)
142151
)
143152
return;
153+
const threadData = (await HelpThread.findOne(thread.id))!;
144154
console.log(`Help thread expired:`, thread);
145-
await thread.send({ embeds: [threadExpireEmbed] });
155+
await thread.send({
156+
content: `<@${threadData.ownerId}>`,
157+
embeds: [threadExpireEmbed],
158+
});
146159
this.manuallyArchivedThreads.add(thread.id);
147160
await this.archiveThread(thread);
148161
}
@@ -161,12 +174,20 @@ export class HelpThreadModule extends Module {
161174
let thread: ThreadChannel = msg.channel;
162175
const threadData = (await HelpThread.findOne(thread.id))!;
163176

177+
const isOwner = threadData.ownerId === msg.author.id;
178+
164179
if (
165-
threadData.ownerId === msg.author.id ||
180+
isOwner ||
181+
msg.member?.roles.cache.has(trustedRoleId) ||
166182
msg.member?.permissions.has('MANAGE_MESSAGES')
167183
) {
168184
console.log(`Closing help thread:`, thread);
169185
await msg.react('✅');
186+
if (!isOwner)
187+
await msg.channel.send({
188+
content: `<@${threadData.ownerId}>`,
189+
embeds: [helperCloseEmbed(msg.member!)],
190+
});
170191
this.manuallyArchivedThreads.add(thread.id);
171192
await this.archiveThread(thread);
172193
} else {

0 commit comments

Comments
 (0)