all repos — stealth-developers @ 4f5dd279f3b91bc869c6255b69bfe4d5d05c5f21

apps/bot/src/lib/structures/ModalDefinition.ts (view raw)

 1
 2
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
export class ModalDefinition<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;
	}
}