aboutsummaryrefslogtreecommitdiff
path: root/src/commands/info/inviteInfo.ts
blob: 123063da5435ee2562ad8102c10c4f17739504c8 (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
import { Arg, ArgType, BotCommand, colors, type CommandMessage, type SlashMessage } from '#lib';
import { embedField } from '#lib/common/tags.js';
import { ApplicationCommandOptionType, EmbedBuilder, Invite } from 'discord.js';

export default class InviteInfoCommand extends BotCommand {
	public constructor() {
		super('inviteInfo', {
			aliases: ['invite-info', 'ii'],
			category: 'info',
			description: 'Get info about an invite.',
			usage: ['invite-info [invite]'],
			examples: ['invite-info discord.gg/moulberry'],
			args: [
				{
					id: 'invite',
					description: 'The guild to find information about.',
					type: 'invite',
					prompt: 'What invite would you like to find information about?',
					retry: '{error} Choose a valid invite to find information about.',
					slashType: ApplicationCommandOptionType.String
				}
			],
			slash: true,
			hidden: true,
			clientPermissions: ['EmbedLinks'],
			clientCheckChannel: true,
			userPermissions: []
		});
	}

	public override async exec(message: CommandMessage | SlashMessage, args: { invite: ArgType<'invite' | 'string'> }) {
		const invite = message.util.isSlashMessage(message)
			? ((await Arg.cast('invite', message, args.invite as string)) as ArgType<'invite'>)
			: (args.invite as Invite);

		const inviteInfoEmbed = new EmbedBuilder().setTitle(`Invite to ${invite.guild!.name}`).setColor(colors.default);

		this.generateAboutField(inviteInfoEmbed, invite);
	}

	private generateAboutField(embed: EmbedBuilder, invite: Invite) {
		const about = embedField`
			Code ${invite.code}
			Channel ${invite.channel!.name}`;

		embed.addFields({ name: '» About', value: about });
	}
}