/[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 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              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;
97                      let perm1;  
98                      let perm;              if (!result) {
99                      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.';
100                }
101                      if (data1) {  
102                          if (data1[0] === 'DENY') {              if (error) {
103                              await (perm = false);                  await this.deferReply(msg, {
104                          }                      content: error,
105                          else if (data1[0] === 'NULL') {                  });
106                              await (perm = null);  
107                          }                  return;
108                          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) => {});  
                     }  
                 }  
             });  
109                            
110              if (options.isInteraction) {              if (options.isInteraction) {
111                  await msg.reply({                  await this.deferReply(msg, {
112                      content: "Channel unlocked.",                      content: "Channel unlocked.",
                     ephemeral: true  
113                  });                  });
114              }              }
115              else {              else {
116                  await (msg as Message).react('🔓');                  await (msg as Message).react('🔓');
117              }              }
   
             await channel.send({  
                 embeds: [  
                     new MessageEmbed()  
                     .setColor('#007bff')  
                     .setDescription(`:closed_lock_with_key: This channel has been unlocked.`)  
                 ]  
             });  
118          }          }
119          catch (e) {          catch (e) {
120              console.log(e);              console.log(e);

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26