/[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 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, User } 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 LockCommand extends BaseCommand {  export default class LockCommand extends BaseCommand {
28      supportsInteractions: boolean = true;          supportsInteractions: boolean = true;    
# Line 20  export default class LockCommand extends Line 35  export default class LockCommand extends
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          if (options.isInteraction) {          if (options.isInteraction) {
42              if (options.options.getChannel('channel')) {              if (options.options.getChannel('channel')) {
43                  channel = await <TextChannel> options.options.getChannel('channel');                  channel = await <TextChannel> options.options.getChannel('channel');
44              }              }
45    
46              if (options.options.getChannel('role')) {              if (options.options.getRole('role')) {
47                  role = await <Role> options.options.getRole('role');                  role = await <Role> options.options.getRole('role');
48              }              }
49          }          }
# Line 72  export default class LockCommand extends Line 90  export default class LockCommand extends
90          }          }
91    
92          try {          try {
93              let dbPerms;              const result = await client.channelLock.lock(channel, msg.member!.user as User, { sendConfirmation: true });
94    
95              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);  
96    
97              if (allowperms && !denyperms) {              if (!result) {
98                  await (dbPerms = 'ALLOW');                  error = 'This channel is already locked' + (role.id === msg.guild!.id ? '' : ' for the given role') + '.';
             }  
             else if (!allowperms && denyperms) {  
                 await (dbPerms = 'DENY');  
             }  
             else if (!allowperms && !denyperms) {  
                 await (dbPerms = 'NULL');  
99              }              }
100    
101                            if (error) {
102              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, {
103                  if (err)                      content: error,
104                      console.log(err);                  });
105                    
106                  try {                  return;
107                      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.`)  
                 ]  
             });  
108                            
109              if (options.isInteraction) {              if (options.isInteraction) {
110                  await msg.reply({                  await this.deferReply(msg, {
111                      content: "Channel locked.",                      content: "Channel locked.",
                     ephemeral: true  
112                  });                  });
113              }              }
114              else {              else {

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26