Skip to content

Commit dc930cd

Browse files
committed
feat(birmel): update bot username after election ends
Add updateBotUsername function to change the bot's global username (not just nickname) to match the winning persona after an election. Uses the same naming pattern as nicknames (e.g., "aaron" -> "Bvaron").
1 parent 601df38 commit dc930cd

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

packages/birmel/src/elections/bot-profile.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { getDiscordClient } from "../discord/client.js";
22
import { getDiscordIdForPersona } from "./persona-discord-ids.js";
3+
import { generateNickname } from "./winner.js";
34
import { loggers } from "../utils/index.js";
45

56
const logger = loggers.scheduler.child("elections").child("profile");
@@ -33,6 +34,9 @@ export async function updateBotProfile(personaName: string): Promise<void> {
3334
// Fetch and update bio using REST API
3435
await updateBotBio(discordId);
3536

37+
// Update bot username to match persona
38+
await updateBotUsername(personaName);
39+
3640
logger.info("Bot profile updated to match winner", {
3741
personaName,
3842
discordId,
@@ -84,3 +88,22 @@ async function updateBotBio(winnerDiscordId: string): Promise<void> {
8488
// Bio update failure is not critical, continue without throwing
8589
}
8690
}
91+
92+
async function updateBotUsername(personaName: string): Promise<void> {
93+
const client = getDiscordClient();
94+
if (!client.user) return;
95+
96+
try {
97+
// Generate username using the same pattern as nickname (e.g., "aaron" -> "Bvaron")
98+
const username = generateNickname(personaName);
99+
100+
// Update the bot's username using REST API
101+
await client.rest.patch("/users/@me", {
102+
body: { username },
103+
});
104+
logger.info("Bot username updated", { personaName, username });
105+
} catch (error) {
106+
logger.error("Failed to update bot username", error, { personaName });
107+
// Username update failure is not critical, continue without throwing
108+
}
109+
}

0 commit comments

Comments
 (0)