/[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 86 by rakin, Mon Jul 29 17:28:32 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);  
             }  
35    
36              if (data === undefined) {          if (options.isInteraction) {
37                  await msg.reply({              id = await <string> options.options.getNumber('id')?.toString();
38                      embeds: [          }
39                          new MessageEmbed()          else {
40                          .setColor('#f14a60')              id = await options.args[0];
41                          .setDescription('No note found')          }
                     ]  
                 });  
42    
43                  return;          const note = await Note.findOne({
44                where: {
45                    guild_id: msg.guild!.id,
46                    id
47              }              }
48            });
49    
50              let user;          if (!note) {
51                await msg.reply(`${await fetchEmojiStr('error')} Invalid note ID.`);
52                return;
53            }
54    
55              try {          let user;
                 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  
                 };  
             }  
56    
57              await msg.reply({          try {
58                  embeds: [              user = await client.users.fetch(note.get().user_id);
59                      new MessageEmbed()          }
60                      .setDescription(data.content)          catch (e) {
61                      .setAuthor(user)              console.log(e);            
62                      .setFields([          }
63    
64            await msg.reply({
65                embeds: [
66                    new MessageEmbed({
67                        author: {
68                            name: user?.tag ?? note.get().user_id,
69                            iconURL: user instanceof User ? user.displayAvatarURL() : undefined,
70                        },
71                        description: note.get().content,
72                        fields: [
73                          {                          {
74                              name: "ID",                              name: 'Note taken by',
75                              value: data.id + ''                              value: note.get().mod_tag
76                          }                          }
77                      ])                      ],
78                      .setTimestamp(new Date(data.date))                      footer: {
79                  ]                          text: `ID: ${note.get().id}`
80              });                      },
81                        timestamp: note.get().createdAt
82                    })
83                ]
84          });          });
   
85      }      }
 };  
86    }

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26