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

Annotation of /branches/8.x/src/commands/information/EmojiCommand.ts

Parent Directory Parent Directory | Revision Log Revision Log


Revision 577 - (hide annotations)
Mon Jul 29 18:52:37 2024 UTC (8 months ago) by rakinar2
File MIME type: application/typescript
File size: 5609 byte(s)
chore: add old version archive branches (2.x to 9.x-dev)
1 rakinar2 577 /**
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 { formatDistanceToNowStrict } from "date-fns";
21     import { EmbedBuilder, SlashCommandBuilder, parseEmoji } from "discord.js";
22     import Command, { ArgumentType, BasicCommandContext, CommandMessage, CommandReturn, ValidationRule } from "../../core/Command";
23    
24     export default class EmojiCommand extends Command {
25     public readonly name = "emoji";
26     public readonly validationRules: ValidationRule[] = [
27     {
28     name: "emoji",
29     types: [ArgumentType.String],
30     errors: {
31     required: "Please specify a server-based emoji!",
32     "type:invalid": "Invalid emoji specified"
33     }
34     }
35     ];
36     public readonly permissions = [];
37     public readonly description = "Shows information about a server-based emoji.";
38     public readonly slashCommandBuilder = new SlashCommandBuilder().addStringOption(option =>
39     option.setName("emoji").setDescription("The target emoji").setRequired(true)
40     );
41    
42     async execute(message: CommandMessage, context: BasicCommandContext): Promise<CommandReturn> {
43     const emojiString = context.isLegacy ? context.parsedNamedArgs.emoji : context.options.getString("emoji", true);
44     const emojiSubString =
45     emojiString.startsWith("<:") && emojiString.endsWith(">")
46     ? emojiString.substring(2, emojiString.length - 1)
47     : emojiString;
48    
49     const emoji = await this.client.emojis.cache.find(
50     e => e.name === emojiSubString || e.identifier === emojiSubString || e.id === emojiSubString
51     );
52    
53     if (!emoji) {
54     if ((emojiString.startsWith("<:") && emojiString.endsWith(">")) || /\d+/g.test(emojiString)) {
55     const parsedEmoji =
56     emojiString.startsWith("<:") && emojiString.endsWith(">")
57     ? parseEmoji(emojiString)
58     : { animated: undefined, id: emojiString, name: undefined };
59    
60     if (!parsedEmoji) {
61     await this.error(message, "Invalid emoji specified");
62     return;
63     }
64    
65     await message.reply({
66     embeds: [
67     new EmbedBuilder()
68     .setColor("#007bff")
69     .setAuthor({
70     name: parsedEmoji.name ?? "Unknown Emoji",
71     iconURL: `https://cdn.discordapp.com/emojis/${parsedEmoji.id}`
72     })
73     .setFields(
74     {
75     name: "Animated",
76     value:
77     parsedEmoji.animated !== undefined
78     ? parsedEmoji.animated
79     ? "Yes"
80     : "No"
81     : "*The system could not load enough information*"
82     },
83     {
84     name: "Download",
85     value: `[Click Here](https://cdn.discordapp.com/emojis/${parsedEmoji.id})`
86     }
87     )
88     .setThumbnail(`https://cdn.discordapp.com/emojis/${parsedEmoji.id}`)
89     .setFooter({
90     text: `ID: ${parsedEmoji.id}`
91     })
92     ]
93     });
94     } else {
95     await message.reply({
96     embeds: [new EmbedBuilder().setColor("#f14a60").setDescription("No emoji found or not a guild based emoji!")]
97     });
98     }
99    
100     return;
101     }
102    
103     await message.reply({
104     embeds: [
105     new EmbedBuilder()
106     .setAuthor({
107     name: emoji.guild.name,
108     iconURL: emoji.guild.iconURL()!
109     })
110     .setTitle(emoji.name ?? "Emoji Information")
111     .setFields(
112     { name: "Name", value: emoji.name ?? "*No name set*" },
113     { name: "Identifier", value: emoji.identifier ?? "*No identifier set*" },
114     { name: "Available", value: emoji.available ? "Yes" : "No" },
115     { name: "Created", value: formatDistanceToNowStrict(emoji.createdAt, { addSuffix: true }) },
116     { name: "Download", value: `[Click here](${emoji.imageURL()})` }
117     )
118     .setThumbnail(emoji.url)
119     .setFooter({
120     text: `ID: ${emoji.id}`
121     })
122     ]
123     });
124     }
125     }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26