/[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

revision 51 by rakin, Mon Jul 29 17:28:23 2024 UTC revision 341 by rakin, Mon Jul 29 17:29:38 2024 UTC
# Line 4  import DiscordClient from '../../client/ Line 4  import DiscordClient from '../../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 MessageEmbed from '../../client/MessageEmbed';  import MessageEmbed from '../../client/MessageEmbed';
7  import getUser from '../../utils/getUser';  import { fetchEmojiStr } from '../../utils/Emoji';
8  import History from '../../automod/History';  import Note from '../../models/Note';
 import getMember from '../../utils/getMember';  
 import ms from 'ms';  
9    
10  export default class NotegetCommand extends BaseCommand {  export default class NotegetCommand extends BaseCommand {
11      supportsInteractions: boolean = true;      supportsInteractions: boolean = true;
# Line 32  export default class NotegetCommand exte Line 30  export default class NotegetCommand exte
30          let id: string;          let id: string;
31    
32          if (options.isInteraction) {          if (options.isInteraction) {
33              id = await options.options.getNumber('id')?.toString()!;              id = await <string> options.options.getString('id');
34          }          }
35          else {          else {
36              id = options.args[0];              id = await options.args[0];
37          }          }
38    
39          await client.db.get("SELECT * FROM notes WHERE id = ? AND guild_id = ?", [[id], msg.guild!.id], async (err: any, data: any) => {          const note = await Note.findOne({
40              if (err) {              guild_id: msg.guild!.id,
41                  console.log(err);              _id: id
42              }          });
   
             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  
                 };  
             }  
43    
44              await msg.reply({          if (!note) {
45                  embeds: [              await msg.reply(`${await fetchEmojiStr('error')} Invalid note ID.`);
46                      new MessageEmbed()              return;
47                      .setDescription(data.content)          }
48                      .setAuthor(user)  
49                      .setFields([          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.51  
changed lines
  Added in v.341

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26