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

Diff of /trunk/src/commands/moderation/UnlockallCommand.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 107 by rakin, Mon Jul 29 17:28:37 2024 UTC
# Line 7  import MessageEmbed from '../../client/M Line 7  import MessageEmbed from '../../client/M
7    
8  export async function unlockAll(client: DiscordClient, role: Role, msg: Message | CommandInteraction, options: CommandOptions | InteractionOptions, channels: Collection <string, TextChannel>, force: boolean) {  export async function unlockAll(client: DiscordClient, role: Role, msg: Message | CommandInteraction, options: CommandOptions | InteractionOptions, channels: Collection <string, TextChannel>, force: boolean) {
9      if (role) {      if (role) {
         const gen = await msg.guild!.roles.fetch(client.config.props[msg.guild!.id].gen_role);  
   
10          channels.forEach(async channel => {          channels.forEach(async channel => {
11              try {              try {
                 await channel.send({  
                     embeds: [  
                         new MessageEmbed()  
                         .setDescription(':closed_lock_with_key: This channel has been unlocked.')  
                     ]  
                 });  
   
12                  client.db.get('SELECT * FROM locks WHERE channel_id = ?', [channel.id], async (err: any, data: any) => {                  client.db.get('SELECT * FROM locks WHERE channel_id = ?', [channel.id], async (err: any, data: any) => {
13                      if (data || force) {                      if (data || force) {
14                          let perm1;                          await channel.send({
15                                embeds: [
16                                    new MessageEmbed()
17                                    .setDescription(':closed_lock_with_key: This channel has been unlocked.')
18                                ]
19                            });
20                            
21                          let perm;                          let perm;
22                          const data1 = data?.perms?.split(',');                          const data1 = data?.perms;
23    
24                          if (data1) {                          if (data1) {
25                              if (data1[0] === 'DENY') {                              if (data1 === 'DENY') {
26                                  await (perm = false);                                  await (perm = false);
27                              }                              }
28                              else if (data1[0] === 'NULL') {                              else if (data1 === 'NULL') {
29                                  await (perm = null);                                  await (perm = null);
30                              }                              }
31                              else if (data1[0] === 'ALLOW') {                              else if (data1 === 'ALLOW') {
32                                  await (perm = true);                                  await (perm = true);
33                              }                              }
   
                             if (data1[1] === 'DENY') {  
                                 await (perm1 = false);  
                             }  
                             else if (data1[1] === 'NULL') {  
                                 await (perm1 = null);  
                             }  
                             else if (data1[1] === 'ALLOW') {  
                                 await (perm1 = true);  
                             }  
34                          }                          }
35                                                    
36                          if (force) {                          if (force) {
                             await (perm1 = true);  
37                              await (perm = true);                              await (perm = true);
38                          }                          }
39    
# Line 58  export async function unlockAll(client: Line 44  export async function unlockAll(client:
44                                  SEND_MESSAGES: perm,                                  SEND_MESSAGES: perm,
45                              });                              });
46    
                             await channel.permissionOverwrites.edit(gen!, {  
                                 SEND_MESSAGES: perm1,  
                             });  
47                          }                          }
48                          catch (e) {                          catch (e) {
49                              console.log(e);                              console.log(e);
50                          }                          }
51    
52                          await console.log(perm, perm1);                          await console.log(perm);
53    
54                          if (data) {                          if (data) {
55                              await client.db.get('DELETE FROM locks WHERE id = ?', [data?.id], async (err: any) => {});                              await client.db.get('DELETE FROM locks WHERE id = ?', [data?.id], async (err: any) => {});
# Line 89  export default class UnlockallCommand ex Line 72  export default class UnlockallCommand ex
72      }      }
73    
74      async run(client: DiscordClient, msg: Message | CommandInteraction, options: CommandOptions | InteractionOptions) {      async run(client: DiscordClient, msg: Message | CommandInteraction, options: CommandOptions | InteractionOptions) {
75            if (!options.isInteraction && typeof options.args[0] === 'undefined') {
76                await msg.reply({
77                    embeds: [
78                        new MessageEmbed()
79                        .setColor('#f14a60')
80                        .setDescription(`This command requires at least one argument.`)
81                    ]
82                });
83    
84                return;
85            }
86    
87          const raid = options.isInteraction ? options.options.getBoolean('raid') === true : (options.options.indexOf('--raid') !== -1);          const raid = options.isInteraction ? options.options.getBoolean('raid') === true : (options.options.indexOf('--raid') !== -1);
88    
89          let role: Role = <Role> msg.guild!.roles.everyone;          let role: Role = <Role> msg.guild!.roles.everyone;
90            let unlockall: string[] = [], unlockallChannels: Collection<string, TextChannel> = new Collection();
91          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);
92    
93          if (options.isInteraction) {          if (options.isInteraction) {
# Line 101  export default class UnlockallCommand ex Line 97  export default class UnlockallCommand ex
97          }          }
98          else {          else {
99              if ((msg as Message).mentions.roles.first()) {              if ((msg as Message).mentions.roles.first()) {
100                  role = await <Role> (msg as Message).mentions.roles.first();                  role = await <Role> (msg as Message).mentions.roles.first();
101              }              }
102              else if (options.normalArgs[0] && options.normalArgs[0] !== 'everyone') {              else if (options.options.includes('-r') && options.normalArgs[options.options.indexOf('-r') + 1]) {
103                  role = <Role> await (msg as Message).guild?.roles.fetch(options.normalArgs[0]);                  role = <Role> await (msg as Message).guild?.roles.fetch(options.normalArgs[options.options.indexOf('-r') + 1]);
104              }              }
105    
106              if (!role) {              if (!role) {
107                  await msg.reply({                  await msg.reply({
# Line 119  export default class UnlockallCommand ex Line 115  export default class UnlockallCommand ex
115            
116                  return;                  return;
117              }              }
118    
119                if (!raid) {
120                    for (const a of options.args) {
121                        if (/^\d+$/g.test(a)) {
122                            unlockall.push(a);
123                        }
124                    }
125        
126                    if ((msg as Message).mentions.channels.first()) {
127                        (msg as Message).mentions.channels.forEach(c => {
128                            if (c instanceof TextChannel)
129                                unlockallChannels.set(c.id, c);
130                        });
131                    }
132                }
133          }          }
134    
135          const channels: Collection <string, GuildBasedChannel> = await msg.guild!.channels.cache.filter(c => (          let channels = raid ? await msg.guild!.channels.cache.filter(c => (
             (!raid && (client.config.props[msg.guild!.id].lockall.indexOf(c.id) !== -1 || client.config.props[msg.guild!.id].lockall.indexOf(c.parent?.id) !== -1)) ||  
136              (raid && (              (raid && (
137                  (client.config.props[msg.guild!.id].raid.exclude && (client.config.props[msg.guild!.id].raid.channels.indexOf(c.id) === -1 && client.config.props[msg.guild!.id].raid.channels.indexOf(c.parent?.id) === -1)) ||                  (client.config.props[msg.guild!.id].raid.exclude && (client.config.props[msg.guild!.id].raid.channels.indexOf(c.id) === -1 && client.config.props[msg.guild!.id].raid.channels.indexOf(c.parent?.id) === -1)) ||
138                  (!client.config.props[msg.guild!.id].raid.exclude && (client.config.props[msg.guild!.id].raid.channels.indexOf(c.id) !== -1 || client.config.props[msg.guild!.id].raid.channels.indexOf(c.parent?.id) !== -1))                  (!client.config.props[msg.guild!.id].raid.exclude && (client.config.props[msg.guild!.id].raid.channels.indexOf(c.id) !== -1 || client.config.props[msg.guild!.id].raid.channels.indexOf(c.parent?.id) !== -1))
139              ))) && c.type === 'GUILD_TEXT'              ))) && c.type === 'GUILD_TEXT'
140          );          ) : null;
141    
142            if (channels === null && !raid) {
143                channels = msg.guild!.channels.cache.filter(c2 => (unlockall.includes(c2.id) || unlockall.includes(c2.parent?.id!)) && c2.type === 'GUILD_TEXT')!;
144                channels = channels.merge(unlockallChannels, c => ({ keep: true, value: c }), c => ({ keep: true, value: c }), (c1, c2) => ({ keep: true, value: c2 }));
145            }
146    
147          await unlockAll(client, role, msg, options, channels as Collection <string, TextChannel>, force);          await unlockAll(client, role, msg, options, channels as Collection <string, TextChannel>, force);
148    

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26