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

Diff of /trunk/src/commands/moderation/NotedelCommand.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 344 by rakin, Mon Jul 29 17:29:40 2024 UTC
# Line 1  Line 1 
1  import { BanOptions, CommandInteraction, Guild, GuildMember, Interaction, Message, User } from 'discord.js';  import { CommandInteraction, Message } 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 MessageEmbed from '../../client/MessageEmbed';  import MessageEmbed from '../../client/MessageEmbed';
7  import getUser from '../../utils/getUser';  import Note from '../../models/Note';
8  import History from '../../automod/History';  import { fetchEmojiStr } from '../../utils/Emoji';
 import getMember from '../../utils/getMember';  
 import ms from 'ms';  
9    
10  export default class NotedelCommand extends BaseCommand {  export default class NotedelCommand extends BaseCommand {
11      supportsInteractions: boolean = true;      supportsInteractions: boolean = true;
# Line 32  export default class NotedelCommand exte Line 30  export default class NotedelCommand exte
30          let id: string;          let id: string;
31    
32          if (options.isInteraction) {          if (options.isInteraction) {
33              id = await <string> options.options.getNumber('id')?.toString();              id = await <string> options.options.getString('id');
34          }          }
35          else {          else {
36              id = await 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              }          });
43    
44              if (data === undefined) {          if (!note) {
45                  await msg.reply({              await msg.reply(`${await fetchEmojiStr('error')} Invalid note ID.`);
46                      embeds: [              return;
47                          new MessageEmbed()          }
48                          .setColor('#f14a60')  
49                          .setDescription('No note found')          await note.delete();
50                      ]  
51                  });          await msg.reply({
52                embeds: [
53                  return;                  new MessageEmbed({
54              }                      description: `${await fetchEmojiStr('check')} Note deleted.`
55                    })
56              await client.db.get('DELETE FROM notes WHERE id = ? AND guild_id = ?', [id, msg.guild!.id], async (err: any) => {              ]
                 if (err) {  
                     console.log(err);  
                 }  
   
                   
                 await History.create(data.user_id, msg.guild!, 'notedel', msg.member?.user.id!, '', async (data2: any) => {  
                     await msg.reply({  
                         embeds: [  
                             new MessageEmbed()  
                             .setDescription('The note has been deleted')  
                         ]  
                     });  
                 });  
             });  
57          });          });
58      }      }
59  }  }

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26