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

Contents of /branches/3.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: 5084 byte(s)
chore: add old version archive branches (2.x to 9.x-dev)
1 /**
2 * This file is part of SudoBot.
3 *
4 * Copyright (C) 2021-2022 OSN Inc.
5 *
6 * SudoBot is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU Affero General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * SudoBot is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
15 *
16 * You should have received a copy of the GNU Affero General Public License
17 * along with SudoBot. If not, see <https://www.gnu.org/licenses/>.
18 */
19
20 import { CommandInteraction, GuildMember, Message, User } from 'discord.js';
21 import BaseCommand from '../../utils/structures/BaseCommand';
22 import DiscordClient from '../../client/Client';
23 import CommandOptions from '../../types/CommandOptions';
24 import InteractionOptions from '../../types/InteractionOptions';
25 import MessageEmbed from '../../client/MessageEmbed';
26 import getUser from '../../utils/getUser';
27 import getMember from '../../utils/getMember';
28
29 export default class AvatarCommand extends BaseCommand {
30 supportsInteractions: boolean = true;
31
32 constructor() {
33 super('avatar', 'information', []);
34 }
35
36 async run(client: DiscordClient, msg: Message | CommandInteraction, options: CommandOptions | InteractionOptions) {
37 let fetchUser: boolean = options.isInteraction ? <boolean> options.options.getBoolean('guild-specific') : (options.options.includes('-g') || options.options.includes('--guild'));
38
39 fetchUser ??= false;
40
41 let user: GuildMember | User | null = null;
42
43 if (msg instanceof CommandInteraction && options.isInteraction) {
44 if (fetchUser) {
45 if (options.options.getUser('user'))
46 user = <User> await options.options.getUser('user');
47 else
48 user = <User> msg.member!.user;
49 }
50 else {
51 if (options.options.getMember('user'))
52 user = <GuildMember> await options.options.getMember('user');
53 else
54 user = <GuildMember> msg.member!;
55 }
56 }
57 else if (msg instanceof Message && !options.isInteraction) {
58 if (options.normalArgs[0]) {
59 if (fetchUser) {
60 try {
61 const tempUser = await getUser(client, msg, options);
62
63 if (!tempUser)
64 throw new Error();
65
66 user = tempUser;
67 }
68 catch (e) {
69 console.log(e);
70
71 await msg.reply({
72 embeds: [
73 new MessageEmbed()
74 .setColor('#f14a60')
75 .setDescription(':x: The user doesn\'t exist.')
76 ]
77 });
78
79 return;
80 }
81 }
82 else {
83 try {
84 const tempMember = await getMember(msg, options);
85
86 if (!tempMember)
87 throw new Error();
88
89 user = tempMember;
90 }
91 catch (e) {
92 console.log(e);
93
94 await msg.reply({
95 embeds: [
96 new MessageEmbed()
97 .setColor('#f14a60')
98 .setDescription(':x: The user doesn\'t exist or not a member of this server.')
99 ]
100 });
101
102 return;
103 }
104 }
105 }
106 else {
107 user = fetchUser ? msg.author : msg.member!;
108 }
109 }
110
111 const mainUser = user instanceof GuildMember ? user.user : user;
112
113 await msg.reply({
114 embeds: [
115 new MessageEmbed()
116 .setColor(mainUser!.hexAccentColor ? mainUser!.hexAccentColor! : '#007bff')
117 .setAuthor({
118 name: user instanceof User ? mainUser!.tag : (user?.nickname !== null ? user?.nickname : user.user.tag)!
119 })
120 .setImage(mainUser!.displayAvatarURL({
121 size: 4096
122 }))
123 .setURL(mainUser!.displayAvatarURL({
124 size: 4096
125 }))
126 .addField('Download', `[Click Here](${mainUser!.displayAvatarURL({ size: 4096 })})`)
127 .setFooter({
128 text: `${mainUser!.tag} (${mainUser!.id})`
129 })
130 ]
131 });
132 }
133 }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26