Yet another Fluxer bot built with TypeScript and Bun
1import { COMMAND_META_KEY } from "@/decorators/command";
2import type { CommandCtor } from "@/types";
3import type { Message } from "@fluxerjs/core";
4
5export function isCommandCtor(val: unknown): val is CommandCtor {
6 return typeof val === "function" && Reflect.hasMetadata(COMMAND_META_KEY, val);
7}
8
9export async function GetMemeberPermission(message: Message) {
10 if (!message.guildId) return null;
11 const guild = message.guild ?? (await message.client.guilds.resolve(message.guildId));
12 if (!guild) return null;
13
14 const member =
15 guild.members.get(message.author.id) ?? (await guild.fetchMember(message.author.id));
16 return member.permissions ?? null;
17}
18
19/***
20 * Helper for getting color palette
21 * @param initial - color palette record/map
22 */
23export class ColorPalette {
24 private colors: Map<string, string>;
25
26 constructor(initial?: Record<string, string>) {
27 // Either custom initial or use default color palette (Catppuccin Mocha)
28 this.colors = new Map(
29 Object.entries(
30 initial ?? {
31 rosewater: "#f5e0dc",
32 flamingo: "#f2cdcd",
33 pink: "#f5c2e7",
34 mauve: "#cba6f7",
35 red: "#f38ba8",
36 maroon: "#eba0ac",
37 peach: "#fab387",
38 yellow: "#f9e2af",
39 green: "#a6e3a1",
40 teal: "#94e2d5",
41 sky: "#89dceb",
42 sapphire: "#74c7ec",
43 blue: "#89b4fa",
44 lavender: "#b4befe",
45 },
46 ),
47 );
48 }
49
50 add(name: string, hex: string): this {
51 this.colors.set(name, hex);
52 return this;
53 }
54
55 get(name: string): string {
56 const color = this.colors.get(name);
57 if (!color) throw new Error(`Color ${name} not found in palette`);
58
59 return color;
60 }
61
62 getOrFallback(name: string, fallback: string): string {
63 return this.colors.get(name) ?? fallback;
64 }
65
66 has(name: string): boolean {
67 return this.colors.has(name);
68 }
69
70 remove(name: string): boolean {
71 return this.colors.delete(name);
72 }
73
74 all(): Record<string, string> {
75 return Object.fromEntries(this.colors);
76 }
77
78 keys(): string[] {
79 return [...this.colors.keys()];
80 }
81
82 values(): string[] {
83 return [...this.colors.values()];
84 }
85}