54 lines
No EOL
1.4 KiB
TypeScript
54 lines
No EOL
1.4 KiB
TypeScript
import { GuildMember } from "discord.js";
|
|
import { Nation } from "../types";
|
|
import { getActiveCharacter } from "./characters";
|
|
|
|
export const NATION_UNICODE: Record<string, string> = {
|
|
Capella: "🔴",
|
|
Procyon: "🔵",
|
|
};
|
|
|
|
export const NATION_KEY: Record<Nation, "capella" | "procyon"> = {
|
|
[Nation.Capella]: "capella",
|
|
[Nation.Procyon]: "procyon",
|
|
};
|
|
|
|
export const NATION_FROM_KEY: Record<"capella" | "procyon", Nation> = {
|
|
"capella": Nation.Capella,
|
|
"procyon": Nation.Procyon,
|
|
};
|
|
|
|
export const Nations = {
|
|
all(): Nation[] {
|
|
return [Nation.Capella, Nation.Procyon];
|
|
},
|
|
|
|
key(nation: Nation): "capella" | "procyon" {
|
|
return NATION_KEY[nation];
|
|
},
|
|
|
|
fromKey(key: "capella" | "procyon"): Nation {
|
|
return NATION_FROM_KEY[key];
|
|
},
|
|
|
|
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;
|
|
},
|
|
|
|
unicode(nation: Nation): string {
|
|
return NATION_UNICODE[nation] ?? "";
|
|
},
|
|
} |