feat: grant Discord role and post webhook on apotheosis

This commit is contained in:
2026-03-07 14:21:15 -08:00
committed by Naomi Carrigan
parent cb5ea9fee6
commit eef807343b
3 changed files with 27 additions and 2 deletions
+4 -1
View File
@@ -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"
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"
+2 -1
View File
@@ -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<HonoEnv>();
@@ -62,6 +62,7 @@ apotheosisRouter.post("/", async (context) => {
},
});
void grantApotheosisRole(discordId);
void postMilestoneWebhook(discordId, "apotheosis", {
prestige: newState.prestige.count,
transcendence: newState.transcendence?.count ?? 0,
+21
View File
@@ -1,3 +1,24 @@
const DISCORD_API = "https://discord.com/api/v10";
export const grantApotheosisRole = async (discordId: string): Promise<void> => {
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 {