apps/bot/src/lib/structures/ComponentDefinition.ts (view raw)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
export class ComponentDefinition<Id extends string, Args extends string[]> {
public readonly id: Id;
public constructor(id: Id) {
this.id = id;
}
public create(...args: Args): string {
return args.length > 0 ? `${this.id}:${args.join(":")}` : this.id;
}
public parse(customId: string): Args | null {
const parts = customId.split(":");
if (parts[0] !== this.id) return null;
return parts.slice(1) as unknown as Args;
}
}
|