From f0a9f894575871d498447c5de2b5f0f826b117b7 Mon Sep 17 00:00:00 2001 From: IRONM00N <64110067+IRONM00N@users.noreply.github.com> Date: Wed, 29 Dec 2021 22:14:04 -0500 Subject: events --- src/lib/extensions/discord.js/BushGuild.ts | 68 ++++++++++++++++-------------- 1 file changed, 37 insertions(+), 31 deletions(-) (limited to 'src/lib/extensions/discord.js/BushGuild.ts') diff --git a/src/lib/extensions/discord.js/BushGuild.ts b/src/lib/extensions/discord.js/BushGuild.ts index 299fdbc..b67c71b 100644 --- a/src/lib/extensions/discord.js/BushGuild.ts +++ b/src/lib/extensions/discord.js/BushGuild.ts @@ -290,40 +290,46 @@ export class BushGuild extends Guild { const moderator = this.members.resolve(options.moderator); if (!moderator) return 'moderator not found'; - const errors = new Collection(); - let successCount = 0; - - for (const _channel of mappedChannels) { - const channel = _channel!; - if (!channel.permissionsFor(this.me!.id)?.has(['MANAGE_CHANNELS'])) { - errors.set(channel.id, new Error('client no permission')); - continue; - } else if (!channel.permissionsFor(options.moderator)?.has(['MANAGE_CHANNELS'])) { - errors.set(channel.id, new Error('moderator no permission')); - continue; - } - const reason = `${options.unlock ? 'Unlocking' : 'Locking Down'} Channel | ${moderator.user.tag} | ${ - options.reason ?? 'No reason provided' - }`; - - if (channel.isThread()) { - const lockdownSuccess = await channel.parent?.permissionOverwrites - .edit(this.id, { SEND_MESSAGES_IN_THREADS: options.unlock ? null : false }, { reason }) - .catch((e) => e); - if (lockdownSuccess instanceof Error) errors.set(channel.id, lockdownSuccess); - else successCount++; - } else { - const lockdownSuccess = await channel.permissionOverwrites - .edit(this.id, { SEND_MESSAGES: options.unlock ? null : false }, { reason }) - .catch((e) => e); - if (lockdownSuccess instanceof Error) errors.set(channel.id, lockdownSuccess); - else successCount++; + const ret = await (async (): Promise => { + const errors = new Collection(); + let successCount = 0; + + for (const _channel of mappedChannels) { + const channel = _channel!; + if (!channel.permissionsFor(this.me!.id)?.has(['MANAGE_CHANNELS'])) { + errors.set(channel.id, new Error('client no permission')); + continue; + } else if (!channel.permissionsFor(options.moderator)?.has(['MANAGE_CHANNELS'])) { + errors.set(channel.id, new Error('moderator no permission')); + continue; + } + + const reason = `[${options.unlock ? 'Unlockdown' : 'Lockdown'}] ${moderator.user.tag} | ${ + options.reason ?? 'No reason provided' + }`; + + if (channel.isThread()) { + const lockdownSuccess = await channel.parent?.permissionOverwrites + .edit(this.id, { SEND_MESSAGES_IN_THREADS: options.unlock ? null : false }, { reason }) + .catch((e) => e); + if (lockdownSuccess instanceof Error) errors.set(channel.id, lockdownSuccess); + else successCount++; + } else { + const lockdownSuccess = await channel.permissionOverwrites + .edit(this.id, { SEND_MESSAGES: options.unlock ? null : false }, { reason }) + .catch((e) => e); + if (lockdownSuccess instanceof Error) errors.set(channel.id, lockdownSuccess); + else successCount++; + } } - } - if (errors.size) return errors; - else return `success: ${successCount}`; + if (errors.size) return errors; + else return `success: ${successCount}`; + })(); + + client.emit(options.unlock ? 'bushUnlockdown' : 'bushLockdown', moderator, options.reason, options.channel); + return ret; } } -- cgit