22 lines
757 B
TypeScript
22 lines
757 B
TypeScript
import { GuildMember } from "discord.js";
|
|
import { Nation } from "../types";
|
|
import { getActiveCharacter } from "./characters";
|
|
|
|
// 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 === "Capella")) return "Capella";
|
|
if (member.roles.cache.some((r) => r.name === "Procyon")) return "Procyon";
|
|
|
|
return null;
|
|
}
|
|
|
|
export function oppositeNation(nation: Nation): Nation {
|
|
return nation === "Capella" ? "Procyon" : "Capella";
|
|
}
|