1 |
rakin |
344 |
import { CommandInteraction, Message, Role, TextChannel, User } from 'discord.js'; |
2 |
rakin |
51 |
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 |
rakin |
206 |
supportsInteractions: boolean = true; |
10 |
rakin |
51 |
|
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 |
rakin |
241 |
if (msg instanceof CommandInteraction) |
20 |
|
|
await msg.deferReply({ ephemeral: true }); |
21 |
|
|
|
22 |
rakin |
51 |
if (options.isInteraction) { |
23 |
|
|
if (options.options.getChannel('channel')) { |
24 |
|
|
channel = await <TextChannel> options.options.getChannel('channel'); |
25 |
|
|
} |
26 |
|
|
|
27 |
rakin |
244 |
if (options.options.getRole('role')) { |
28 |
rakin |
51 |
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 |
rakin |
241 |
const result = await client.channelLock.lock(channel, msg.member!.user as User, { sendConfirmation: true }); |
75 |
rakin |
51 |
|
76 |
rakin |
241 |
let error = null; |
77 |
rakin |
51 |
|
78 |
rakin |
241 |
if (!result) { |
79 |
rakin |
242 |
error = 'This channel is already locked' + (role.id === msg.guild!.id ? '' : ' for the given role') + '.'; |
80 |
rakin |
51 |
} |
81 |
rakin |
241 |
|
82 |
|
|
if (error) { |
83 |
|
|
await this.deferReply(msg, { |
84 |
|
|
content: error, |
85 |
|
|
}); |
86 |
|
|
|
87 |
|
|
return; |
88 |
rakin |
51 |
} |
89 |
|
|
|
90 |
|
|
if (options.isInteraction) { |
91 |
rakin |
241 |
await this.deferReply(msg, { |
92 |
rakin |
51 |
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 |
|
|
} |