diff options
author | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2021-12-29 22:14:04 -0500 |
---|---|---|
committer | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2021-12-29 22:14:04 -0500 |
commit | f0a9f894575871d498447c5de2b5f0f826b117b7 (patch) | |
tree | e3dc03b24ef7197699bc74ad47ebcbdc9cb19c1b /src/lib/extensions/discord.js | |
parent | 1182f63498c856111762e2766d6cdddf063f2a97 (diff) | |
download | tanzanite-f0a9f894575871d498447c5de2b5f0f826b117b7.tar.gz tanzanite-f0a9f894575871d498447c5de2b5f0f826b117b7.tar.bz2 tanzanite-f0a9f894575871d498447c5de2b5f0f826b117b7.zip |
events
Diffstat (limited to 'src/lib/extensions/discord.js')
-rw-r--r-- | src/lib/extensions/discord.js/BushClientEvents.d.ts | 34 | ||||
-rw-r--r-- | src/lib/extensions/discord.js/BushGuild.ts | 68 |
2 files changed, 71 insertions, 31 deletions
diff --git a/src/lib/extensions/discord.js/BushClientEvents.d.ts b/src/lib/extensions/discord.js/BushClientEvents.d.ts index 10d70f9..b779991 100644 --- a/src/lib/extensions/discord.js/BushClientEvents.d.ts +++ b/src/lib/extensions/discord.js/BushClientEvents.d.ts @@ -6,6 +6,7 @@ import type { BushGuildBan, BushGuildEmoji, BushGuildMember, + BushGuildTextBasedChannel, BushMessage, BushMessageReaction, BushNewsChannel, @@ -171,6 +172,17 @@ export interface BushClientEvents extends AkairoClientEvents { dmSuccess?: boolean, evidence?: string ]; + bushBlock: [ + victim: BushGuildMember | BushUser, + moderator: BushUser, + guild: BushGuild, + reason: string | undefined, + caseID: string, + duration: number, + dmSuccess: boolean, + channel: BushGuildTextBasedChannel, + evidence?: string + ]; bushKick: [ victim: BushGuildMember, moderator: BushUser, @@ -224,6 +236,16 @@ export interface BushClientEvents extends AkairoClientEvents { dmSuccess: boolean, evidence?: string ]; + bushUnblock: [ + victim: BushGuildMember | BushUser, + moderator: BushUser, + guild: BushGuild, + reason: string | undefined, + caseID: string, + dmSuccess: boolean, + channel: BushGuildTextBasedChannel, + evidence?: string + ]; bushUnmute: [ victim: BushGuildMember, moderator: BushUser, @@ -263,6 +285,18 @@ export interface BushClientEvents extends AkairoClientEvents { currentXp: number, message: BushMessage & { guild: BushGuild } ]; + bushLockdown: [ + moderator: BushGuildMember, + reason?: string | undefined, + channel?: BushGuildTextBasedChannel, + all?: boolean + ]; + bushUnlockdown: [ + moderator: BushGuildMember, + reason?: string | undefined, + channel?: BushGuildTextBasedChannel, + all?: boolean + ]; } type Setting = 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<Snowflake, Error>(); - 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<LockdownResponse> => { + const errors = new Collection<Snowflake, Error>(); + 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; } } |