1 |
rakin |
51 |
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 (options.isInteraction) { |
24 |
|
|
if (options.options.getChannel('channel')) { |
25 |
|
|
channel = await <TextChannel> options.options.getChannel('channel'); |
26 |
|
|
} |
27 |
|
|
|
28 |
|
|
if (options.options.getChannel('role')) { |
29 |
|
|
role = await <Role> options.options.getRole('role'); |
30 |
|
|
} |
31 |
|
|
} |
32 |
|
|
else { |
33 |
|
|
if ((msg as Message).mentions.roles.first()) { |
34 |
|
|
role = await <Role> (msg as Message).mentions.roles.first(); |
35 |
|
|
} |
36 |
|
|
else if (options.normalArgs[0] && options.normalArgs[0] !== 'everyone') { |
37 |
|
|
role = <Role> await (msg as Message).guild?.roles.fetch(options.normalArgs[0]); |
38 |
|
|
} |
39 |
|
|
|
40 |
|
|
if ((msg as Message).mentions.channels.first()) { |
41 |
|
|
channel = await <TextChannel> (msg as Message).mentions.channels.first(); |
42 |
|
|
} |
43 |
|
|
else if (options.normalArgs[1]) { |
44 |
|
|
channel = <TextChannel> await (msg as Message).guild?.channels.fetch(options.normalArgs[1]); |
45 |
|
|
} |
46 |
|
|
|
47 |
|
|
if (!role) { |
48 |
|
|
await msg.reply({ |
49 |
|
|
embeds: [ |
50 |
|
|
new MessageEmbed() |
51 |
|
|
.setColor('#f14a60') |
52 |
|
|
.setDescription(`Invalid role given.`) |
53 |
|
|
], |
54 |
|
|
ephemeral: true |
55 |
|
|
}); |
56 |
|
|
|
57 |
|
|
return; |
58 |
|
|
} |
59 |
|
|
|
60 |
|
|
if (!channel || channel.type !== 'GUILD_TEXT') { |
61 |
|
|
await msg.reply({ |
62 |
|
|
embeds: [ |
63 |
|
|
new MessageEmbed() |
64 |
|
|
.setColor('#f14a60') |
65 |
|
|
.setDescription(`Invalid text channel given.`) |
66 |
|
|
], |
67 |
|
|
ephemeral: true |
68 |
|
|
}); |
69 |
|
|
|
70 |
|
|
return; |
71 |
|
|
} |
72 |
|
|
} |
73 |
|
|
|
74 |
|
|
try { |
75 |
|
|
let dbPerms; |
76 |
|
|
|
77 |
|
|
let overWrites = await channel.permissionOverwrites.cache.get(role.id); |
78 |
|
|
let allowperms = await overWrites?.allow?.has(Permissions.FLAGS.SEND_MESSAGES); |
79 |
|
|
let denyperms = await overWrites?.deny?.has(Permissions.FLAGS.SEND_MESSAGES); |
80 |
|
|
|
81 |
|
|
if (allowperms && !denyperms) { |
82 |
|
|
await (dbPerms = 'ALLOW'); |
83 |
|
|
} |
84 |
|
|
else if (!allowperms && denyperms) { |
85 |
|
|
await (dbPerms = 'DENY'); |
86 |
|
|
} |
87 |
|
|
else if (!allowperms && !denyperms) { |
88 |
|
|
await (dbPerms = 'NULL'); |
89 |
|
|
} |
90 |
|
|
|
91 |
|
|
|
92 |
rakin |
103 |
await client.db.get('INSERT INTO locks(channel_id, perms, date) VALUES(?, ?, ?)', [channel.id, dbPerms, new Date().toISOString()], async (err: any) => { |
93 |
rakin |
51 |
if (err) |
94 |
|
|
console.log(err); |
95 |
|
|
|
96 |
|
|
try { |
97 |
|
|
await channel.permissionOverwrites.edit(role, { |
98 |
|
|
SEND_MESSAGES: false, |
99 |
|
|
}); |
100 |
|
|
} |
101 |
|
|
catch (e) { |
102 |
|
|
console.log(e); |
103 |
|
|
} |
104 |
|
|
}) |
105 |
|
|
|
106 |
|
|
await channel.send({ |
107 |
|
|
embeds: [ |
108 |
|
|
new MessageEmbed() |
109 |
|
|
.setColor('#007bff') |
110 |
|
|
.setDescription(`:lock: This channel has been locked.`) |
111 |
|
|
] |
112 |
|
|
}); |
113 |
|
|
|
114 |
|
|
if (options.isInteraction) { |
115 |
|
|
await msg.reply({ |
116 |
|
|
content: "Channel locked.", |
117 |
|
|
ephemeral: true |
118 |
|
|
}); |
119 |
|
|
} |
120 |
|
|
else { |
121 |
|
|
await (msg as Message).react('🔒'); |
122 |
|
|
} |
123 |
|
|
} |
124 |
|
|
catch (e) { |
125 |
|
|
console.log(e); |
126 |
|
|
|
127 |
|
|
await msg.reply({ |
128 |
|
|
embeds: [ |
129 |
|
|
new MessageEmbed() |
130 |
|
|
.setColor('#f14a60') |
131 |
|
|
.setDescription(`Failed to lock channel. Maybe missing permissions?`) |
132 |
|
|
], |
133 |
|
|
ephemeral: true |
134 |
|
|
}); |
135 |
|
|
|
136 |
|
|
return; |
137 |
|
|
} |
138 |
|
|
} |
139 |
|
|
} |