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

Contents of /trunk/commands/lockall.js

Parent Directory Parent Directory | Revision Log Revision Log


Revision 44 - (show annotations)
Mon Jul 29 17:28:20 2024 UTC (8 months, 1 week ago) by rakin
File MIME type: text/javascript
File size: 3873 byte(s)
Improved edited message scanning and added file filters
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 channels = app.config.get('lockall');
8
9 if (msg.mentions.channels.first()) {
10 channels = msg.mentions.channels;
11 }
12 else {
13 channels = await msg.guild.channels.cache.filter(c => channels.indexOf(c.id) !== -1 && c.type === 'GUILD_TEXT');
14 }
15
16 let role = msg.guild.roles.everyone;
17
18 await this.lockAll(role, channels, cm.options.indexOf('--no-send') === -1);
19 },
20 async lockAll(role, channels, send) {
21 if (role) {
22 await channels.forEach(async channel => {
23 try {
24 if (send) {
25 await channel.send({
26 embeds: [
27 new MessageEmbed()
28 .setDescription(':lock: This channel has been locked.')
29 ]
30 });
31 }
32
33 let dbPerms;
34 let dbPerms1;
35
36 let overWrites = await channel.permissionOverwrites.cache.get(role.id);
37 let allowperms = await overWrites?.allow?.has(Permissions.FLAGS.SEND_MESSAGES);
38 let denyperms = await overWrites?.deny?.has(Permissions.FLAGS.SEND_MESSAGES);
39
40 let role1 = await channel.guild.roles.fetch(app.config.props[channel.guild.id].gen_role);
41
42 let overWrites1 = await channel.permissionOverwrites.cache.get(role1.id);
43 let allowperms1 = await overWrites1?.allow?.has(Permissions.FLAGS.SEND_MESSAGES);
44 let denyperms1 = await overWrites1?.deny?.has(Permissions.FLAGS.SEND_MESSAGES);
45
46 if (allowperms && !denyperms) {
47 await (dbPerms = 'ALLOW');
48 }
49 else if (!allowperms && denyperms) {
50 await (dbPerms = 'DENY');
51 }
52 else if (!allowperms && !denyperms) {
53 await (dbPerms = 'NULL');
54 }
55
56 if (allowperms1 && !denyperms1) {
57 await (dbPerms1 = 'ALLOW');
58 }
59 else if (!allowperms1 && denyperms1) {
60 await (dbPerms1 = 'DENY');
61 }
62 else if (!allowperms1 && !denyperms1) {
63 await (dbPerms1 = 'NULL');
64 }
65
66 await app.db.get('INSERT INTO locks(channel_id, perms, date) VALUES(?, ?, ?)', [channel.id, dbPerms + ',' + dbPerms1, new Date().toISOString()], async (err) => {
67 if (err)
68 console.log(err);
69
70 try {
71 await channel.permissionOverwrites.edit(role, {
72 SEND_MESSAGES: false,
73 });
74 }
75 catch (e) {
76 console.log(e);
77 }
78
79 try {
80 const gen = await channel.guild.roles.fetch(app.config.props[channel.guild.id].gen_role);
81
82 await channel.permissionOverwrites.edit(gen, {
83 SEND_MESSAGES: false,
84 });
85 }
86 catch (e) {
87 console.log(e);
88 }
89 })
90 }
91 catch (e) {
92 console.log(e);
93 }
94 });
95 }
96 }
97 };

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26