diff --git a/backend/src/plugins/CompanionChannels/functions/handleCompanionPermissions.ts b/backend/src/plugins/CompanionChannels/functions/handleCompanionPermissions.ts index d6e3e764..c4e66f49 100644 --- a/backend/src/plugins/CompanionChannels/functions/handleCompanionPermissions.ts +++ b/backend/src/plugins/CompanionChannels/functions/handleCompanionPermissions.ts @@ -5,6 +5,7 @@ import { isDiscordAPIError, MINUTES } from "../../../utils"; import { LogsPlugin } from "../../Logs/LogsPlugin"; import { CompanionChannelsPluginType, TCompanionChannelOpts } from "../types"; import { getCompanionChannelOptsForVoiceChannelId } from "./getCompanionChannelOptsForVoiceChannelId"; +import { filterObject } from "../../../utils/filterObject"; const ERROR_COOLDOWN_KEY = "errorCooldown"; const ERROR_COOLDOWN = 5 * MINUTES; @@ -63,7 +64,9 @@ export async function handleCompanionPermissions( const channel = pluginData.guild.channels.cache.get(channelId as Snowflake); if (!channel || !(channel instanceof TextChannel)) continue; pluginData.state.serverLogs.ignoreLog(LogType.CHANNEL_UPDATE, channelId, 3 * 1000); - await channel.permissionOverwrites.create(userId as Snowflake, new Permissions(BigInt(permissions)).serialize(), { + const fullSerialized = new Permissions(BigInt(permissions)).serialize(); + const onlyAllowed = filterObject(fullSerialized, v => v === true); + await channel.permissionOverwrites.create(userId, onlyAllowed, { reason: `Companion Channel for ${voiceChannel!.id} | User Joined`, }); } diff --git a/backend/src/utils/filterObject.ts b/backend/src/utils/filterObject.ts new file mode 100644 index 00000000..f5fd6de0 --- /dev/null +++ b/backend/src/utils/filterObject.ts @@ -0,0 +1,13 @@ +/** + * Filter an object's properties based on its values and keys + * @return New object with filtered properties + */ +export function filterObject>( + object: T, + filterFn: (value: T[K], key: K) => boolean, +): Record { + return Object.fromEntries(Object.entries(object).filter(([key, value]) => filterFn(value as any, key))) as Record< + keyof T, + T[keyof T] + >; +}