From e73a09918c2ef330c533bc15dd33a548c2326ba3 Mon Sep 17 00:00:00 2001 From: ayntee Date: Fri, 13 Nov 2020 18:04:07 +0400 Subject: [PATCH 1/2] New function isChannelSynced(channelID: string) --- src/handlers/channel.ts | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/handlers/channel.ts b/src/handlers/channel.ts index 23803aef4..b74965be7 100644 --- a/src/handlers/channel.ts +++ b/src/handlers/channel.ts @@ -421,3 +421,30 @@ export async function followChannel( return data.webhook_id; } + +/** + * Checks whether a channel is synchronized with its parent/category channel or not. + * @param channelID The ID of the channel to test for synchronization + * @return Returns `true` if the channel is synchronized, otherwise `false`. Returns `false` if the channel is not cached. + */ +export async function isChannelSynced(channelID: string) { + const channel = await cacheHandlers.get("channels", channelID); + if (!channel?.parentID) return false; + + const parentChannel = await cacheHandlers.get("channels", channel.parentID); + if (!parentChannel) return false; + + return channel.permission_overwrites?.every((overwrite) => { + const permission = parentChannel.permission_overwrites?.find((ow) => + ow.id === overwrite.id + ); + if (!permission) return false; + if ( + overwrite.allow !== permission.allow || overwrite.deny !== permission.deny + ) { + return false; + } + + return true; + }); +} From 49815b579dd45f70be49cce704056d206031f7d4 Mon Sep 17 00:00:00 2001 From: ayntee Date: Fri, 13 Nov 2020 18:09:27 +0400 Subject: [PATCH 2/2] Linted code --- src/handlers/guild.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/handlers/guild.ts b/src/handlers/guild.ts index a0865d759..47385b112 100644 --- a/src/handlers/guild.ts +++ b/src/handlers/guild.ts @@ -617,5 +617,8 @@ export function getUser(userID: string) { * So it does not cache the guild, you must do it manually. * */ export function getGuild(guildID: string, counts = true) { - return RequestManager.get(endpoints.GUILD(guildID), { with_counts: counts }) as Promise + return RequestManager.get( + endpoints.GUILD(guildID), + { with_counts: counts }, + ) as Promise; }