/[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 241 by rakin, Mon Jul 29 17:29:10 2024 UTC
# Line 19  export default class UnlockCommand exten Line 19  export default class UnlockCommand exten
19      async run(client: DiscordClient, msg: Message | CommandInteraction, options: CommandOptions | InteractionOptions) {      async run(client: DiscordClient, msg: Message | CommandInteraction, options: CommandOptions | InteractionOptions) {
20          let channel: TextChannel = <TextChannel> msg.channel;          let channel: TextChannel = <TextChannel> msg.channel;
21          let role: Role = <Role> msg.guild!.roles.everyone;          let role: Role = <Role> msg.guild!.roles.everyone;
22    
23            if (msg instanceof CommandInteraction)
24                await msg.deferReply({ ephemeral: true });
25    
26          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);
27    
28          if (options.isInteraction) {          if (options.isInteraction) {
# Line 73  export default class UnlockCommand exten Line 77  export default class UnlockCommand exten
77          }          }
78    
79          try {          try {
80              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 });
81                  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('🔓');  
                 }  
82    
83                  await channel.send({              if (!result) {
84                      embeds: [                  error = 'This channel wasn\'t locked. If you want to force unlock, run this command with `--force` option or select `True` if using slash commands.';
85                          new MessageEmbed()              }
86                          .setColor('#007bff')  
87                          .setDescription(`:closed_lock_with_key: This channel has been unlocked.`)              if (error) {
88                      ]                  await this.deferReply(msg, {
89                        content: error,
90                  });                  });
91              });  
92                    return;
93                }
94                
95                if (options.isInteraction) {
96                    await this.deferReply(msg, {
97                        content: "Channel unlocked.",
98                    });
99                }
100                else {
101                    await (msg as Message).react('🔓');
102                }
103          }          }
104          catch (e) {          catch (e) {
105              console.log(e);              console.log(e);

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26