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

Diff of /trunk/src/commands/moderation/LockallCommand.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 103 by rakin, Mon Jul 29 17:28:36 2024 UTC
# Line 7  import MessageEmbed from '../../client/M Line 7  import MessageEmbed from '../../client/M
7    
8  export async function lockAll(client: DiscordClient, role: Role, channels: Collection <string, TextChannel>, send: boolean = true) {  export async function lockAll(client: DiscordClient, role: Role, channels: Collection <string, TextChannel>, send: boolean = true) {
9      if (role) {      if (role) {
10          let role1 = await channels.first()!.guild.roles.fetch(client.config.props[channels.first()!.guild.id].gen_role);          // const gen = await channels.first()!.guild.roles.fetch(client.config.props[channels.first()!.guild.id].gen_role);
         const gen = await channels.first()!.guild.roles.fetch(client.config.props[channels.first()!.guild.id].gen_role);  
11    
12          await channels.forEach(async channel => {          await channels.forEach(async channel => {
13              try {              try {
# Line 22  export async function lockAll(client: Di Line 21  export async function lockAll(client: Di
21                  }                  }
22    
23                  let dbPerms;                  let dbPerms;
                 let dbPerms1;  
24    
25                  let overWrites = await channel.permissionOverwrites.cache.get(role.id);                  let overWrites = await channel.permissionOverwrites.cache.get(role.id);
26                  let allowperms = await overWrites?.allow?.has(Permissions.FLAGS.SEND_MESSAGES);                  let allowperms = await overWrites?.allow?.has(Permissions.FLAGS.SEND_MESSAGES);
27                  let denyperms = await overWrites?.deny?.has(Permissions.FLAGS.SEND_MESSAGES);                  let denyperms = await overWrites?.deny?.has(Permissions.FLAGS.SEND_MESSAGES);
28    
                 let overWrites1 = await channel.permissionOverwrites.cache.get(role1!.id);  
                 let allowperms1 = await overWrites1?.allow?.has(Permissions.FLAGS.SEND_MESSAGES);  
                 let denyperms1 = await overWrites1?.deny?.has(Permissions.FLAGS.SEND_MESSAGES);  
   
29                  if (allowperms && !denyperms) {                  if (allowperms && !denyperms) {
30                      await (dbPerms = 'ALLOW');                      await (dbPerms = 'ALLOW');
31                  }                  }
# Line 42  export async function lockAll(client: Di Line 36  export async function lockAll(client: Di
36                      await (dbPerms = 'NULL');                      await (dbPerms = 'NULL');
37                  }                  }
38    
39                  if (allowperms1 && !denyperms1) {                  console.log(dbPerms);
                     await (dbPerms1 = 'ALLOW');  
                 }  
                 else if (!allowperms1 && denyperms1) {  
                     await (dbPerms1 = 'DENY');  
                 }  
                 else if (!allowperms1 && !denyperms1) {  
                     await (dbPerms1 = 'NULL');  
                 }  
40                                    
41                  await client.db.get('INSERT INTO locks(channel_id, perms, date) VALUES(?, ?, ?)', [channel.id, dbPerms + ',' + dbPerms1, new Date().toISOString()], async (err: any) => {  
42                    await client.db.get('INSERT INTO locks(channel_id, perms, date) VALUES(?, ?, ?)', [channel.id, dbPerms, new Date().toISOString()], async (err: any) => {
43                      if (err)                      if (err)
44                          console.log(err);                          console.log(err);
45                                            
# Line 64  export async function lockAll(client: Di Line 51  export async function lockAll(client: Di
51                      catch (e) {                      catch (e) {
52                          console.log(e);                          console.log(e);
53                      }                      }
   
                     try {  
                         await channel.permissionOverwrites.edit(gen!, {  
                             SEND_MESSAGES: false,  
                         });  
                     }  
                     catch (e) {  
                         console.log(e);  
                     }  
54                  })                  })
55              }              }
56              catch (e) {              catch (e) {
# Line 90  export default class LockallCommand exte Line 68  export default class LockallCommand exte
68      }      }
69    
70      async run(client: DiscordClient, msg: Message | CommandInteraction, options: CommandOptions | InteractionOptions) {      async run(client: DiscordClient, msg: Message | CommandInteraction, options: CommandOptions | InteractionOptions) {
71            if (!options.isInteraction && typeof options.args[0] === 'undefined') {
72                await msg.reply({
73                    embeds: [
74                        new MessageEmbed()
75                        .setColor('#f14a60')
76                        .setDescription(`This command requires at least one argument.`)
77                    ]
78                });
79    
80                return;
81            }
82    
83          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);
84    
85          let role: Role = <Role> msg.guild!.roles.everyone;          let role: Role = <Role> msg.guild!.roles.everyone;
86            let lockall: string[] = [];
87          // 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);
88    
89          if (options.isInteraction) {          if (options.isInteraction) {
90                lockall = options.options.getString('channels')!.split(' ');
91    
92              if (options.options.getChannel('role')) {              if (options.options.getChannel('role')) {
93                  role = await <Role> options.options.getRole('role');                  role = await <Role> options.options.getRole('role');
94              }              }
# Line 104  export default class LockallCommand exte Line 97  export default class LockallCommand exte
97              if ((msg as Message).mentions.roles.first()) {              if ((msg as Message).mentions.roles.first()) {
98                  role = await <Role> (msg as Message).mentions.roles.first();                  role = await <Role> (msg as Message).mentions.roles.first();
99              }              }
100              else if (options.normalArgs[0] && options.normalArgs[0] !== 'everyone') {              else if (options.options.includes('-r') && options.normalArgs[options.options.indexOf('-r') + 1]) {
101                  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]);
102              }              }
103    
104              if (!role) {              if (!role) {
# Line 120  export default class LockallCommand exte Line 113  export default class LockallCommand exte
113            
114                  return;                  return;
115              }              }
116    
117                for (const a of options.args) {
118                    if (/^\d+$/g.test(a)) {
119                        lockall.push(a);
120                    }
121                }
122          }          }
123    
124          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)) ||  
125              (raid && (              (raid && (
126                  (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)) ||
127                  (!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))
128              ))) && c.type === 'GUILD_TEXT'              ))) && c.type === 'GUILD_TEXT'
129          );          ) : null;
130    
131            if (channels === null && !raid) {
132                channels = msg.guild!.channels.cache.filter(c2 => (lockall.includes(c2.id) || lockall.includes(c2.parent?.id!)) && c2.type === 'GUILD_TEXT')!;
133            }
134    
135          await lockAll(client, role, channels as Collection <string, TextChannel>, true);          await lockAll(client, role, channels as Collection <string, TextChannel>, true);
136    
137          if (options.isInteraction) {          if (options.isInteraction) {

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26