|
1 | 1 | import { getDiscordClient } from "../discord/client.js"; |
2 | 2 | import { getDiscordIdForPersona } from "./persona-discord-ids.js"; |
| 3 | +import { generateNickname } from "./winner.js"; |
3 | 4 | import { loggers } from "../utils/index.js"; |
4 | 5 |
|
5 | 6 | const logger = loggers.scheduler.child("elections").child("profile"); |
@@ -33,6 +34,9 @@ export async function updateBotProfile(personaName: string): Promise<void> { |
33 | 34 | // Fetch and update bio using REST API |
34 | 35 | await updateBotBio(discordId); |
35 | 36 |
|
| 37 | + // Update bot username to match persona |
| 38 | + await updateBotUsername(personaName); |
| 39 | + |
36 | 40 | logger.info("Bot profile updated to match winner", { |
37 | 41 | personaName, |
38 | 42 | discordId, |
@@ -84,3 +88,22 @@ async function updateBotBio(winnerDiscordId: string): Promise<void> { |
84 | 88 | // Bio update failure is not critical, continue without throwing |
85 | 89 | } |
86 | 90 | } |
| 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