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

Annotation of /trunk/src/commands/moderation/UnlockallCommand.ts

Parent Directory Parent Directory | Revision Log Revision Log


Revision 51 - (hide annotations)
Mon Jul 29 17:28:23 2024 UTC (8 months, 1 week ago) by rakin
File MIME type: application/typescript
File size: 4567 byte(s)
Release version 2.0
1 rakin 51 import { Collection, CommandInteraction, GuildBasedChannel, GuildChannel, Message, Permissions, Role, TextChannel } from 'discord.js';
2     import BaseCommand from '../../utils/structures/BaseCommand';
3     import CommandOptions from '../../types/CommandOptions';
4     import InteractionOptions from '../../types/InteractionOptions';
5     import DiscordClient from '../../client/Client';
6     import MessageEmbed from '../../client/MessageEmbed';
7    
8     export async function unlockAll(client: DiscordClient, role: Role, msg: Message | CommandInteraction, options: CommandOptions | InteractionOptions, channels: Collection <string, TextChannel>, force: boolean) {
9     if (role) {
10     const gen = await msg.guild!.roles.fetch(client.config.props[msg.guild!.id].gen_role);
11    
12     channels.forEach(async channel => {
13     try {
14     await channel.send({
15     embeds: [
16     new MessageEmbed()
17     .setDescription(':closed_lock_with_key: This channel has been unlocked.')
18     ]
19     });
20    
21     client.db.get('SELECT * FROM locks WHERE channel_id = ?', [channel.id], async (err: any, data: any) => {
22     if (data || force) {
23     let perm1;
24     let perm;
25     const data1 = data?.perms?.split(',');
26    
27     if (data1) {
28     if (data1[0] === 'DENY') {
29     await (perm = false);
30     }
31     else if (data1[0] === 'NULL') {
32     await (perm = null);
33     }
34     else if (data1[0] === 'ALLOW') {
35     await (perm = true);
36     }
37    
38     if (data1[1] === 'DENY') {
39     await (perm1 = false);
40     }
41     else if (data1[1] === 'NULL') {
42     await (perm1 = null);
43     }
44     else if (data1[1] === 'ALLOW') {
45     await (perm1 = true);
46     }
47     }
48    
49     if (force) {
50     await (perm1 = true);
51     await (perm = true);
52     }
53    
54     await console.log(channel.name);
55    
56     try {
57     await channel.permissionOverwrites.edit(role, {
58     SEND_MESSAGES: perm,
59     });
60    
61     await channel.permissionOverwrites.edit(gen!, {
62     SEND_MESSAGES: perm1,
63     });
64     }
65     catch (e) {
66     console.log(e);
67     }
68    
69     await console.log(perm, perm1);
70    
71     if (data) {
72     await client.db.get('DELETE FROM locks WHERE id = ?', [data?.id], async (err: any) => {});
73     }
74     }
75     });
76     }
77     catch(e) {
78     console.log(e);
79     }
80     });
81     }
82     }
83    
84     export default class UnlockallCommand extends BaseCommand {
85     supportsInteractions: boolean = true;
86    
87     constructor() {
88     super('unlockall', 'moderation', []);
89     }
90    
91     async run(client: DiscordClient, msg: Message | CommandInteraction, options: CommandOptions | InteractionOptions) {
92     const raid = options.isInteraction ? options.options.getBoolean('raid') === true : (options.options.indexOf('--raid') !== -1);
93    
94     let role: Role = <Role> msg.guild!.roles.everyone;
95     const force = options.isInteraction ? options.options.getBoolean('force') === true : (options.options.indexOf('--force') !== -1);
96    
97     if (options.isInteraction) {
98     if (options.options.getChannel('role')) {
99     role = await <Role> options.options.getRole('role');
100     }
101     }
102     else {
103     if ((msg as Message).mentions.roles.first()) {
104     role = await <Role> (msg as Message).mentions.roles.first();
105     }
106     else if (options.normalArgs[0] && options.normalArgs[0] !== 'everyone') {
107     role = <Role> await (msg as Message).guild?.roles.fetch(options.normalArgs[0]);
108     }
109    
110     if (!role) {
111     await msg.reply({
112     embeds: [
113     new MessageEmbed()
114     .setColor('#f14a60')
115     .setDescription(`Invalid role given.`)
116     ],
117     ephemeral: true
118     });
119    
120     return;
121     }
122     }
123    
124     const channels: Collection <string, GuildBasedChannel> = await msg.guild!.channels.cache.filter(c => (
125     (!raid && (client.config.props[msg.guild!.id].lockall.indexOf(c.id) !== -1 || client.config.props[msg.guild!.id].lockall.indexOf(c.parent?.id) !== -1)) ||
126     (raid && (
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)) ||
128     (!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))
129     ))) && c.type === 'GUILD_TEXT'
130     );
131    
132     await unlockAll(client, role, msg, options, channels as Collection <string, TextChannel>, force);
133    
134     if (options.isInteraction) {
135     await msg.reply({
136     content: "The channels are unlocked.",
137     ephemeral: true
138     });
139     }
140     else {
141     await (msg as Message).react('🔓');
142     }
143     }
144     }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26