3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-05-21 08:45:03 +00:00

Allow automod to distinguish between automatic and manual mutes

This commit is contained in:
Dark 2021-04-03 18:52:07 +02:00
parent fdaf386193
commit 254457997d
No known key found for this signature in database
GPG key ID: 384C4B4F5B1E25A8
7 changed files with 32 additions and 8 deletions

View file

@ -251,7 +251,9 @@ export const AutomodPlugin = zeppelinGuildPlugin<AutomodPluginType>()("automod",
const mutesEvents = pluginData.getPlugin(MutesPlugin).getEventEmitter(); const mutesEvents = pluginData.getPlugin(MutesPlugin).getEventEmitter();
pluginData.state.mutesListeners = new Map(); pluginData.state.mutesListeners = new Map();
pluginData.state.mutesListeners.set("mute", (userId: string) => runAutomodOnModAction(pluginData, "mute", userId)); pluginData.state.mutesListeners.set("mute", (userId: string, reason: string, isAutomodAction: boolean) =>
runAutomodOnModAction(pluginData, "mute", userId, reason, isAutomodAction),
);
pluginData.state.mutesListeners.set("unmute", (userId: string) => pluginData.state.mutesListeners.set("unmute", (userId: string) =>
runAutomodOnModAction(pluginData, "unmute", userId), runAutomodOnModAction(pluginData, "unmute", userId),
); );

View file

@ -49,7 +49,14 @@ export const MuteAction = automodAction({
const mutes = pluginData.getPlugin(MutesPlugin); const mutes = pluginData.getPlugin(MutesPlugin);
for (const userId of userIdsToMute) { for (const userId of userIdsToMute) {
try { try {
await mutes.muteUser(userId, duration, reason, { contactMethods, caseArgs }, rolesToRemove, rolesToRestore); await mutes.muteUser(
userId,
duration,
reason,
{ contactMethods, caseArgs, isAutomodAction: true },
rolesToRemove,
rolesToRestore,
);
} catch (e) { } catch (e) {
if (e instanceof RecoverablePluginError && e.code === ERRORS.NO_MUTE_ROLE_IN_CONFIG) { if (e instanceof RecoverablePluginError && e.code === ERRORS.NO_MUTE_ROLE_IN_CONFIG) {
pluginData.getPlugin(LogsPlugin).log(LogType.BOT_ALERT, { pluginData.getPlugin(LogsPlugin).log(LogType.BOT_ALERT, {

View file

@ -9,6 +9,7 @@ export async function runAutomodOnModAction(
modAction: ModActionType, modAction: ModActionType,
userId: string, userId: string,
reason?: string, reason?: string,
isAutomodAction: boolean = false,
) { ) {
const user = await resolveUser(pluginData.client, userId); const user = await resolveUser(pluginData.client, userId);
@ -18,6 +19,7 @@ export async function runAutomodOnModAction(
modAction: { modAction: {
type: modAction, type: modAction,
reason, reason,
isAutomodAction,
}, },
}; };

View file

@ -5,13 +5,24 @@ import { automodTrigger } from "../helpers";
interface MuteTriggerResultType {} interface MuteTriggerResultType {}
export const MuteTrigger = automodTrigger<MuteTriggerResultType>()({ export const MuteTrigger = automodTrigger<MuteTriggerResultType>()({
configType: t.type({}), configType: t.type({
defaultConfig: {}, manual: t.boolean,
automatic: t.boolean,
}),
async match({ context }) { defaultConfig: {
manual: true,
automatic: true,
},
async match({ context, triggerConfig }) {
if (context.modAction?.type !== "mute") { if (context.modAction?.type !== "mute") {
return; return;
} }
// If automatic && automatic turned off -> return
if (context.modAction.isAutomodAction && !triggerConfig.automatic) return;
// If manual && manual turned off -> return
if (!context.modAction.isAutomodAction && !triggerConfig.manual) return;
return { return {
extra: {}, extra: {},

View file

@ -122,6 +122,7 @@ export interface AutomodContext {
modAction?: { modAction?: {
type: ModActionType; type: ModActionType;
reason?: string; reason?: string;
isAutomodAction: boolean;
}; };
antiraid?: { antiraid?: {
level: string | null; level: string | null;

View file

@ -247,7 +247,7 @@ export async function muteUser(
lock.unlock(); lock.unlock();
pluginData.state.events.emit("mute", user.id, reason); pluginData.state.events.emit("mute", user.id, reason, muteOptions.isAutomodAction);
return { return {
case: theCase, case: theCase,

View file

@ -34,8 +34,8 @@ export const ConfigSchema = t.type({
export type TConfigSchema = t.TypeOf<typeof ConfigSchema>; export type TConfigSchema = t.TypeOf<typeof ConfigSchema>;
export interface MutesEvents { export interface MutesEvents {
mute: (userId: string, reason?: string) => void; mute: (userId: string, reason?: string, manual?: boolean) => void;
unmute: (userId: string, reason?: string) => void; unmute: (userId: string, reason?: string, manual?: boolean) => void;
} }
export interface MutesEventEmitter extends EventEmitter { export interface MutesEventEmitter extends EventEmitter {
@ -75,6 +75,7 @@ export type UnmuteResult = {
export interface MuteOptions { export interface MuteOptions {
caseArgs?: Partial<CaseArgs>; caseArgs?: Partial<CaseArgs>;
contactMethods?: UserNotificationMethod[]; contactMethods?: UserNotificationMethod[];
isAutomodAction?: boolean;
} }
export const mutesCmd = guildCommand<MutesPluginType>(); export const mutesCmd = guildCommand<MutesPluginType>();