1 |
import { BanOptions, CommandInteraction, EmojiIdentifierResolvable, GuildMember, Interaction, Message, Permissions, Role, TextChannel, User } from 'discord.js'; |
import { BanOptions, CommandInteraction, Message, Role, TextChannel, User } from 'discord.js'; |
2 |
import BaseCommand from '../../utils/structures/BaseCommand'; |
import BaseCommand from '../../utils/structures/BaseCommand'; |
3 |
import DiscordClient from '../../client/Client'; |
import DiscordClient from '../../client/Client'; |
4 |
import CommandOptions from '../../types/CommandOptions'; |
import CommandOptions from '../../types/CommandOptions'; |
5 |
import InteractionOptions from '../../types/InteractionOptions'; |
import InteractionOptions from '../../types/InteractionOptions'; |
6 |
import MessageEmbed from '../../client/MessageEmbed'; |
import MessageEmbed from '../../client/MessageEmbed'; |
|
import getUser from '../../utils/getUser'; |
|
|
import getMember from '../../utils/getMember'; |
|
|
import History from '../../automod/History'; |
|
|
import { fetchEmoji } from '../../utils/Emoji'; |
|
7 |
|
|
8 |
export default class LockCommand extends BaseCommand { |
export default class LockCommand extends BaseCommand { |
9 |
supportsInteractions: boolean = true; |
supportsInteractions: boolean = true; |
10 |
|
|
11 |
constructor() { |
constructor() { |
12 |
super('lock', 'moderation', []); |
super('lock', 'moderation', []); |
16 |
let channel: TextChannel = <TextChannel> msg.channel; |
let channel: TextChannel = <TextChannel> msg.channel; |
17 |
let role: Role = <Role> msg.guild!.roles.everyone; |
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) { |
if (options.isInteraction) { |
23 |
if (options.options.getChannel('channel')) { |
if (options.options.getChannel('channel')) { |
24 |
channel = await <TextChannel> options.options.getChannel('channel'); |
channel = await <TextChannel> options.options.getChannel('channel'); |
25 |
} |
} |
26 |
|
|
27 |
if (options.options.getChannel('role')) { |
if (options.options.getRole('role')) { |
28 |
role = await <Role> options.options.getRole('role'); |
role = await <Role> options.options.getRole('role'); |
29 |
} |
} |
30 |
} |
} |
71 |
} |
} |
72 |
|
|
73 |
try { |
try { |
74 |
let dbPerms; |
const result = await client.channelLock.lock(channel, msg.member!.user as User, { sendConfirmation: true }); |
75 |
|
|
76 |
let overWrites = await channel.permissionOverwrites.cache.get(role.id); |
let error = null; |
|
let allowperms = await overWrites?.allow?.has(Permissions.FLAGS.SEND_MESSAGES); |
|
|
let denyperms = await overWrites?.deny?.has(Permissions.FLAGS.SEND_MESSAGES); |
|
77 |
|
|
78 |
if (allowperms && !denyperms) { |
if (!result) { |
79 |
await (dbPerms = 'ALLOW'); |
error = 'This channel is already locked' + (role.id === msg.guild!.id ? '' : ' for the given role') + '.'; |
|
} |
|
|
else if (!allowperms && denyperms) { |
|
|
await (dbPerms = 'DENY'); |
|
|
} |
|
|
else if (!allowperms && !denyperms) { |
|
|
await (dbPerms = 'NULL'); |
|
80 |
} |
} |
81 |
|
|
82 |
|
if (error) { |
83 |
await client.db.get('INSERT INTO locks(channel_id, perms, date) VALUES(?, ?, ?)', [channel.id, dbPerms, new Date().toISOString()], async (err: any) => { |
await this.deferReply(msg, { |
84 |
if (err) |
content: error, |
85 |
console.log(err); |
}); |
86 |
|
|
87 |
try { |
return; |
88 |
await channel.permissionOverwrites.edit(role, { |
} |
|
SEND_MESSAGES: false, |
|
|
}); |
|
|
} |
|
|
catch (e) { |
|
|
console.log(e); |
|
|
} |
|
|
}) |
|
|
|
|
|
await channel.send({ |
|
|
embeds: [ |
|
|
new MessageEmbed() |
|
|
.setColor('#007bff') |
|
|
.setDescription(`:lock: This channel has been locked.`) |
|
|
] |
|
|
}); |
|
89 |
|
|
90 |
if (options.isInteraction) { |
if (options.isInteraction) { |
91 |
await msg.reply({ |
await this.deferReply(msg, { |
92 |
content: "Channel locked.", |
content: "Channel locked.", |
|
ephemeral: true |
|
93 |
}); |
}); |
94 |
} |
} |
95 |
else { |
else { |