Skip to content

Commit

Permalink
auto close locked threads
Browse files Browse the repository at this point in the history
Signed-off-by: RedGuy12 <paul@reid-family.org>
  • Loading branch information
cobaltt7 committed Aug 7, 2023
1 parent 45fcabd commit a2471c9
Showing 1 changed file with 36 additions and 1 deletion.
37 changes: 36 additions & 1 deletion modules/threads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ defineEvent("threadCreate", async (thread) => {
});
});

defineEvent("threadUpdate", async ({ archived: wasArchived }, thread) => {
defineEvent("threadUpdate", async ({ archived: wasArchived, locked: wasLocked }, thread) => {
if (thread.guild.id !== config.guild.id) return;
const options = getThreadConfig(thread);
if (thread.archived && options.keepOpen) await thread.setArchived(false, "Keeping thread open");
Expand All @@ -270,6 +270,41 @@ defineEvent("threadUpdate", async ({ archived: wasArchived }, thread) => {
}) ?? [],
);
}

if (!wasLocked && thread.locked && thread.parent?.type === ChannelType.GuildForum) {
const date = Date.now() + 43_200_000;
remindersDatabase.data = [
...remindersDatabase.data,
{
channel: thread.id,
date: date,
reminder: undefined,
user: client.user.id,
id: SpecialReminders.CloseThread,
},
];
await queueReminders();

await thread.send({
content: `${constants.emojis.statuses.yes} I’ll close this thread ${time(
Math.round(date / 1_000),
TimestampStyles.RelativeTime,
)}!`,
components: [
{
type: ComponentType.ActionRow,
components: [
{
type: ComponentType.Button,
label: "Cancel",
customId: "close_cancelThreadChange",
style: ButtonStyle.Danger,
},
],
},
],
});
}
});

function getThreadConfig(thread: AnyThreadChannel) {
Expand Down

0 comments on commit a2471c9

Please sign in to comment.