summaryrefslogtreecommitdiff
path: root/index.ts
diff options
context:
space:
mode:
authorMathias Magnusson <mathias@magnusson.space>2026-01-17 02:05:56 +0100
committerMathias Magnusson <mathias@magnusson.space>2026-01-17 02:05:56 +0100
commitac23b1f60e99269711727e92be83231ea9c310e1 (patch)
tree7362ae0f9ae2dffe5e500422572e25e4d521b68a /index.ts
parent3eb6e7729c2fb5461b3f04d5f496084f18906e41 (diff)
downloadchalle-anka-ac23b1f60e99269711727e92be83231ea9c310e1.tar.gz
automatically add "unsolved"-tag on all new posts
Diffstat (limited to 'index.ts')
-rw-r--r--index.ts23
1 files changed, 21 insertions, 2 deletions
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);