aboutsummaryrefslogtreecommitdiff
path: root/src/commands/info/avatar.ts
blob: 7625b6193901cef40077f123a87d867a69d01976 (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
import { GuildMember, MessageEmbed, User } from 'discord.js';
import { BushCommand, BushMessage, BushSlashMessage } from '../../lib';

export default class AvatarCommand extends BushCommand {
	constructor() {
		super('avatar', {
			aliases: ['avatar', 'av'],
			category: 'info',
			description: {
				content: "A command to get a user's avatar",
				usage: 'avatar [user]',
				examples: 'avatar'
			},
			args: [
				{
					id: 'user',
					customType: util.arg.union('member', 'globalUser'),
					prompt: {
						start: 'Who would you like to see the avatar of?',
						retry: '{error} Choose a valid user.',
						optional: true
					}
				}
			],
			clientPermissions: (m) => util.clientSendAndPermCheck(m, ['EMBED_LINKS'], true),
			userPermissions: [],
			slash: true,
			slashOptions: [
				{
					name: 'user',
					description: 'The user you would like to find the avatar of.',
					type: 'USER',
					required: false
				}
			]
		});
	}

	override async exec(message: BushMessage | BushSlashMessage, args: { user: GuildMember | User }): Promise<void> {
		const params: { size: 2048; format: 'png'; dynamic: true } = { size: 2048, format: 'png', dynamic: true };
		const defaultAvatar = `https://cdn.discordapp.com/embed/avatars/${Math.ceil(Math.random() * 6) - 1}.png`;

		const member = (args.user ?? message.member) instanceof GuildMember ? args.user ?? message.member : undefined;
		const user = args.user instanceof GuildMember ? args.user.user : args.user ?? message.author;

		const guildAvatar = member?.avatarURL(params);

		const embed = new MessageEmbed().setTimestamp().setColor(util.colors.default).setTitle(`${user.tag}'s Avatar`);
		guildAvatar
			? embed.setImage(guildAvatar).setThumbnail(user.avatarURL(params) ?? defaultAvatar)
			: embed.setImage(user.avatarURL(params) ?? defaultAvatar);

		await message.util.reply({ embeds: [embed] });
	}
}