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

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26