/[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 341 - (hide annotations)
Mon Jul 29 17:29:38 2024 UTC (8 months, 2 weeks ago) by rakin
File MIME type: application/typescript
File size: 4180 byte(s)
refactor: removing using the old history manager
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    
8     export default class UnlockCommand extends BaseCommand {
9     supportsInteractions: boolean = true;
10    
11     constructor() {
12     super('unlock', 'moderation', []);
13     }
14    
15     async run(client: DiscordClient, msg: Message | CommandInteraction, options: CommandOptions | InteractionOptions) {
16     let channel: TextChannel = <TextChannel> msg.channel;
17     let role: Role = <Role> msg.guild!.roles.everyone;
18 rakin 241
19     if (msg instanceof CommandInteraction)
20     await msg.deferReply({ ephemeral: true });
21    
22 rakin 51 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 rakin 244 if (options.options.getRole('role')) {
30 rakin 51 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 rakin 241 const result = await client.channelLock.unlock(channel, { sendConfirmation: true, force });
77     let error = null;
78 rakin 51
79 rakin 241 if (!result) {
80 rakin 242 error = 'This channel wasn\'t locked' + (role.id === msg.guild!.id ? '' : ' for the given role') + '. If you want to force unlock, run this command with `--force` option or select `True` if using slash commands.';
81 rakin 241 }
82 rakin 51
83 rakin 241 if (error) {
84     await this.deferReply(msg, {
85     content: error,
86     });
87 rakin 51
88 rakin 241 return;
89     }
90    
91     if (options.isInteraction) {
92     await this.deferReply(msg, {
93     content: "Channel unlocked.",
94 rakin 51 });
95 rakin 241 }
96     else {
97     await (msg as Message).react('🔓');
98     }
99 rakin 51 }
100     catch (e) {
101     console.log(e);
102    
103     await msg.reply({
104     embeds: [
105     new MessageEmbed()
106     .setColor('#f14a60')
107     .setDescription(`Failed to unlock channel. Maybe missing permissions?`)
108     ],
109     ephemeral: true
110     });
111    
112     return;
113     }
114     }
115     }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26