/[sudobot]/trunk/src/commands/moderation/NotegetCommand.ts
ViewVC logotype

Diff of /trunk/src/commands/moderation/NotegetCommand.ts

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

trunk/commands/noteget.js revision 5 by rakin, Mon Jul 29 17:28:11 2024 UTC trunk/src/commands/moderation/NotegetCommand.ts revision 344 by rakin, Mon Jul 29 17:29:40 2024 UTC
# Line 1  Line 1 
1  const MessageEmbed = require("../src/MessageEmbed");  import { CommandInteraction, Message, User } from 'discord.js';
2    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 { fetchEmojiStr } from '../../utils/Emoji';
8    import Note from '../../models/Note';
9    
10  module.exports = {  export default class NotegetCommand extends BaseCommand {
11      async handle(msg, cm) {      supportsInteractions: boolean = true;
12          if (typeof cm.args[0] === 'undefined') {  
13        constructor() {
14            super('noteget', 'moderation', []);
15        }
16    
17        async run(client: DiscordClient, msg: Message | CommandInteraction, options: CommandOptions | InteractionOptions) {
18            if (!options.isInteraction && typeof options.args[0] === 'undefined') {
19              await msg.reply({              await msg.reply({
20                  embeds: [                  embeds: [
21                      new MessageEmbed()                      new MessageEmbed()
# Line 14  module.exports = { Line 27  module.exports = {
27              return;              return;
28          }          }
29    
30          await app.db.get("SELECT * FROM notes WHERE id = ? AND guild_id = ?", [cm.args[0], msg.guild.id], async (err, data) => {          let id: string;
             if (err) {  
                 console.log(err);  
             }  
   
             if (data === undefined) {  
                 await msg.reply({  
                     embeds: [  
                         new MessageEmbed()  
                         .setColor('#f14a60')  
                         .setDescription('No note found')  
                     ]  
                 });  
   
                 return;  
             }  
   
             let user;  
   
             try {  
                 user = await msg.guild.members.fetch(data.user_id);  
                 user = {  
                     name: user.user.tag,  
                     iconURL: user.displayAvatarURL()  
                 };  
             }  
             catch(e) {  
                 user = {  
                     name: "User " + data.user_id  
                 };  
             }  
31    
32              await msg.reply({          if (options.isInteraction) {
33                  embeds: [              id = await <string> options.options.getString('id');
34                      new MessageEmbed()          }
35                      .setDescription(data.content)          else {
36                      .setAuthor(user)              id = await options.args[0];
37                      .setFields([          }
38    
39            const note = await Note.findOne({
40                guild_id: msg.guild!.id,
41                _id: id
42            });
43    
44            if (!note) {
45                await msg.reply(`${await fetchEmojiStr('error')} Invalid note ID.`);
46                return;
47            }
48    
49            let user;
50    
51            try {
52                user = await client.users.fetch(note.user_id);
53            }
54            catch (e) {
55                console.log(e);            
56            }
57    
58            await msg.reply({
59                embeds: [
60                    new MessageEmbed({
61                        author: {
62                            name: user?.tag ?? note.user_id,
63                            iconURL: user instanceof User ? user.displayAvatarURL() : undefined,
64                        },
65                        description: note.content,
66                        fields: [
67                          {                          {
68                              name: "ID",                              name: 'Note taken by',
69                              value: data.id + ''                              value: note.mod_tag
70                          }                          }
71                      ])                      ],
72                      .setTimestamp(new Date(data.date))                      footer: {
73                  ]                          text: `ID: ${note.id}`
74              });                      },
75                        timestamp: note.createdAt
76                    })
77                ]
78          });          });
   
79      }      }
 };  
80    }

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26