/[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 393 by rakin, Mon Jul 29 17:29:59 2024 UTC
# Line 1  Line 1 
1  import { BanOptions, CommandInteraction, EmojiIdentifierResolvable, GuildMember, Interaction, Message, Permissions, Role, TextChannel, User } from 'discord.js';  /**
2    * This file is part of SudoBot.
3    *
4    * Copyright (C) 2021-2022 OSN Inc.
5    *
6    * SudoBot is free software; you can redistribute it and/or modify it
7    * under the terms of the GNU Affero General Public License as published by
8    * the Free Software Foundation, either version 3 of the License, or
9    * (at your option) any later version.
10    *
11    * SudoBot is distributed in the hope that it will be useful, but
12    * WITHOUT ANY WARRANTY; without even the implied warranty of
13    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14    * GNU Affero General Public License for more details.
15    *
16    * You should have received a copy of the GNU Affero General Public License
17    * along with SudoBot. If not, see <https://www.gnu.org/licenses/>.
18    */
19    
20    import { CommandInteraction, Message, Role, TextChannel } from 'discord.js';
21  import BaseCommand from '../../utils/structures/BaseCommand';  import BaseCommand from '../../utils/structures/BaseCommand';
22  import DiscordClient from '../../client/Client';  import DiscordClient from '../../client/Client';
23  import CommandOptions from '../../types/CommandOptions';  import CommandOptions from '../../types/CommandOptions';
24  import InteractionOptions from '../../types/InteractionOptions';  import InteractionOptions from '../../types/InteractionOptions';
25  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';  
26    
27  export default class UnlockCommand extends BaseCommand {  export default class UnlockCommand extends BaseCommand {
28      supportsInteractions: boolean = true;      supportsInteractions: boolean = true;
# Line 19  export default class UnlockCommand exten Line 34  export default class UnlockCommand exten
34      async run(client: DiscordClient, msg: Message | CommandInteraction, options: CommandOptions | InteractionOptions) {      async run(client: DiscordClient, msg: Message | CommandInteraction, options: CommandOptions | InteractionOptions) {
35          let channel: TextChannel = <TextChannel> msg.channel;          let channel: TextChannel = <TextChannel> msg.channel;
36          let role: Role = <Role> msg.guild!.roles.everyone;          let role: Role = <Role> msg.guild!.roles.everyone;
37    
38            if (msg instanceof CommandInteraction)
39                await msg.deferReply({ ephemeral: true });
40    
41          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);
42    
43          if (options.isInteraction) {          if (options.isInteraction) {
# Line 26  export default class UnlockCommand exten Line 45  export default class UnlockCommand exten
45                  channel = await <TextChannel> options.options.getChannel('channel');                  channel = await <TextChannel> options.options.getChannel('channel');
46              }              }
47    
48              if (options.options.getChannel('role')) {              if (options.options.getRole('role')) {
49                  role = await <Role> options.options.getRole('role');                  role = await <Role> options.options.getRole('role');
50              }              }
51          }          }
# Line 73  export default class UnlockCommand exten Line 92  export default class UnlockCommand exten
92          }          }
93    
94          try {          try {
95              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 });
96                  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('🔓');  
                 }  
97    
98                  await channel.send({              if (!result) {
99                      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.';
100                          new MessageEmbed()              }
101                          .setColor('#007bff')  
102                          .setDescription(`:closed_lock_with_key: This channel has been unlocked.`)              if (error) {
103                      ]                  await this.deferReply(msg, {
104                        content: error,
105                  });                  });
106              });  
107                    return;
108                }
109                
110                if (options.isInteraction) {
111                    await this.deferReply(msg, {
112                        content: "Channel unlocked.",
113                    });
114                }
115                else {
116                    await (msg as Message).react('🔓');
117                }
118          }          }
119          catch (e) {          catch (e) {
120              console.log(e);              console.log(e);

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26