generated from nhcarrigan/template
feat: grant Discord role and post webhook on apotheosis
This commit is contained in:
@@ -7,3 +7,6 @@ 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_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"
|
||||
@@ -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,
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user