import { GuildMember } from "discord.js"; import { Nation } from "../types"; import { getActiveCharacter } from "./characters"; export const NATION_UNICODE: Record = { Capella: "🔴", Procyon: "🔵", }; export const NATION_KEY: Record = { [Nation.Capella]: "capella", [Nation.Procyon]: "procyon", }; export const NATION_FROM_KEY: Record<"capella" | "procyon", Nation> = { "capella": Nation.Capella, "procyon": Nation.Procyon, }; export function nationKey(nation: Nation): "capella" | "procyon" { return NATION_KEY[nation]; } // Resolve a user's nation — character nation takes priority over Discord role export function resolveNation(member: GuildMember, userKey: string | null): Nation | null { // 1. Active character's nation if (userKey) { const char = getActiveCharacter(userKey); if (char) return char.nation; } // 2. Discord role fallback if (member.roles.cache.some((r) => r.name === Nation.Capella)) return Nation.Capella; if (member.roles.cache.some((r) => r.name === Nation.Procyon)) return Nation.Procyon; return null; } export function oppositeNation(nation: Nation): Nation { return nation === Nation.Capella ? Nation.Procyon : Nation.Capella; } export const Nations = { key(nation: Nation): "capella" | "procyon" { return NATION_KEY[nation]; }, resolve(member: GuildMember, userKey: string|null): Nation | null { // 1. Active character's nation if (userKey) { const char = getActiveCharacter(userKey); if (char) return char.nation; } // 2. Discord role fallback if (member.roles.cache.some((r) => r.name === Nation.Capella)) return Nation.Capella; if (member.roles.cache.some((r) => r.name === Nation.Procyon)) return Nation.Procyon; return null; }, opposite(nation: Nation): Nation { return nation === Nation.Capella ? Nation.Procyon : Nation.Capella; }, }