From ac23b1f60e99269711727e92be83231ea9c310e1 Mon Sep 17 00:00:00 2001 From: Mathias Magnusson Date: Sat, 17 Jan 2026 02:05:56 +0100 Subject: automatically add "unsolved"-tag on all new posts --- index.ts | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'index.ts') diff --git a/index.ts b/index.ts index 57e7ba9..acc61fa 100644 --- a/index.ts +++ b/index.ts @@ -1,4 +1,5 @@ import { + ChannelType, Client, CommandInteraction, Events, @@ -7,7 +8,7 @@ import { Routes, } from "discord.js"; -import { buttonCommands, slashCommands } from "./commands.ts"; +import { buttonCommands, ensureUnsolvedTag, slashCommands, getCtfForum } from "./commands.ts"; function requireEnv(key: string): string { let value = process.env[key]; @@ -21,7 +22,7 @@ let token = requireEnv("DISCORD_TOKEN"); let clientId = requireEnv("DISCORD_CLIENT_ID"); let guildId = requireEnv("DISCORD_GUILD_ID"); -let client = new Client({ intents: [GatewayIntentBits.Guilds] }); +let client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages] }); let rest = new REST({ version: "10" }).setToken(token); @@ -72,6 +73,24 @@ client.on(Events.InteractionCreate, async (interaction) => { } }); +client.on(Events.ThreadCreate, async (thread) => { + try { + let forum = await getCtfForum(thread); + + if (thread.ownerId === client.user?.id) + return; + + let tag = await ensureUnsolvedTag(forum); + if (thread.appliedTags.includes(tag.id)) + return; + + await thread.setAppliedTags([...thread.appliedTags, tag.id]); + } catch (error) { + if (error === "done") return; + console.error("Failed to auto-tag thread", error); + } +}); + try { await registerSlashCommands(); await client.login(token); -- cgit v1.2.3