/[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 51 by rakin, Mon Jul 29 17:28:23 2024 UTC revision 341 by rakin, Mon Jul 29 17:29:38 2024 UTC
# Line 4  import DiscordClient from '../../client/ Line 4  import DiscordClient from '../../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              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;
78                      let perm1;  
79                      let perm;              if (!result) {
80                      const data1 = data?.perms?.split(',');                  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                }
82                      if (data1) {  
83                          if (data1[0] === 'DENY') {              if (error) {
84                              await (perm = false);                  await this.deferReply(msg, {
85                          }                      content: error,
86                          else if (data1[0] === 'NULL') {                  });
87                              await (perm = null);  
88                          }                  return;
89                          else if (data1[0] === 'ALLOW') {              }
                             await (perm = true);  
                         }  
   
                         if (data1[1] === 'DENY') {  
                             await (perm1 = false);  
                         }  
                         else if (data1[1] === 'NULL') {  
                             await (perm1 = null);  
                         }  
                         else if (data1[1] === 'ALLOW') {  
                             await (perm1 = true);  
                         }  
                     }  
                       
                     if (force) {  
                         await (perm1 = true);  
                         await (perm = true);  
                     }  
   
                     await console.log(channel.name);  
   
                     try {  
                         await channel.permissionOverwrites.edit(role, {  
                             SEND_MESSAGES: perm,  
                         });  
   
                         const gen = await msg.guild!.roles.fetch(client.config.props[msg.guild!.id].gen_role);  
   
                         await channel.permissionOverwrites.edit(gen!, {  
                             SEND_MESSAGES: perm1,  
                         });  
                     }  
                     catch (e) {  
                         console.log(e);  
                     }  
   
                     await console.log(perm, perm1);  
   
                     if (data) {  
                         await client.db.get('DELETE FROM locks WHERE id = ?', [data?.id], async (err: any) => {});  
                     }  
                 }  
             });  
90                            
91              if (options.isInteraction) {              if (options.isInteraction) {
92                  await msg.reply({                  await this.deferReply(msg, {
93                      content: "Channel unlocked.",                      content: "Channel unlocked.",
                     ephemeral: true  
94                  });                  });
95              }              }
96              else {              else {
97                  await (msg as Message).react('🔓');                  await (msg as Message).react('🔓');
98              }              }
   
             await channel.send({  
                 embeds: [  
                     new MessageEmbed()  
                     .setColor('#007bff')  
                     .setDescription(`:closed_lock_with_key: This channel has been unlocked.`)  
                 ]  
             });  
99          }          }
100          catch (e) {          catch (e) {
101              console.log(e);              console.log(e);

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26