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

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

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

revision 103 by rakin, Mon Jul 29 17:28:36 2024 UTC revision 344 by rakin, Mon Jul 29 17:29:40 2024 UTC
# Line 1  Line 1 
1  import { BanOptions, CommandInteraction, EmojiIdentifierResolvable, GuildMember, Interaction, Message, Permissions, Role, TextChannel, User } from 'discord.js';  import { CommandInteraction, Message, Role, TextChannel } 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';
 import getUser from '../../utils/getUser';  
 import getMember from '../../utils/getMember';  
 import History from '../../automod/History';  
 import { fetchEmoji } from '../../utils/Emoji';  
7    
8  export default class UnlockCommand extends BaseCommand {  export default class UnlockCommand extends BaseCommand {
9      supportsInteractions: boolean = true;      supportsInteractions: boolean = true;
# Line 19  export default class UnlockCommand exten Line 15  export default class UnlockCommand exten
15      async run(client: DiscordClient, msg: Message | CommandInteraction, options: CommandOptions | InteractionOptions) {      async run(client: DiscordClient, msg: Message | CommandInteraction, options: CommandOptions | InteractionOptions) {
16          let channel: TextChannel = <TextChannel> msg.channel;          let channel: TextChannel = <TextChannel> msg.channel;
17          let role: Role = <Role> msg.guild!.roles.everyone;          let role: Role = <Role> msg.guild!.roles.everyone;
18    
19            if (msg instanceof CommandInteraction)
20                await msg.deferReply({ ephemeral: true });
21    
22          const force = options.isInteraction ? options.options.getBoolean('force') === true : (options.options.indexOf('--force') !== -1);          const force = options.isInteraction ? options.options.getBoolean('force') === true : (options.options.indexOf('--force') !== -1);
23    
24          if (options.isInteraction) {          if (options.isInteraction) {
# Line 26  export default class UnlockCommand exten Line 26  export default class UnlockCommand exten
26                  channel = await <TextChannel> options.options.getChannel('channel');                  channel = await <TextChannel> options.options.getChannel('channel');
27              }              }
28    
29              if (options.options.getChannel('role')) {              if (options.options.getRole('role')) {
30                  role = await <Role> options.options.getRole('role');                  role = await <Role> options.options.getRole('role');
31              }              }
32          }          }
# Line 73  export default class UnlockCommand exten Line 73  export default class UnlockCommand exten
73          }          }
74    
75          try {          try {
76              await client.db.get('SELECT * FROM locks WHERE channel_id = ?', [channel.id], async (err: any, data: any) => {              const result = await client.channelLock.unlock(channel, { sendConfirmation: true, force });
77                  if (data || force) {              let error = null;
                     let perm;  
                     const data1 = data?.perms;  
   
                     if (data1) {  
                         if (data1 === 'DENY') {  
                             await (perm = false);  
                         }  
                         else if (data1 === 'NULL') {  
                             await (perm = null);  
                         }  
                         else if (data1 === 'ALLOW') {  
                             await (perm = true);  
                         }  
                     }  
   
                     console.log(data1, perm);                      
                       
                     if (force) {  
                         await (perm = true);  
                     }  
   
                     await console.log(channel.name, role.name);  
   
                     try {  
                         await channel.permissionOverwrites.edit(role, {  
                             SEND_MESSAGES: perm,  
                         });  
                     }  
                     catch (e) {  
                         console.log(e);  
                     }  
   
                     if (data) {  
                         await client.db.get('DELETE FROM locks WHERE id = ?', [data?.id], async (err: any) => {});  
                     }  
                 }  
                 else {  
                     await msg.reply({  
                         embeds: [  
                             new MessageEmbed()  
                             .setColor('#007bff')  
                             .setDescription(`:closed_lock_with_key: This channel wasn't locked.`)  
                         ],  
                         ephemeral: true  
                     });  
   
                     return;  
                 }  
   
                 if (options.isInteraction) {  
                     await msg.reply({  
                         content: "Channel unlocked.",  
                         ephemeral: true  
                     });  
                 }  
                 else {  
                     await (msg as Message).react('🔓');  
                 }  
78    
79                  await channel.send({              if (!result) {
80                      embeds: [                  error = 'This channel wasn\'t locked' + (role.id === msg.guild!.id ? '' : ' for the given role') + '. If you want to force unlock, run this command with `--force` option or select `True` if using slash commands.';
81                          new MessageEmbed()              }
82                          .setColor('#007bff')  
83                          .setDescription(`:closed_lock_with_key: This channel has been unlocked.`)              if (error) {
84                      ]                  await this.deferReply(msg, {
85                        content: error,
86                  });                  });
87              });  
88                    return;
89                }
90                
91                if (options.isInteraction) {
92                    await this.deferReply(msg, {
93                        content: "Channel unlocked.",
94                    });
95                }
96                else {
97                    await (msg as Message).react('🔓');
98                }
99          }          }
100          catch (e) {          catch (e) {
101              console.log(e);              console.log(e);

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26