19 |
async run(client: DiscordClient, msg: Message | CommandInteraction, options: CommandOptions | InteractionOptions) { |
async run(client: DiscordClient, msg: Message | CommandInteraction, options: CommandOptions | InteractionOptions) { |
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 |
const force = options.isInteraction ? options.options.getBoolean('force') === true : (options.options.indexOf('--force') !== -1); |
const force = options.isInteraction ? options.options.getBoolean('force') === true : (options.options.indexOf('--force') !== -1); |
27 |
|
|
28 |
if (options.isInteraction) { |
if (options.isInteraction) { |
77 |
} |
} |
78 |
|
|
79 |
try { |
try { |
80 |
client.db.get('SELECT * FROM locks WHERE channel_id = ?', [channel.id], async (err: any, data: any) => { |
const result = await client.channelLock.unlock(channel, { sendConfirmation: true, force }); |
81 |
if (data || force) { |
let error = null; |
82 |
let perm1; |
|
83 |
let perm; |
if (!result) { |
84 |
const data1 = data?.perms?.split(','); |
error = 'This channel wasn\'t locked. If you want to force unlock, run this command with `--force` option or select `True` if using slash commands.'; |
85 |
|
} |
86 |
if (data1) { |
|
87 |
if (data1[0] === 'DENY') { |
if (error) { |
88 |
await (perm = false); |
await this.deferReply(msg, { |
89 |
} |
content: error, |
90 |
else if (data1[0] === 'NULL') { |
}); |
91 |
await (perm = null); |
|
92 |
} |
return; |
93 |
else if (data1[0] === 'ALLOW') { |
} |
|
await (perm = true); |
|
|
} |
|
|
|
|
|
if (data1[1] === 'DENY') { |
|
|
await (perm1 = false); |
|
|
} |
|
|
else if (data1[1] === 'NULL') { |
|
|
await (perm1 = null); |
|
|
} |
|
|
else if (data1[1] === 'ALLOW') { |
|
|
await (perm1 = true); |
|
|
} |
|
|
} |
|
|
|
|
|
if (force) { |
|
|
await (perm1 = true); |
|
|
await (perm = true); |
|
|
} |
|
|
|
|
|
await console.log(channel.name); |
|
|
|
|
|
try { |
|
|
await channel.permissionOverwrites.edit(role, { |
|
|
SEND_MESSAGES: perm, |
|
|
}); |
|
|
|
|
|
const gen = await msg.guild!.roles.fetch(client.config.props[msg.guild!.id].gen_role); |
|
|
|
|
|
await channel.permissionOverwrites.edit(gen!, { |
|
|
SEND_MESSAGES: perm1, |
|
|
}); |
|
|
} |
|
|
catch (e) { |
|
|
console.log(e); |
|
|
} |
|
|
|
|
|
await console.log(perm, perm1); |
|
|
|
|
|
if (data) { |
|
|
await client.db.get('DELETE FROM locks WHERE id = ?', [data?.id], async (err: any) => {}); |
|
|
} |
|
|
} |
|
|
}); |
|
94 |
|
|
95 |
if (options.isInteraction) { |
if (options.isInteraction) { |
96 |
await msg.reply({ |
await this.deferReply(msg, { |
97 |
content: "Channel unlocked.", |
content: "Channel unlocked.", |
|
ephemeral: true |
|
98 |
}); |
}); |
99 |
} |
} |
100 |
else { |
else { |
101 |
await (msg as Message).react('🔓'); |
await (msg as Message).react('🔓'); |
102 |
} |
} |
|
|
|
|
await channel.send({ |
|
|
embeds: [ |
|
|
new MessageEmbed() |
|
|
.setColor('#007bff') |
|
|
.setDescription(`:closed_lock_with_key: This channel has been unlocked.`) |
|
|
] |
|
|
}); |
|
103 |
} |
} |
104 |
catch (e) { |
catch (e) { |
105 |
console.log(e); |
console.log(e); |