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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 344 - (show annotations)
Mon Jul 29 17:29:40 2024 UTC (8 months, 1 week ago) by rakin
File MIME type: application/typescript
File size: 3870 byte(s)
chore: eslint autofix
1 import { CommandInteraction, Message, 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 LockCommand extends BaseCommand {
9 supportsInteractions: boolean = true;
10
11 constructor() {
12 super('lock', '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
19 if (msg instanceof CommandInteraction)
20 await msg.deferReply({ ephemeral: true });
21
22 if (options.isInteraction) {
23 if (options.options.getChannel('channel')) {
24 channel = await <TextChannel> options.options.getChannel('channel');
25 }
26
27 if (options.options.getRole('role')) {
28 role = await <Role> options.options.getRole('role');
29 }
30 }
31 else {
32 if ((msg as Message).mentions.roles.first()) {
33 role = await <Role> (msg as Message).mentions.roles.first();
34 }
35 else if (options.normalArgs[0] && options.normalArgs[0] !== 'everyone') {
36 role = <Role> await (msg as Message).guild?.roles.fetch(options.normalArgs[0]);
37 }
38
39 if ((msg as Message).mentions.channels.first()) {
40 channel = await <TextChannel> (msg as Message).mentions.channels.first();
41 }
42 else if (options.normalArgs[1]) {
43 channel = <TextChannel> await (msg as Message).guild?.channels.fetch(options.normalArgs[1]);
44 }
45
46 if (!role) {
47 await msg.reply({
48 embeds: [
49 new MessageEmbed()
50 .setColor('#f14a60')
51 .setDescription(`Invalid role given.`)
52 ],
53 ephemeral: true
54 });
55
56 return;
57 }
58
59 if (!channel || channel.type !== 'GUILD_TEXT') {
60 await msg.reply({
61 embeds: [
62 new MessageEmbed()
63 .setColor('#f14a60')
64 .setDescription(`Invalid text channel given.`)
65 ],
66 ephemeral: true
67 });
68
69 return;
70 }
71 }
72
73 try {
74 const result = await client.channelLock.lock(channel, msg.member!.user as User, { sendConfirmation: true });
75
76 let error = null;
77
78 if (!result) {
79 error = 'This channel is already locked' + (role.id === msg.guild!.id ? '' : ' for the given role') + '.';
80 }
81
82 if (error) {
83 await this.deferReply(msg, {
84 content: error,
85 });
86
87 return;
88 }
89
90 if (options.isInteraction) {
91 await this.deferReply(msg, {
92 content: "Channel locked.",
93 });
94 }
95 else {
96 await (msg as Message).react('🔒');
97 }
98 }
99 catch (e) {
100 console.log(e);
101
102 await msg.reply({
103 embeds: [
104 new MessageEmbed()
105 .setColor('#f14a60')
106 .setDescription(`Failed to lock channel. Maybe missing permissions?`)
107 ],
108 ephemeral: true
109 });
110
111 return;
112 }
113 }
114 }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26