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

Contents of /branches/8.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: 4614 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-2023 OSN Developers.
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 { EmbedBuilder, GuildMember, SlashCommandBuilder, User } from "discord.js";
21 import Command, { ArgumentType, BasicCommandContext, CommandMessage, CommandReturn, ValidationRule } from "../../core/Command";
22 import { logError } from "../../utils/Logger";
23
24 export default class AvatarCommand extends Command {
25 public readonly name = "avatar";
26 public readonly validationRules: ValidationRule[] = [
27 {
28 types: [ArgumentType.User],
29 name: "user",
30 optional: true,
31 errors: {
32 "type:invalid": "Invalid user given",
33 "entity:null": "That user could not be found!"
34 },
35 entity: {
36 notNull: true
37 }
38 }
39 ];
40 public readonly permissions = [];
41 public readonly aliases = ["avt", "av", "pfp", "gav", "gavatar", "gavt", "gpfp"];
42
43 public readonly description = "Shows your or someone else's avatar.";
44 public readonly slashCommandBuilder = new SlashCommandBuilder()
45 .addUserOption(option => option.setName("user").setDescription("The target user"))
46 .addBooleanOption(option =>
47 option
48 .setName("global")
49 .setDescription("Specify whether the system should fetch the global user avatar instead of guild-only avatar")
50 );
51
52 async execute(message: CommandMessage, context: BasicCommandContext): Promise<CommandReturn> {
53 await this.deferIfInteraction(message);
54
55 const user: User =
56 (context.isLegacy ? context.parsedNamedArgs.user : context.options.getUser("user")) ?? message.member!.user;
57 let member: GuildMember | undefined;
58
59 if (!(context.isLegacy ? context.argv[0].startsWith("g") : context.options.getBoolean("global") ?? false)) {
60 try {
61 member = user
62 ? message.guild!.members.cache.get(user.id) ?? (await message.guild!.members.fetch(user.id))
63 : (message.member! as GuildMember);
64 } catch (e) {
65 logError(e);
66 }
67 }
68
69 await this.deferredReply(message, {
70 embeds: [
71 new EmbedBuilder()
72 .setColor(user!.hexAccentColor ?? "#007bff")
73 .setAuthor({
74 name: member?.user.username ?? user!.username
75 })
76 .setImage(
77 member?.displayAvatarURL({
78 size: 4096,
79 forceStatic: false
80 }) ??
81 user!.displayAvatarURL({
82 size: 4096,
83 forceStatic: false
84 })
85 )
86 .setURL(
87 member?.displayAvatarURL({
88 size: 4096,
89 forceStatic: false
90 }) ??
91 user!.displayAvatarURL({
92 size: 4096,
93 forceStatic: false
94 })
95 )
96 .addFields({
97 name: "Download",
98 value: `[Click Here](${
99 member?.displayAvatarURL({
100 size: 4096,
101 forceStatic: false
102 }) ??
103 user!.displayAvatarURL({
104 size: 4096,
105 forceStatic: false
106 })
107 })`
108 })
109 .setFooter({
110 text: `${user!.username} (${user!.id})`
111 })
112 ]
113 });
114 }
115 }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26