3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-07-07 11:07:19 +00:00

Timeouts: better validations (#438)

* better timeout validations

Signed-off-by: GitHub <noreply@github.com>

* almeida reviews

Signed-off-by: GitHub <noreply@github.com>

* better error handling

Signed-off-by: GitHub <noreply@github.com>

* add missing catch noops

Signed-off-by: GitHub <noreply@github.com>

---------

Signed-off-by: GitHub <noreply@github.com>
This commit is contained in:
Tiago R 2023-12-28 14:41:32 +00:00 committed by GitHub
parent 047ab872df
commit 8860d4fb22
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 49 additions and 9 deletions

View file

@ -13,6 +13,7 @@ import { TemplateSafeValueContainer, renderTemplate } from "../../../templateFor
import {
UserNotificationMethod,
UserNotificationResult,
noop,
notifyUser,
resolveMember,
resolveUser,
@ -108,7 +109,7 @@ export async function muteUser(
if (zepRoles.size === 0 || !zepRoles.some((zepRole) => zepRole.position > actualMuteRole.position)) {
lock.unlock();
logs.logBotAlert({
body: `Cannot mute users, specified mute role is above Zeppelin in the role hierarchy`,
body: `Cannot mute user, specified mute role is above Zeppelin in the role hierarchy`,
});
throw new RecoverablePluginError(ERRORS.MUTE_ROLE_ABOVE_ZEP, pluginData.guild);
}
@ -117,7 +118,24 @@ export async function muteUser(
pluginData.getPlugin(RoleManagerPlugin).addPriorityRole(member.id, muteRole!);
}
} else {
await member.disableCommunicationUntil(timeoutUntil);
if (!member.manageable) {
lock.unlock();
logs.logBotAlert({
body: `Cannot mute user, specified user is above Zeppelin in the role hierarchy`,
});
throw new RecoverablePluginError(ERRORS.USER_ABOVE_ZEP, pluginData.guild);
}
if (!member.moderatable) {
// redundant safety, since canActOn already checks this
lock.unlock();
logs.logBotAlert({
body: `Cannot mute user, specified user is not moderatable`,
});
throw new RecoverablePluginError(ERRORS.USER_NOT_MODERATABLE, pluginData.guild);
}
await member.disableCommunicationUntil(timeoutUntil).catch(noop);
}
// If enabled, move the user to the mute voice channel (e.g. afk - just to apply the voice perms from the mute role)