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