mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-05-21 00:35:02 +00:00
Allow automod to distinguish between automatic and manual mutes
This commit is contained in:
parent
fdaf386193
commit
254457997d
7 changed files with 32 additions and 8 deletions
|
@ -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),
|
||||||
);
|
);
|
||||||
|
|
|
@ -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, {
|
||||||
|
|
|
@ -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,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -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: {},
|
||||||
|
|
|
@ -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;
|
||||||
|
|
|
@ -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,
|
||||||
|
|
|
@ -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>();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue