20 |
let channel: TextChannel = <TextChannel> msg.channel; |
let channel: TextChannel = <TextChannel> msg.channel; |
21 |
let role: Role = <Role> msg.guild!.roles.everyone; |
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) { |
if (options.isInteraction) { |
27 |
if (options.options.getChannel('channel')) { |
if (options.options.getChannel('channel')) { |
28 |
channel = await <TextChannel> options.options.getChannel('channel'); |
channel = await <TextChannel> options.options.getChannel('channel'); |
75 |
} |
} |
76 |
|
|
77 |
try { |
try { |
78 |
let dbPerms; |
const result = await client.channelLock.lock(channel, msg.member!.user as User, { sendConfirmation: true }); |
79 |
|
|
80 |
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); |
|
81 |
|
|
82 |
if (allowperms && !denyperms) { |
if (!result) { |
83 |
await (dbPerms = 'ALLOW'); |
error = 'This channel is already locked.'; // If you want to force unlock, run this command with `--force` option or select `True` if using slash commands.'; |
|
} |
|
|
else if (!allowperms && denyperms) { |
|
|
await (dbPerms = 'DENY'); |
|
|
} |
|
|
else if (!allowperms && !denyperms) { |
|
|
await (dbPerms = 'NULL'); |
|
84 |
} |
} |
85 |
|
|
86 |
|
if (error) { |
87 |
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, { |
88 |
if (err) |
content: error, |
89 |
console.log(err); |
}); |
90 |
|
|
91 |
try { |
return; |
92 |
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.`) |
|
|
] |
|
|
}); |
|
93 |
|
|
94 |
if (options.isInteraction) { |
if (options.isInteraction) { |
95 |
await msg.reply({ |
await this.deferReply(msg, { |
96 |
content: "Channel locked.", |
content: "Channel locked.", |
|
ephemeral: true |
|
97 |
}); |
}); |
98 |
} |
} |
99 |
else { |
else { |