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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 393 - (hide annotations)
Mon Jul 29 17:29:59 2024 UTC (8 months, 2 weeks ago) by rakin
File MIME type: application/typescript
File size: 4594 byte(s)
style: add license comments (#77)

* style: add license commits

* fix: shebang errors
1 rakin 393 /**
2     * This file is part of SudoBot.
3     *
4     * Copyright (C) 2021-2022 OSN Inc.
5     *
6     * SudoBot is free software; you can redistribute it and/or modify it
7     * under the terms of the GNU Affero General Public License as published by
8     * the Free Software Foundation, either version 3 of the License, or
9     * (at your option) any later version.
10     *
11     * SudoBot is distributed in the hope that it will be useful, but
12     * WITHOUT ANY WARRANTY; without even the implied warranty of
13     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14     * GNU Affero General Public License for more details.
15     *
16     * You should have received a copy of the GNU Affero General Public License
17     * along with SudoBot. If not, see <https://www.gnu.org/licenses/>.
18     */
19    
20 rakin 344 import { CommandInteraction, Message, Role, TextChannel, User } from 'discord.js';
21 rakin 51 import BaseCommand from '../../utils/structures/BaseCommand';
22     import DiscordClient from '../../client/Client';
23     import CommandOptions from '../../types/CommandOptions';
24     import InteractionOptions from '../../types/InteractionOptions';
25     import MessageEmbed from '../../client/MessageEmbed';
26    
27     export default class LockCommand extends BaseCommand {
28 rakin 206 supportsInteractions: boolean = true;
29 rakin 51
30     constructor() {
31     super('lock', 'moderation', []);
32     }
33    
34     async run(client: DiscordClient, msg: Message | CommandInteraction, options: CommandOptions | InteractionOptions) {
35     let channel: TextChannel = <TextChannel> msg.channel;
36     let role: Role = <Role> msg.guild!.roles.everyone;
37    
38 rakin 241 if (msg instanceof CommandInteraction)
39     await msg.deferReply({ ephemeral: true });
40    
41 rakin 51 if (options.isInteraction) {
42     if (options.options.getChannel('channel')) {
43     channel = await <TextChannel> options.options.getChannel('channel');
44     }
45    
46 rakin 244 if (options.options.getRole('role')) {
47 rakin 51 role = await <Role> options.options.getRole('role');
48     }
49     }
50     else {
51     if ((msg as Message).mentions.roles.first()) {
52     role = await <Role> (msg as Message).mentions.roles.first();
53     }
54     else if (options.normalArgs[0] && options.normalArgs[0] !== 'everyone') {
55     role = <Role> await (msg as Message).guild?.roles.fetch(options.normalArgs[0]);
56     }
57    
58     if ((msg as Message).mentions.channels.first()) {
59     channel = await <TextChannel> (msg as Message).mentions.channels.first();
60     }
61     else if (options.normalArgs[1]) {
62     channel = <TextChannel> await (msg as Message).guild?.channels.fetch(options.normalArgs[1]);
63     }
64    
65     if (!role) {
66     await msg.reply({
67     embeds: [
68     new MessageEmbed()
69     .setColor('#f14a60')
70     .setDescription(`Invalid role given.`)
71     ],
72     ephemeral: true
73     });
74    
75     return;
76     }
77    
78     if (!channel || channel.type !== 'GUILD_TEXT') {
79     await msg.reply({
80     embeds: [
81     new MessageEmbed()
82     .setColor('#f14a60')
83     .setDescription(`Invalid text channel given.`)
84     ],
85     ephemeral: true
86     });
87    
88     return;
89     }
90     }
91    
92     try {
93 rakin 241 const result = await client.channelLock.lock(channel, msg.member!.user as User, { sendConfirmation: true });
94 rakin 51
95 rakin 241 let error = null;
96 rakin 51
97 rakin 241 if (!result) {
98 rakin 242 error = 'This channel is already locked' + (role.id === msg.guild!.id ? '' : ' for the given role') + '.';
99 rakin 51 }
100 rakin 241
101     if (error) {
102     await this.deferReply(msg, {
103     content: error,
104     });
105    
106     return;
107 rakin 51 }
108    
109     if (options.isInteraction) {
110 rakin 241 await this.deferReply(msg, {
111 rakin 51 content: "Channel locked.",
112     });
113     }
114     else {
115     await (msg as Message).react('🔒');
116     }
117     }
118     catch (e) {
119     console.log(e);
120    
121     await msg.reply({
122     embeds: [
123     new MessageEmbed()
124     .setColor('#f14a60')
125     .setDescription(`Failed to lock channel. Maybe missing permissions?`)
126     ],
127     ephemeral: true
128     });
129    
130     return;
131     }
132     }
133     }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26