7 |
|
|
8 |
export async function unlockAll(client: DiscordClient, role: Role, msg: Message | CommandInteraction, options: CommandOptions | InteractionOptions, channels: Collection <string, TextChannel>, force: boolean) { |
export async function unlockAll(client: DiscordClient, role: Role, msg: Message | CommandInteraction, options: CommandOptions | InteractionOptions, channels: Collection <string, TextChannel>, force: boolean) { |
9 |
if (role) { |
if (role) { |
|
const gen = await msg.guild!.roles.fetch(client.config.props[msg.guild!.id].gen_role); |
|
|
|
|
10 |
channels.forEach(async channel => { |
channels.forEach(async channel => { |
11 |
try { |
try { |
|
await channel.send({ |
|
|
embeds: [ |
|
|
new MessageEmbed() |
|
|
.setDescription(':closed_lock_with_key: This channel has been unlocked.') |
|
|
] |
|
|
}); |
|
|
|
|
12 |
client.db.get('SELECT * FROM locks WHERE channel_id = ?', [channel.id], async (err: any, data: any) => { |
client.db.get('SELECT * FROM locks WHERE channel_id = ?', [channel.id], async (err: any, data: any) => { |
13 |
if (data || force) { |
if (data || force) { |
14 |
let perm1; |
await channel.send({ |
15 |
|
embeds: [ |
16 |
|
new MessageEmbed() |
17 |
|
.setDescription(':closed_lock_with_key: This channel has been unlocked.') |
18 |
|
] |
19 |
|
}); |
20 |
|
|
21 |
let perm; |
let perm; |
22 |
const data1 = data?.perms?.split(','); |
const data1 = data?.perms; |
23 |
|
|
24 |
if (data1) { |
if (data1) { |
25 |
if (data1[0] === 'DENY') { |
if (data1 === 'DENY') { |
26 |
await (perm = false); |
await (perm = false); |
27 |
} |
} |
28 |
else if (data1[0] === 'NULL') { |
else if (data1 === 'NULL') { |
29 |
await (perm = null); |
await (perm = null); |
30 |
} |
} |
31 |
else if (data1[0] === 'ALLOW') { |
else if (data1 === 'ALLOW') { |
32 |
await (perm = true); |
await (perm = true); |
33 |
} |
} |
|
|
|
|
if (data1[1] === 'DENY') { |
|
|
await (perm1 = false); |
|
|
} |
|
|
else if (data1[1] === 'NULL') { |
|
|
await (perm1 = null); |
|
|
} |
|
|
else if (data1[1] === 'ALLOW') { |
|
|
await (perm1 = true); |
|
|
} |
|
34 |
} |
} |
35 |
|
|
36 |
if (force) { |
if (force) { |
|
await (perm1 = true); |
|
37 |
await (perm = true); |
await (perm = true); |
38 |
} |
} |
39 |
|
|
44 |
SEND_MESSAGES: perm, |
SEND_MESSAGES: perm, |
45 |
}); |
}); |
46 |
|
|
|
await channel.permissionOverwrites.edit(gen!, { |
|
|
SEND_MESSAGES: perm1, |
|
|
}); |
|
47 |
} |
} |
48 |
catch (e) { |
catch (e) { |
49 |
console.log(e); |
console.log(e); |
50 |
} |
} |
51 |
|
|
52 |
await console.log(perm, perm1); |
await console.log(perm); |
53 |
|
|
54 |
if (data) { |
if (data) { |
55 |
await client.db.get('DELETE FROM locks WHERE id = ?', [data?.id], async (err: any) => {}); |
await client.db.get('DELETE FROM locks WHERE id = ?', [data?.id], async (err: any) => {}); |
72 |
} |
} |
73 |
|
|
74 |
async run(client: DiscordClient, msg: Message | CommandInteraction, options: CommandOptions | InteractionOptions) { |
async run(client: DiscordClient, msg: Message | CommandInteraction, options: CommandOptions | InteractionOptions) { |
75 |
|
if (!options.isInteraction && typeof options.args[0] === 'undefined') { |
76 |
|
await msg.reply({ |
77 |
|
embeds: [ |
78 |
|
new MessageEmbed() |
79 |
|
.setColor('#f14a60') |
80 |
|
.setDescription(`This command requires at least one argument.`) |
81 |
|
] |
82 |
|
}); |
83 |
|
|
84 |
|
return; |
85 |
|
} |
86 |
|
|
87 |
const raid = options.isInteraction ? options.options.getBoolean('raid') === true : (options.options.indexOf('--raid') !== -1); |
const raid = options.isInteraction ? options.options.getBoolean('raid') === true : (options.options.indexOf('--raid') !== -1); |
88 |
|
|
89 |
let role: Role = <Role> msg.guild!.roles.everyone; |
let role: Role = <Role> msg.guild!.roles.everyone; |
90 |
|
let unlockall: string[] = []; |
91 |
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); |
92 |
|
|
93 |
if (options.isInteraction) { |
if (options.isInteraction) { |
97 |
} |
} |
98 |
else { |
else { |
99 |
if ((msg as Message).mentions.roles.first()) { |
if ((msg as Message).mentions.roles.first()) { |
100 |
role = await <Role> (msg as Message).mentions.roles.first(); |
role = await <Role> (msg as Message).mentions.roles.first(); |
101 |
} |
} |
102 |
else if (options.normalArgs[0] && options.normalArgs[0] !== 'everyone') { |
else if (options.options.includes('-r') && options.normalArgs[options.options.indexOf('-r') + 1]) { |
103 |
role = <Role> await (msg as Message).guild?.roles.fetch(options.normalArgs[0]); |
role = <Role> await (msg as Message).guild?.roles.fetch(options.normalArgs[options.options.indexOf('-r') + 1]); |
104 |
} |
} |
105 |
|
|
106 |
if (!role) { |
if (!role) { |
107 |
await msg.reply({ |
await msg.reply({ |
115 |
|
|
116 |
return; |
return; |
117 |
} |
} |
118 |
|
|
119 |
|
for (const a of options.args) { |
120 |
|
if (/^\d+$/g.test(a)) { |
121 |
|
unlockall.push(a); |
122 |
|
} |
123 |
|
} |
124 |
} |
} |
125 |
|
|
126 |
const channels: Collection <string, GuildBasedChannel> = await msg.guild!.channels.cache.filter(c => ( |
let channels = raid ? await msg.guild!.channels.cache.filter(c => ( |
|
(!raid && (client.config.props[msg.guild!.id].lockall.indexOf(c.id) !== -1 || client.config.props[msg.guild!.id].lockall.indexOf(c.parent?.id) !== -1)) || |
|
127 |
(raid && ( |
(raid && ( |
128 |
(client.config.props[msg.guild!.id].raid.exclude && (client.config.props[msg.guild!.id].raid.channels.indexOf(c.id) === -1 && client.config.props[msg.guild!.id].raid.channels.indexOf(c.parent?.id) === -1)) || |
(client.config.props[msg.guild!.id].raid.exclude && (client.config.props[msg.guild!.id].raid.channels.indexOf(c.id) === -1 && client.config.props[msg.guild!.id].raid.channels.indexOf(c.parent?.id) === -1)) || |
129 |
(!client.config.props[msg.guild!.id].raid.exclude && (client.config.props[msg.guild!.id].raid.channels.indexOf(c.id) !== -1 || client.config.props[msg.guild!.id].raid.channels.indexOf(c.parent?.id) !== -1)) |
(!client.config.props[msg.guild!.id].raid.exclude && (client.config.props[msg.guild!.id].raid.channels.indexOf(c.id) !== -1 || client.config.props[msg.guild!.id].raid.channels.indexOf(c.parent?.id) !== -1)) |
130 |
))) && c.type === 'GUILD_TEXT' |
))) && c.type === 'GUILD_TEXT' |
131 |
); |
) : null; |
132 |
|
|
133 |
|
if (channels === null && !raid) { |
134 |
|
channels = msg.guild!.channels.cache.filter(c2 => (unlockall.includes(c2.id) || unlockall.includes(c2.parent?.id!)) && c2.type === 'GUILD_TEXT')!; |
135 |
|
} |
136 |
|
|
137 |
await unlockAll(client, role, msg, options, channels as Collection <string, TextChannel>, force); |
await unlockAll(client, role, msg, options, channels as Collection <string, TextChannel>, force); |
138 |
|
|