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

Contents of /branches/2.x/src/commands/moderation/LockCommand.ts

Parent Directory Parent Directory | Revision Log Revision Log


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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26