/[sudobot]/branches/2.x/src/commands/moderation/UnlockCommand.ts
ViewVC logotype

Annotation of /branches/2.x/src/commands/moderation/UnlockCommand.ts

Parent Directory Parent Directory | Revision Log Revision Log


Revision 577 - (hide annotations)
Mon Jul 29 18:52:37 2024 UTC (8 months ago) by rakinar2
File MIME type: application/typescript
File size: 4363 byte(s)
chore: add old version archive branches (2.x to 9.x-dev)
1 rakinar2 577 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    
23     if (msg instanceof CommandInteraction)
24     await msg.deferReply({ ephemeral: true });
25    
26     const force = options.isInteraction ? options.options.getBoolean('force') === true : (options.options.indexOf('--force') !== -1);
27    
28     if (options.isInteraction) {
29     if (options.options.getChannel('channel')) {
30     channel = await <TextChannel> options.options.getChannel('channel');
31     }
32    
33     if (options.options.getRole('role')) {
34     role = await <Role> options.options.getRole('role');
35     }
36     }
37     else {
38     if ((msg as Message).mentions.roles.first()) {
39     role = await <Role> (msg as Message).mentions.roles.first();
40     }
41     else if (options.normalArgs[0] && options.normalArgs[0] !== 'everyone') {
42     role = <Role> await (msg as Message).guild?.roles.fetch(options.normalArgs[0]);
43     }
44    
45     if ((msg as Message).mentions.channels.first()) {
46     channel = await <TextChannel> (msg as Message).mentions.channels.first();
47     }
48     else if (options.normalArgs[1]) {
49     channel = <TextChannel> await (msg as Message).guild?.channels.fetch(options.normalArgs[1]);
50     }
51    
52     if (!role) {
53     await msg.reply({
54     embeds: [
55     new MessageEmbed()
56     .setColor('#f14a60')
57     .setDescription(`Invalid role given.`)
58     ],
59     ephemeral: true
60     });
61    
62     return;
63     }
64    
65     if (!channel || channel.type !== 'GUILD_TEXT') {
66     await msg.reply({
67     embeds: [
68     new MessageEmbed()
69     .setColor('#f14a60')
70     .setDescription(`Invalid text channel given.`)
71     ],
72     ephemeral: true
73     });
74    
75     return;
76     }
77     }
78    
79     try {
80     const result = await client.channelLock.unlock(channel, { sendConfirmation: true, force });
81     let error = null;
82    
83     if (!result) {
84     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.';
85     }
86    
87     if (error) {
88     await this.deferReply(msg, {
89     content: error,
90     });
91    
92     return;
93     }
94    
95     if (options.isInteraction) {
96     await this.deferReply(msg, {
97     content: "Channel unlocked.",
98     });
99     }
100     else {
101     await (msg as Message).react('🔓');
102     }
103     }
104     catch (e) {
105     console.log(e);
106    
107     await msg.reply({
108     embeds: [
109     new MessageEmbed()
110     .setColor('#f14a60')
111     .setDescription(`Failed to unlock channel. Maybe missing permissions?`)
112     ],
113     ephemeral: true
114     });
115    
116     return;
117     }
118     }
119     }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26