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

Diff of /trunk/src/commands/moderation/LockCommand.ts

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

revision 206 by rakin, Mon Jul 29 17:29:01 2024 UTC revision 241 by rakin, Mon Jul 29 17:29:10 2024 UTC
# Line 20  export default class LockCommand extends Line 20  export default class LockCommand extends
20          let channel: TextChannel = <TextChannel> msg.channel;          let channel: TextChannel = <TextChannel> msg.channel;
21          let role: Role = <Role> msg.guild!.roles.everyone;          let role: Role = <Role> msg.guild!.roles.everyone;
22    
23            if (msg instanceof CommandInteraction)
24                await msg.deferReply({ ephemeral: true });
25    
26          if (options.isInteraction) {          if (options.isInteraction) {
27              if (options.options.getChannel('channel')) {              if (options.options.getChannel('channel')) {
28                  channel = await <TextChannel> options.options.getChannel('channel');                  channel = await <TextChannel> options.options.getChannel('channel');
# Line 72  export default class LockCommand extends Line 75  export default class LockCommand extends
75          }          }
76    
77          try {          try {
78              let dbPerms;              const result = await client.channelLock.lock(channel, msg.member!.user as User, { sendConfirmation: true });
79    
80              let overWrites = await channel.permissionOverwrites.cache.get(role.id);              let error = null;
             let allowperms = await overWrites?.allow?.has(Permissions.FLAGS.SEND_MESSAGES);  
             let denyperms = await overWrites?.deny?.has(Permissions.FLAGS.SEND_MESSAGES);  
81    
82              if (allowperms && !denyperms) {              if (!result) {
83                  await (dbPerms = 'ALLOW');                  error = 'This channel is already locked.'; // If you want to force unlock, run this command with `--force` option or select `True` if using slash commands.';
             }  
             else if (!allowperms && denyperms) {  
                 await (dbPerms = 'DENY');  
             }  
             else if (!allowperms && !denyperms) {  
                 await (dbPerms = 'NULL');  
84              }              }
85    
86                            if (error) {
87              await client.db.get('INSERT INTO locks(channel_id, perms, date) VALUES(?, ?, ?)', [channel.id, dbPerms, new Date().toISOString()], async (err: any) => {                  await this.deferReply(msg, {
88                  if (err)                      content: error,
89                      console.log(err);                  });
90                    
91                  try {                  return;
92                      await channel.permissionOverwrites.edit(role, {              }
                         SEND_MESSAGES: false,  
                     });  
                 }  
                 catch (e) {  
                     console.log(e);  
                 }  
             })  
     
             await channel.send({  
                 embeds: [  
                     new MessageEmbed()  
                     .setColor('#007bff')  
                     .setDescription(`:lock: This channel has been locked.`)  
                 ]  
             });  
93                            
94              if (options.isInteraction) {              if (options.isInteraction) {
95                  await msg.reply({                  await this.deferReply(msg, {
96                      content: "Channel locked.",                      content: "Channel locked.",
                     ephemeral: true  
97                  });                  });
98              }              }
99              else {              else {

Legend:
Removed from v.206  
changed lines
  Added in v.241

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26