diff options
Diffstat (limited to 'index.ts')
| -rw-r--r-- | index.ts | 23 |
1 files changed, 21 insertions, 2 deletions
@@ -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); |
