/[sudobot]/trunk/src/commands/information/EmojiCommand.ts
ViewVC logotype

Diff of /trunk/src/commands/information/EmojiCommand.ts

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 54 by rakin, Mon Jul 29 17:28:24 2024 UTC revision 344 by rakin, Mon Jul 29 17:29:40 2024 UTC
# Line 1  Line 1 
1  import { CommandInteraction, Emoji, Message } from 'discord.js';  import { CommandInteraction, Message, Util } from 'discord.js';
2  import BaseCommand from '../../utils/structures/BaseCommand';  import BaseCommand from '../../utils/structures/BaseCommand';
3  import DiscordClient from '../../client/Client';  import DiscordClient from '../../client/Client';
4  import CommandOptions from '../../types/CommandOptions';  import CommandOptions from '../../types/CommandOptions';
5  import InteractionOptions from '../../types/InteractionOptions';  import InteractionOptions from '../../types/InteractionOptions';
6  import axios from 'axios';  import { timeSince } from '../../utils/util';
 import path from 'path';  
 import { deleteFile, download, timeSince } from '../../utils/util';  
7  import MessageEmbed from '../../client/MessageEmbed';  import MessageEmbed from '../../client/MessageEmbed';
8    
9  export default class EmojiCommand extends BaseCommand {  export default class EmojiCommand extends BaseCommand {
# Line 37  export default class EmojiCommand extend Line 35  export default class EmojiCommand extend
35              emojiString = options.args[0];              emojiString = options.args[0];
36          }          }
37    
38          if (emojiString.startsWith('<:') && emojiString.endsWith('>')) {          const emojiSubString = emojiString.startsWith('<:') && emojiString.endsWith('>') ? emojiString.substring(2, emojiString.length - 1) : emojiString;
             console.log(emojiString);  
             emojiString = emojiString.substring(2, emojiString.length - 1);  
         }  
39                    
40          const emoji = await client.emojis.cache.find(e => e.name === emojiString || e.identifier === emojiString);          let emoji = await client.emojis.cache.find(e => e.name === emojiSubString || e.identifier === emojiSubString || e.id === emojiSubString);
41    
42          if (!emoji) {          if (!emoji) {
43              await msg.reply({              if ((emojiString.startsWith('<:') && emojiString.endsWith('>')) || /\d+/g.test(emojiString)) {
44                  embeds: [                  let parsedEmoji = emojiString.startsWith('<:') && emojiString.endsWith('>') ? Util.parseEmoji(emojiString) : { animated: undefined, id: emojiString, name: undefined };
45                      new MessageEmbed()  
46                      .setColor('#f14a60')                  if (!parsedEmoji) {
47                      .setDescription('No emoji found or not a guild based emoji!')                      await msg.reply({
48                  ]                          embeds: [
49              });                              new MessageEmbed()
50                                .setColor('#f14a60')
51                                .setDescription('Invalid emoji!')
52                            ]
53                        });
54    
55                        return;
56                    }
57    
58                    await msg.reply({
59                        embeds: [
60                            new MessageEmbed()
61                            .setAuthor({
62                                name: parsedEmoji.name ?? "Unknown Emoji",
63                                iconURL: `https://cdn.discordapp.com/emojis/${parsedEmoji.id}`,
64                            })
65                            .setFields({
66                                name: "Animated",
67                                value: parsedEmoji.animated !== undefined ? parsedEmoji.animated ? 'Yes' : 'No' : "*The system could not load enough information*",
68                            }, {
69                                name: "Download",
70                                value: `[Click Here](https://cdn.discordapp.com/emojis/${parsedEmoji.id})`
71                            })
72                            .setThumbnail(`https://cdn.discordapp.com/emojis/${parsedEmoji.id}`)
73                            .setFooter({
74                                text: `ID: ${parsedEmoji.id}`
75                            })
76                        ]
77                    });
78                }
79                else {
80                    await msg.reply({
81                        embeds: [
82                            new MessageEmbed()
83                            .setColor('#f14a60')
84                            .setDescription('No emoji found or not a guild based emoji!')
85                        ]
86                    });
87                }
88    
89              return;              return;
90          }                }
91    
92          await msg.reply({          await msg.reply({
93              embeds: [              embeds: [
# Line 67  export default class EmojiCommand extend Line 100  export default class EmojiCommand extend
100                  .addField('Name', emoji.name ?? '*No name set*')                  .addField('Name', emoji.name ?? '*No name set*')
101                  .addField('Identifier', emoji.identifier ?? '*No identifier set*')                  .addField('Identifier', emoji.identifier ?? '*No identifier set*')
102                  .addField('Available', emoji.available ? 'Yes' : 'No')                  .addField('Available', emoji.available ? 'Yes' : 'No')
103                  .addField('Created at', timeSince(emoji.createdAt.getTime()))                  .addField('Created', timeSince(emoji.createdAt.getTime()))
104                  .addField('Download', `[Click here](${emoji.url})`)                  .addField('Download', `[Click here](${emoji.url})`)
105                  .setImage(emoji.url)                  .setThumbnail(emoji.url)
106                  .setFooter({                  .setFooter({
107                      text: `ID: ${emoji.id}`                      text: `ID: ${emoji.id}`
108                  })                  })

Legend:
Removed from v.54  
changed lines
  Added in v.344

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26