mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-03-15 05:41:51 +00:00
fix: check for too many permission overwrites in companion channels
This commit is contained in:
parent
dd1afc4dab
commit
c1a91d4dec
1 changed files with 12 additions and 2 deletions
|
@ -10,6 +10,10 @@ import { getCompanionChannelOptsForVoiceChannelId } from "./getCompanionChannelO
|
||||||
const ERROR_COOLDOWN_KEY = "errorCooldown";
|
const ERROR_COOLDOWN_KEY = "errorCooldown";
|
||||||
const ERROR_COOLDOWN = 5 * MINUTES;
|
const ERROR_COOLDOWN = 5 * MINUTES;
|
||||||
|
|
||||||
|
// The real limit is 500, but to be on the safer side, this is lower
|
||||||
|
// Temporary fix until we move to role-based companion channels
|
||||||
|
const MAX_OVERWRITES = 450;
|
||||||
|
|
||||||
export async function handleCompanionPermissions(
|
export async function handleCompanionPermissions(
|
||||||
pluginData: GuildPluginData<CompanionChannelsPluginType>,
|
pluginData: GuildPluginData<CompanionChannelsPluginType>,
|
||||||
userId: string,
|
userId: string,
|
||||||
|
@ -50,6 +54,8 @@ export async function handleCompanionPermissions(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const logs = pluginData.getPlugin(LogsPlugin);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
for (const channelId of permsToDelete) {
|
for (const channelId of permsToDelete) {
|
||||||
const channel = pluginData.guild.channels.cache.get(channelId as Snowflake);
|
const channel = pluginData.guild.channels.cache.get(channelId as Snowflake);
|
||||||
|
@ -63,6 +69,12 @@ export async function handleCompanionPermissions(
|
||||||
for (const [channelId, permissions] of permsToSet) {
|
for (const [channelId, permissions] of permsToSet) {
|
||||||
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;
|
||||||
|
if (channel.permissionOverwrites.cache.size >= MAX_OVERWRITES) {
|
||||||
|
logs.logBotAlert({
|
||||||
|
body: `Could not apply companion channel permissions for <#${channel.id}>: too many permissions`,
|
||||||
|
});
|
||||||
|
continue;
|
||||||
|
}
|
||||||
pluginData.state.serverLogs.ignoreLog(LogType.CHANNEL_UPDATE, channelId, 3 * 1000);
|
pluginData.state.serverLogs.ignoreLog(LogType.CHANNEL_UPDATE, channelId, 3 * 1000);
|
||||||
const fullSerialized = new PermissionsBitField(BigInt(permissions)).serialize();
|
const fullSerialized = new PermissionsBitField(BigInt(permissions)).serialize();
|
||||||
const onlyAllowed = filterObject(fullSerialized, (v) => v === true);
|
const onlyAllowed = filterObject(fullSerialized, (v) => v === true);
|
||||||
|
@ -72,8 +84,6 @@ export async function handleCompanionPermissions(
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (isDiscordAPIError(e)) {
|
if (isDiscordAPIError(e)) {
|
||||||
const logs = pluginData.getPlugin(LogsPlugin);
|
|
||||||
|
|
||||||
if (e.code === 50001) {
|
if (e.code === 50001) {
|
||||||
logs.logBotAlert({
|
logs.logBotAlert({
|
||||||
body: `One of the companion channels can't be accessed. Pausing companion channels for 5 minutes or until the bot is reloaded on this server.`,
|
body: `One of the companion channels can't be accessed. Pausing companion channels for 5 minutes or until the bot is reloaded on this server.`,
|
||||||
|
|
Loading…
Add table
Reference in a new issue