aboutsummaryrefslogtreecommitdiff
path: root/src/commands/info/inviteInfo.ts
blob: 5df86ad56e2837dbdb04101ffd35cb05f5d93a85 (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
import { Arg, ArgType, BushCommand, clientSendAndPermCheck, colors, type CommandMessage, type SlashMessage } from '#lib';
import { ApplicationCommandOptionType, EmbedBuilder, Invite, PermissionFlagsBits } from 'discord.js';

export default class InviteInfoCommand extends BushCommand {
	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,
			clientPermissions: (m) => clientSendAndPermCheck(m, [PermissionFlagsBits.EmbedLinks], 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 = [`**code:** ${invite.code}`, `**channel:** ${invite.channel!.name}`];

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