Fix extra denied permissions on companion channels
This commit is contained in:
parent
c86abb04a0
commit
220b28d484
2 changed files with 17 additions and 1 deletions
|
@ -5,6 +5,7 @@ import { isDiscordAPIError, MINUTES } from "../../../utils";
|
||||||
import { LogsPlugin } from "../../Logs/LogsPlugin";
|
import { LogsPlugin } from "../../Logs/LogsPlugin";
|
||||||
import { CompanionChannelsPluginType, TCompanionChannelOpts } from "../types";
|
import { CompanionChannelsPluginType, TCompanionChannelOpts } from "../types";
|
||||||
import { getCompanionChannelOptsForVoiceChannelId } from "./getCompanionChannelOptsForVoiceChannelId";
|
import { getCompanionChannelOptsForVoiceChannelId } from "./getCompanionChannelOptsForVoiceChannelId";
|
||||||
|
import { filterObject } from "../../../utils/filterObject";
|
||||||
|
|
||||||
const ERROR_COOLDOWN_KEY = "errorCooldown";
|
const ERROR_COOLDOWN_KEY = "errorCooldown";
|
||||||
const ERROR_COOLDOWN = 5 * MINUTES;
|
const ERROR_COOLDOWN = 5 * MINUTES;
|
||||||
|
@ -63,7 +64,9 @@ export async function handleCompanionPermissions(
|
||||||
const channel = pluginData.guild.channels.cache.get(channelId as Snowflake);
|
const channel = pluginData.guild.channels.cache.get(channelId as Snowflake);
|
||||||
if (!channel || !(channel instanceof TextChannel)) continue;
|
if (!channel || !(channel instanceof TextChannel)) continue;
|
||||||
pluginData.state.serverLogs.ignoreLog(LogType.CHANNEL_UPDATE, channelId, 3 * 1000);
|
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`,
|
reason: `Companion Channel for ${voiceChannel!.id} | User Joined`,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
13
backend/src/utils/filterObject.ts
Normal file
13
backend/src/utils/filterObject.ts
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
/**
|
||||||
|
* Filter an object's properties based on its values and keys
|
||||||
|
* @return New object with filtered properties
|
||||||
|
*/
|
||||||
|
export function filterObject<T extends Record<string | number | symbol, unknown>>(
|
||||||
|
object: T,
|
||||||
|
filterFn: <K extends keyof T>(value: T[K], key: K) => boolean,
|
||||||
|
): Record<keyof T, T[keyof T]> {
|
||||||
|
return Object.fromEntries(Object.entries(object).filter(([key, value]) => filterFn(value as any, key))) as Record<
|
||||||
|
keyof T,
|
||||||
|
T[keyof T]
|
||||||
|
>;
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue