aboutsummaryrefslogtreecommitdiff
path: root/src/commands/tickets/ticket-!.ts
blob: 6ec4093ca96f73b9c58e9ec34eac1984b7665890 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import { BushCommand, clientSendAndPermCheck, deepWriteable, type SlashMessage } from '#lib';
import { Flag, type ArgumentGeneratorReturn, type SlashOption } from 'discord-akairo';
import { ApplicationCommandOptionType } from 'discord.js';

export const ticketSubcommands = deepWriteable({
	create: {
		description: 'Create a ticket.',
		type: ApplicationCommandOptionType.Subcommand,
		options: [
			{
				name: 'word',
				description: 'What word do you want to highlight?',
				retry: '{error} Enter a valid word.',
				type: ApplicationCommandOptionType.String,
				required: true
			}
		]
	}
} as const);

export default class TicketCommand extends BushCommand {
	public constructor() {
		super('ticket', {
			aliases: ['ticket'],
			category: 'ticket',
			description: 'Manage tickets.',
			usage: ['ticket create <reason>'],
			examples: ['ticket creates very cool ticket'],
			slashOptions: Object.entries(ticketSubcommands).map(
				([subcommand, options]) => ({ name: subcommand, ...options } as SlashOption)
			),
			slash: false,
			channel: 'guild',
			clientPermissions: (m) => clientSendAndPermCheck(m),
			userPermissions: [],
			ownerOnly: true,
			hidden: true
		});
	}

	public override *args(): ArgumentGeneratorReturn {
		const subcommand: keyof typeof ticketSubcommands = yield {
			id: 'subcommand',
			type: Object.keys(ticketSubcommands),
			prompt: {
				start: 'What sub command would you like to use?',
				retry: `{error} Valid subcommands are: ${Object.keys(ticketSubcommands)
					.map((s) => `\`${s}\``)
					.join()}.`
			}
		};

		return Flag.continue(`ticket-${subcommand}`);
	}

	public override async exec() {
		throw new Error('This command is not meant to be executed directly.');
	}

	public override async execSlash(message: SlashMessage, args: { subcommand: string; subcommandGroup?: string }) {
		// manual `Flag.continue`
		const subcommand = this.handler.modules.get(`ticket-${args.subcommandGroup ?? args.subcommand}`)!;
		return subcommand.exec(message, args);
	}
}