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

Contents of /trunk/commands/lock.js

Parent Directory Parent Directory | Revision Log Revision Log


Revision 39 - (show annotations)
Mon Jul 29 17:28:19 2024 UTC (8 months, 1 week ago) by rakin
File MIME type: text/javascript
File size: 4336 byte(s)
Updated anti-raid systems
1 const { Permissions } = require("discord.js");
2 const MessageEmbed = require("../src/MessageEmbed");
3
4 module.exports = {
5 needsOptionParse: true,
6 async handle(msg, cm) {
7 let channel;
8
9 if (typeof cm.normalArgs[0] === 'undefined') {
10 channel = msg.channel;
11 }
12
13 let role = msg.guild.roles.everyone;
14
15 if (role) {
16 if (!channel) {
17 channel = msg.mentions?.channels?.first();
18
19 if (!channel) {
20 channel = msg.guild.channels.cache.find(c => c.id === cm.normalArgs[0]);
21 }
22 }
23
24 if (channel) {
25 try {
26 if (cm.options.indexOf('--no-send') === -1) {
27 channel.send({
28 embeds: [
29 new MessageEmbed()
30 .setDescription(':lock: This channel has been locked.')
31 ]
32 });
33 }
34
35 let dbPerms;
36 let dbPerms1;
37
38 let overWrites = await channel.permissionOverwrites.cache.get(role.id);
39 let allowperms = await overWrites?.allow?.has(Permissions.FLAGS.SEND_MESSAGES);
40 let denyperms = await overWrites?.deny?.has(Permissions.FLAGS.SEND_MESSAGES);
41
42 let role1 = await channel.guild.roles.fetch(app.config.props[channel.guild.id].gen_role);
43
44 let overWrites1 = await channel.permissionOverwrites.cache.get(role1.id);
45 let allowperms1 = await overWrites1?.allow?.has(Permissions.FLAGS.SEND_MESSAGES);
46 let denyperms1 = await overWrites1?.deny?.has(Permissions.FLAGS.SEND_MESSAGES);
47
48 if (allowperms && !denyperms) {
49 await (dbPerms = 'ALLOW');
50 }
51 else if (!allowperms && denyperms) {
52 await (dbPerms = 'DENY');
53 }
54 else if (!allowperms && !denyperms) {
55 await (dbPerms = 'NULL');
56 }
57
58 if (allowperms1 && !denyperms1) {
59 await (dbPerms1 = 'ALLOW');
60 }
61 else if (!allowperms1 && denyperms1) {
62 await (dbPerms1 = 'DENY');
63 }
64 else if (!allowperms1 && !denyperms1) {
65 await (dbPerms1 = 'NULL');
66 }
67
68 await app.db.get('INSERT INTO locks(channel_id, perms, date) VALUES(?, ?, ?)', [channel.id, dbPerms + ',' + dbPerms1, new Date().toISOString()], async (err) => {
69 if (err)
70 console.log(err);
71
72 try {
73 await channel.permissionOverwrites.edit(role, {
74 SEND_MESSAGES: false,
75 });
76 }
77 catch (e) {
78 console.log(e);
79 }
80
81 try {
82 const gen = await channel.guild.roles.fetch(app.config.props[channel.guild.id].gen_role);
83
84 await channel.permissionOverwrites.edit(gen, {
85 SEND_MESSAGES: false,
86 });
87 }
88 catch (e) {
89 console.log(e);
90 }
91 })
92 }
93 catch (e) {
94 console.log(e);
95 }
96 }
97 else {
98 console.log('invalid channel');
99 }
100 }
101
102 // await msg.reply({
103 // embeds: [
104 // new MessageEmbed()
105 // .setDescription(`The user ${user.user.tag} has been beaned`)
106 // .addFields([
107 // {
108 // name: "Reason",
109 // value: typeof reason === 'undefined' ? '*No reason provided*' : reason
110 // }
111 // ])
112 // ]
113 // });
114 }
115 };

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26