3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-05-11 04:45:02 +00:00

Improve error handling with mutes

This commit is contained in:
Dragory 2020-09-13 22:45:02 +03:00
parent 599c365640
commit 61804d9e64
No known key found for this signature in database
GPG key ID: 5F387BA66DF8AAC1
4 changed files with 61 additions and 18 deletions

View file

@ -5,6 +5,8 @@ import { asyncMap, convertDelayStringToMS, resolveMember, tDelayString, tNullabl
import { resolveActionContactMethods } from "../functions/resolveActionContactMethods";
import { ModActionsPlugin } from "../../ModActions/ModActionsPlugin";
import { MutesPlugin } from "../../Mutes/MutesPlugin";
import { ERRORS, RecoverablePluginError } from "../../../RecoverablePluginError";
import { LogsPlugin } from "../../Logs/LogsPlugin";
export const MuteAction = automodAction({
configType: t.type({
@ -18,7 +20,7 @@ export const MuteAction = automodAction({
notify: null, // Use defaults from ModActions
},
async apply({ pluginData, contexts, actionConfig, matchResult }) {
async apply({ pluginData, contexts, actionConfig, ruleName, matchResult }) {
const duration = actionConfig.duration ? convertDelayStringToMS(actionConfig.duration) : null;
const reason = actionConfig.reason || "Muted automatically";
const contactMethods = resolveActionContactMethods(pluginData, actionConfig);
@ -32,7 +34,17 @@ export const MuteAction = automodAction({
const mutes = pluginData.getPlugin(MutesPlugin);
for (const userId of userIdsToMute) {
await mutes.muteUser(userId, duration, reason, { contactMethods, caseArgs });
try {
await mutes.muteUser(userId, duration, reason, { contactMethods, caseArgs });
} catch (e) {
if (e instanceof RecoverablePluginError && e.code === ERRORS.NO_MUTE_ROLE_IN_CONFIG) {
pluginData.getPlugin(LogsPlugin).log(LogType.BOT_ALERT, {
body: `Failed to mute <@!${userId}> in Automod rule \`${ruleName}\` because a mute role has not been specified in server config`,
});
} else {
throw e;
}
}
}
},
});