/[sudobot]/branches/2.x/src/commands/information/AvatarCommand.ts
ViewVC logotype

Contents of /branches/2.x/src/commands/information/AvatarCommand.ts

Parent Directory Parent Directory | Revision Log Revision Log


Revision 577 - (show annotations)
Mon Jul 29 18:52:37 2024 UTC (8 months ago) by rakinar2
File MIME type: application/typescript
File size: 4402 byte(s)
chore: add old version archive branches (2.x to 9.x-dev)
1 import { ColorResolvable, CommandInteraction, GuildMember, Message, User } from 'discord.js';
2 import BaseCommand from '../../utils/structures/BaseCommand';
3 import DiscordClient from '../../client/Client';
4 import CommandOptions from '../../types/CommandOptions';
5 import InteractionOptions from '../../types/InteractionOptions';
6 import MessageEmbed from '../../client/MessageEmbed';
7 import e from 'express';
8 import getUser from '../../utils/getUser';
9 import getMember from '../../utils/getMember';
10
11 export default class AvatarCommand extends BaseCommand {
12 supportsInteractions: boolean = true;
13
14 constructor() {
15 super('avatar', 'information', []);
16 }
17
18 async run(client: DiscordClient, msg: Message | CommandInteraction, options: CommandOptions | InteractionOptions) {
19 let fetchUser: boolean = options.isInteraction ? <boolean> options.options.getBoolean('guild-specific') : (options.options.includes('-g') || options.options.includes('--guild'));
20
21 fetchUser ??= false;
22
23 let user: GuildMember | User | null = null;
24
25 if (msg instanceof CommandInteraction && options.isInteraction) {
26 if (fetchUser) {
27 if (options.options.getUser('user'))
28 user = <User> await options.options.getUser('user');
29 else
30 user = <User> msg.member!.user;
31 }
32 else {
33 if (options.options.getMember('user'))
34 user = <GuildMember> await options.options.getMember('user');
35 else
36 user = <GuildMember> msg.member!;
37 }
38 }
39 else if (msg instanceof Message && !options.isInteraction) {
40 if (options.normalArgs[0]) {
41 if (fetchUser) {
42 try {
43 const tempUser = await getUser(client, msg, options);
44
45 if (!tempUser)
46 throw new Error();
47
48 user = tempUser;
49 }
50 catch (e) {
51 console.log(e);
52
53 await msg.reply({
54 embeds: [
55 new MessageEmbed()
56 .setColor('#f14a60')
57 .setDescription(':x: The user doesn\'t exist.')
58 ]
59 });
60
61 return;
62 }
63 }
64 else {
65 try {
66 const tempMember = await getMember(msg, options);
67
68 if (!tempMember)
69 throw new Error();
70
71 user = tempMember;
72 }
73 catch (e) {
74 console.log(e);
75
76 await msg.reply({
77 embeds: [
78 new MessageEmbed()
79 .setColor('#f14a60')
80 .setDescription(':x: The user doesn\'t exist or not a member of this server.')
81 ]
82 });
83
84 return;
85 }
86 }
87 }
88 else {
89 user = fetchUser ? msg.author : msg.member!;
90 }
91 }
92
93 const mainUser = user instanceof GuildMember ? user.user : user;
94
95 await msg.reply({
96 embeds: [
97 new MessageEmbed()
98 .setColor(mainUser!.hexAccentColor ? mainUser!.hexAccentColor! : '#007bff')
99 .setAuthor({
100 name: user instanceof User ? mainUser!.tag : (user?.nickname !== null ? user?.nickname : user.user.tag)!
101 })
102 .setImage(mainUser!.displayAvatarURL({
103 size: 4096
104 }))
105 .setURL(mainUser!.displayAvatarURL({
106 size: 4096
107 }))
108 .addField('Download', `[Click Here](${mainUser!.displayAvatarURL({ size: 4096 })})`)
109 .setFooter({
110 text: `${mainUser!.tag} (${mainUser!.id})`
111 })
112 ]
113 });
114 }
115 }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26