import { COMMAND_META_KEY } from "@/decorators/command"; import type { CommandCtor } from "@/types"; import type { Message } from "@fluxerjs/core"; export function isCommandCtor(val: unknown): val is CommandCtor { return typeof val === "function" && Reflect.hasMetadata(COMMAND_META_KEY, val); } export async function GetMemeberPermission(message: Message) { if (!message.guildId) return null; const guild = message.guild ?? (await message.client.guilds.resolve(message.guildId)); if (!guild) return null; const member = guild.members.get(message.author.id) ?? (await guild.fetchMember(message.author.id)); return member.permissions ?? null; } /*** * Helper for getting color palette * @param initial - color palette record/map */ export class ColorPalette { private colors: Map; constructor(initial?: Record) { // Either custom initial or use default color palette (Catppuccin Mocha) this.colors = new Map( Object.entries( initial ?? { rosewater: "#f5e0dc", flamingo: "#f2cdcd", pink: "#f5c2e7", mauve: "#cba6f7", red: "#f38ba8", maroon: "#eba0ac", peach: "#fab387", yellow: "#f9e2af", green: "#a6e3a1", teal: "#94e2d5", sky: "#89dceb", sapphire: "#74c7ec", blue: "#89b4fa", lavender: "#b4befe", }, ), ); } add(name: string, hex: string): this { this.colors.set(name, hex); return this; } get(name: string): string { const color = this.colors.get(name); if (!color) throw new Error(`Color ${name} not found in palette`); return color; } getOrFallback(name: string, fallback: string): string { return this.colors.get(name) ?? fallback; } has(name: string): boolean { return this.colors.has(name); } remove(name: string): boolean { return this.colors.delete(name); } all(): Record { return Object.fromEntries(this.colors); } keys(): string[] { return [...this.colors.keys()]; } values(): string[] { return [...this.colors.values()]; } }