/[sudobot]/trunk/commands/unlockall.js
ViewVC logotype

Diff of /trunk/commands/unlockall.js

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 10 by rakin, Mon Jul 29 17:28:12 2024 UTC revision 39 by rakin, Mon Jul 29 17:28:19 2024 UTC
# Line 4  const MessageEmbed = require("../src/Mes Line 4  const MessageEmbed = require("../src/Mes
4  module.exports = {  module.exports = {
5      needsOptionParse: true,      needsOptionParse: true,
6      async handle(msg, cm) {      async handle(msg, cm) {
7          let channels = cm.options.indexOf('--raid') !== -1 ? app.config.get('raid').included : app.config.get('lockall');          let channels = cm.options.indexOf('--raid') !== -1 ? app.config.get('raid').excluded : app.config.get('lockall');
8    
9          if (msg.mentions.channels.first()) {          if (msg.mentions.channels.first()) {
10              channels = msg.mentions.channels;              channels = msg.mentions.channels;
11          }          }
12          else {          else {
13              channels = await msg.guild.channels.cache.filter(c => channels.indexOf(c.id) !== -1);              channels = await msg.guild.channels.cache.filter(c => ((cm.options.indexOf('--raid') !== -1 && channels.indexOf(c.id) === -1 && channels.indexOf(c.parent?.id) === -1 && c.type === 'GUILD_TEXT') || (cm.options.indexOf('--raid') === -1 && channels.indexOf(c.id) !== -1)));
14          }          }
15    
16          await this.unlockAll(msg, cm, channels);          await this.unlockAll(msg, cm, channels);
17      },      },
18      async unlockAll(msg, cm, channels) {      async unlockAll(msg, cm, channels) {
19          let role = cm.options.indexOf('--everyone') === -1 ? msg.guild.roles.cache.find(r => r.id === app.config.get('gen_role')) : msg.guild.roles.everyone;          let role = msg.guild.roles.everyone;
20    
21          if (role) {          if (role) {
22              channels.forEach(async channel => {              channels.forEach(async channel => {
23                  if (cm.options.indexOf('--no-send') === -1) {                  try {
24                      channel.send({                      if (cm.options.indexOf('--no-send') === -1) {
25                          embeds: [                          await channel.send({
26                              new MessageEmbed()                              embeds: [
27                              .setDescription(':closed_lock_with_key: This channel has been unlocked.')                                  new MessageEmbed()
28                          ]                                  .setDescription(':closed_lock_with_key: This channel has been unlocked.')
29                                ]
30                            });
31                        }
32    
33                        app.db.get('SELECT * FROM locks WHERE channel_id = ?', [channel.id], async (err, data) => {
34                            if (data || cm.options.indexOf('--force') !== -1) {
35                                let perm1;
36                                let perm;
37                                const data1 = data?.perms?.split(',');
38    
39                                if (data1) {
40                                    if (data1[0] === 'DENY') {
41                                        await (perm = false);
42                                    }
43                                    else if (data1[0] === 'NULL') {
44                                        await (perm = null);
45                                    }
46                                    else if (data1[0] === 'ALLOW') {
47                                        await (perm = true);
48                                    }
49        
50                                    if (data1[1] === 'DENY') {
51                                        await (perm1 = false);
52                                    }
53                                    else if (data1[1] === 'NULL') {
54                                        await (perm1 = null);
55                                    }
56                                    else if (data1[1] === 'ALLOW') {
57                                        await (perm1 = true);
58                                    }
59                                }
60                                
61                                if (cm.options.indexOf('--force') !== -1) {
62                                    await (perm1 = true);
63                                    await (perm = true);
64                                }
65    
66                                await console.log(channel.name);
67    
68                                try {
69                                    await channel.permissionOverwrites.edit(role, {
70                                        SEND_MESSAGES: perm,
71                                    });
72    
73                                    const gen = await msg.guild.roles.fetch(app.config.props[msg.guild.id].gen_role);
74    
75                                    await channel.permissionOverwrites.edit(gen, {
76                                        SEND_MESSAGES: perm1,
77                                    });
78                                }
79                                catch (e) {
80                                    console.log(e);
81                                }
82    
83                                await console.log(perm, perm1);
84    
85                                if (data) {
86                                    await app.db.get('DELETE FROM locks WHERE id = ?', [data?.id], async (err) => {});
87                                }
88                            }
89                      });                      });
90                  }                  }
91                                    catch(e) {
92                  channel.permissionOverwrites.edit(role, {                      console.log(e);
93                      SEND_MESSAGES: true,                  }
                 });  
94              });              });
95          }          }
96      }      }

Legend:
Removed from v.10  
changed lines
  Added in v.39

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26