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

Annotation of /trunk/src/commands/moderation/UnlockCommand.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: 6129 byte(s)
Release version 2.0
1 rakin 51 import { BanOptions, CommandInteraction, EmojiIdentifierResolvable, GuildMember, Interaction, Message, Permissions, Role, TextChannel, User } from 'discord.js';
2     import BaseCommand from '../../utils/structures/BaseCommand';
3     import DiscordClient from '../../client/Client';
4     import CommandOptions from '../../types/CommandOptions';
5     import InteractionOptions from '../../types/InteractionOptions';
6     import MessageEmbed from '../../client/MessageEmbed';
7     import getUser from '../../utils/getUser';
8     import getMember from '../../utils/getMember';
9     import History from '../../automod/History';
10     import { fetchEmoji } from '../../utils/Emoji';
11    
12     export default class UnlockCommand extends BaseCommand {
13     supportsInteractions: boolean = true;
14    
15     constructor() {
16     super('unlock', 'moderation', []);
17     }
18    
19     async run(client: DiscordClient, msg: Message | CommandInteraction, options: CommandOptions | InteractionOptions) {
20     let channel: TextChannel = <TextChannel> msg.channel;
21     let role: Role = <Role> msg.guild!.roles.everyone;
22     const force = options.isInteraction ? options.options.getBoolean('force') === true : (options.options.indexOf('--force') !== -1);
23    
24     if (options.isInteraction) {
25     if (options.options.getChannel('channel')) {
26     channel = await <TextChannel> options.options.getChannel('channel');
27     }
28    
29     if (options.options.getChannel('role')) {
30     role = await <Role> options.options.getRole('role');
31     }
32     }
33     else {
34     if ((msg as Message).mentions.roles.first()) {
35     role = await <Role> (msg as Message).mentions.roles.first();
36     }
37     else if (options.normalArgs[0] && options.normalArgs[0] !== 'everyone') {
38     role = <Role> await (msg as Message).guild?.roles.fetch(options.normalArgs[0]);
39     }
40    
41     if ((msg as Message).mentions.channels.first()) {
42     channel = await <TextChannel> (msg as Message).mentions.channels.first();
43     }
44     else if (options.normalArgs[1]) {
45     channel = <TextChannel> await (msg as Message).guild?.channels.fetch(options.normalArgs[1]);
46     }
47    
48     if (!role) {
49     await msg.reply({
50     embeds: [
51     new MessageEmbed()
52     .setColor('#f14a60')
53     .setDescription(`Invalid role given.`)
54     ],
55     ephemeral: true
56     });
57    
58     return;
59     }
60    
61     if (!channel || channel.type !== 'GUILD_TEXT') {
62     await msg.reply({
63     embeds: [
64     new MessageEmbed()
65     .setColor('#f14a60')
66     .setDescription(`Invalid text channel given.`)
67     ],
68     ephemeral: true
69     });
70    
71     return;
72     }
73     }
74    
75     try {
76     client.db.get('SELECT * FROM locks WHERE channel_id = ?', [channel.id], async (err: any, data: any) => {
77     if (data || force) {
78     let perm1;
79     let perm;
80     const data1 = data?.perms?.split(',');
81    
82     if (data1) {
83     if (data1[0] === 'DENY') {
84     await (perm = false);
85     }
86     else if (data1[0] === 'NULL') {
87     await (perm = null);
88     }
89     else if (data1[0] === 'ALLOW') {
90     await (perm = true);
91     }
92    
93     if (data1[1] === 'DENY') {
94     await (perm1 = false);
95     }
96     else if (data1[1] === 'NULL') {
97     await (perm1 = null);
98     }
99     else if (data1[1] === 'ALLOW') {
100     await (perm1 = true);
101     }
102     }
103    
104     if (force) {
105     await (perm1 = true);
106     await (perm = true);
107     }
108    
109     await console.log(channel.name);
110    
111     try {
112     await channel.permissionOverwrites.edit(role, {
113     SEND_MESSAGES: perm,
114     });
115    
116     const gen = await msg.guild!.roles.fetch(client.config.props[msg.guild!.id].gen_role);
117    
118     await channel.permissionOverwrites.edit(gen!, {
119     SEND_MESSAGES: perm1,
120     });
121     }
122     catch (e) {
123     console.log(e);
124     }
125    
126     await console.log(perm, perm1);
127    
128     if (data) {
129     await client.db.get('DELETE FROM locks WHERE id = ?', [data?.id], async (err: any) => {});
130     }
131     }
132     });
133    
134     if (options.isInteraction) {
135     await msg.reply({
136     content: "Channel unlocked.",
137     ephemeral: true
138     });
139     }
140     else {
141     await (msg as Message).react('🔓');
142     }
143    
144     await channel.send({
145     embeds: [
146     new MessageEmbed()
147     .setColor('#007bff')
148     .setDescription(`:closed_lock_with_key: This channel has been unlocked.`)
149     ]
150     });
151     }
152     catch (e) {
153     console.log(e);
154    
155     await msg.reply({
156     embeds: [
157     new MessageEmbed()
158     .setColor('#f14a60')
159     .setDescription(`Failed to unlock channel. Maybe missing permissions?`)
160     ],
161     ephemeral: true
162     });
163    
164     return;
165     }
166     }
167     }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26