From eef807343b0adf6a46715087a09d07e83bd4a3cb Mon Sep 17 00:00:00 2001 From: Hikari Date: Sat, 7 Mar 2026 14:21:15 -0800 Subject: [PATCH] feat: grant Discord role and post webhook on apotheosis --- apps/api/prod.env | 5 ++++- apps/api/src/routes/apotheosis.ts | 3 ++- apps/api/src/services/webhook.ts | 21 +++++++++++++++++++++ 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/apps/api/prod.env b/apps/api/prod.env index 049594d..0e20818 100644 --- a/apps/api/prod.env +++ b/apps/api/prod.env @@ -6,4 +6,7 @@ DATABASE_URL="op://Environment Variables - Naomi/Elysium/mongo url" ANTI_CHEAT_SECRET="op://Environment Variables - Naomi/Elysium/anti cheat secret" PORT="op://Environment Variables - Naomi/Elysium/port" CORS_ORIGIN="op://Environment Variables - Naomi/Elysium/origin" -DISCORD_MILESTONE_WEBHOOK="op://Environment Variables - Naomi/Elysium/discord milestone webhook" \ No newline at end of file +DISCORD_MILESTONE_WEBHOOK="op://Environment Variables - Naomi/Elysium/discord milestone webhook" +DISCORD_BOT_TOKEN="op://Environment Variables - Naomi/Elysium/discord bot token" +DISCORD_GUILD_ID="op://Environment Variables - Naomi/Elysium/discord guild id" +DISCORD_APOTHEOSIS_ROLE_ID="op://Environment Variables - Naomi/Elysium/discord apotheosis role id" \ No newline at end of file diff --git a/apps/api/src/routes/apotheosis.ts b/apps/api/src/routes/apotheosis.ts index cf35886..579ed08 100644 --- a/apps/api/src/routes/apotheosis.ts +++ b/apps/api/src/routes/apotheosis.ts @@ -7,7 +7,7 @@ import { buildPostApotheosisState, isEligibleForApotheosis, } from "../services/apotheosis.js"; -import { postMilestoneWebhook } from "../services/webhook.js"; +import { grantApotheosisRole, postMilestoneWebhook } from "../services/webhook.js"; export const apotheosisRouter = new Hono(); @@ -62,6 +62,7 @@ apotheosisRouter.post("/", async (context) => { }, }); + void grantApotheosisRole(discordId); void postMilestoneWebhook(discordId, "apotheosis", { prestige: newState.prestige.count, transcendence: newState.transcendence?.count ?? 0, diff --git a/apps/api/src/services/webhook.ts b/apps/api/src/services/webhook.ts index ac57aa0..76d605d 100644 --- a/apps/api/src/services/webhook.ts +++ b/apps/api/src/services/webhook.ts @@ -1,3 +1,24 @@ +const DISCORD_API = "https://discord.com/api/v10"; + +export const grantApotheosisRole = async (discordId: string): Promise => { + const botToken = process.env["DISCORD_BOT_TOKEN"]; + const guildId = process.env["DISCORD_GUILD_ID"]; + const roleId = process.env["DISCORD_APOTHEOSIS_ROLE_ID"]; + + if (!botToken || !guildId || !roleId) { + return; + } + + try { + await fetch(`${DISCORD_API}/guilds/${guildId}/members/${discordId}/roles/${roleId}`, { + method: "PUT", + headers: { Authorization: `Bot ${botToken}` }, + }); + } catch { + // Graceful degradation — role grant failure must not affect the apotheosis + } +}; + type MilestoneType = "prestige" | "transcendence" | "apotheosis"; interface MilestoneCounts {