mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-03-16 22:21:51 +00:00
Allow Automod to distinguish whether mod actions are manual or automatic (#179)
This commit is contained in:
parent
90b6f4bc86
commit
51db942d97
18 changed files with 106 additions and 32 deletions
|
@ -235,14 +235,20 @@ export const AutomodPlugin = zeppelinGuildPlugin<AutomodPluginType>()("automod",
|
||||||
pluginData.state.modActionsListeners.set("note", (userId: string) =>
|
pluginData.state.modActionsListeners.set("note", (userId: string) =>
|
||||||
runAutomodOnModAction(pluginData, "note", userId),
|
runAutomodOnModAction(pluginData, "note", userId),
|
||||||
);
|
);
|
||||||
pluginData.state.modActionsListeners.set("warn", (userId: string) =>
|
pluginData.state.modActionsListeners.set(
|
||||||
runAutomodOnModAction(pluginData, "warn", userId),
|
"warn",
|
||||||
|
(userId: string, reason: string | undefined, isAutomodAction: boolean) =>
|
||||||
|
runAutomodOnModAction(pluginData, "warn", userId, reason, isAutomodAction),
|
||||||
);
|
);
|
||||||
pluginData.state.modActionsListeners.set("kick", (userId: string) =>
|
pluginData.state.modActionsListeners.set(
|
||||||
runAutomodOnModAction(pluginData, "kick", userId),
|
"kick",
|
||||||
|
(userId: string, reason: string | undefined, isAutomodAction: boolean) =>
|
||||||
|
runAutomodOnModAction(pluginData, "kick", userId, reason, isAutomodAction),
|
||||||
);
|
);
|
||||||
pluginData.state.modActionsListeners.set("ban", (userId: string) =>
|
pluginData.state.modActionsListeners.set(
|
||||||
runAutomodOnModAction(pluginData, "ban", userId),
|
"ban",
|
||||||
|
(userId: string, reason: string | undefined, isAutomodAction: boolean) =>
|
||||||
|
runAutomodOnModAction(pluginData, "ban", userId, reason, isAutomodAction),
|
||||||
);
|
);
|
||||||
pluginData.state.modActionsListeners.set("unban", (userId: string) =>
|
pluginData.state.modActionsListeners.set("unban", (userId: string) =>
|
||||||
runAutomodOnModAction(pluginData, "unban", userId),
|
runAutomodOnModAction(pluginData, "unban", userId),
|
||||||
|
@ -251,7 +257,11 @@ 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 | undefined, 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),
|
||||||
);
|
);
|
||||||
|
|
|
@ -33,7 +33,12 @@ export const BanAction = automodAction({
|
||||||
|
|
||||||
const modActions = pluginData.getPlugin(ModActionsPlugin);
|
const modActions = pluginData.getPlugin(ModActionsPlugin);
|
||||||
for (const userId of userIdsToBan) {
|
for (const userId of userIdsToBan) {
|
||||||
await modActions.banUserId(userId, reason, { contactMethods, caseArgs, deleteMessageDays });
|
await modActions.banUserId(userId, reason, {
|
||||||
|
contactMethods,
|
||||||
|
caseArgs,
|
||||||
|
deleteMessageDays,
|
||||||
|
isAutomodAction: true,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
|
@ -33,7 +33,7 @@ export const KickAction = automodAction({
|
||||||
const modActions = pluginData.getPlugin(ModActionsPlugin);
|
const modActions = pluginData.getPlugin(ModActionsPlugin);
|
||||||
for (const member of membersToKick) {
|
for (const member of membersToKick) {
|
||||||
if (!member) continue;
|
if (!member) continue;
|
||||||
await modActions.kickMember(member, reason, { contactMethods, caseArgs });
|
await modActions.kickMember(member, reason, { contactMethods, caseArgs, isAutomodAction: true });
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
|
@ -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, {
|
||||||
|
|
|
@ -33,7 +33,7 @@ export const WarnAction = automodAction({
|
||||||
const modActions = pluginData.getPlugin(ModActionsPlugin);
|
const modActions = pluginData.getPlugin(ModActionsPlugin);
|
||||||
for (const member of membersToWarn) {
|
for (const member of membersToWarn) {
|
||||||
if (!member) continue;
|
if (!member) continue;
|
||||||
await modActions.warnMember(member, reason, { contactMethods, caseArgs });
|
await modActions.warnMember(member, reason, { contactMethods, caseArgs, isAutomodAction: true });
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
|
@ -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,25 @@ import { automodTrigger } from "../helpers";
|
||||||
interface BanTriggerResultType {}
|
interface BanTriggerResultType {}
|
||||||
|
|
||||||
export const BanTrigger = automodTrigger<BanTriggerResultType>()({
|
export const BanTrigger = automodTrigger<BanTriggerResultType>()({
|
||||||
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 !== "ban") {
|
if (context.modAction?.type !== "ban") {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
console.log(context);
|
||||||
|
// 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: {},
|
||||||
|
|
|
@ -5,13 +5,24 @@ import { automodTrigger } from "../helpers";
|
||||||
interface KickTriggerResultType {}
|
interface KickTriggerResultType {}
|
||||||
|
|
||||||
export const KickTrigger = automodTrigger<KickTriggerResultType>()({
|
export const KickTrigger = automodTrigger<KickTriggerResultType>()({
|
||||||
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 !== "kick") {
|
if (context.modAction?.type !== "kick") {
|
||||||
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: {},
|
||||||
|
|
|
@ -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: {},
|
||||||
|
|
|
@ -5,13 +5,24 @@ import { automodTrigger } from "../helpers";
|
||||||
interface WarnTriggerResultType {}
|
interface WarnTriggerResultType {}
|
||||||
|
|
||||||
export const WarnTrigger = automodTrigger<WarnTriggerResultType>()({
|
export const WarnTrigger = automodTrigger<WarnTriggerResultType>()({
|
||||||
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 !== "warn") {
|
if (context.modAction?.type !== "warn") {
|
||||||
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;
|
||||||
|
|
|
@ -112,7 +112,5 @@ export const WarnCmd = modActionsCmd({
|
||||||
msg.channel,
|
msg.channel,
|
||||||
`Warned **${memberToWarn.user.username}#${memberToWarn.user.discriminator}** (Case #${warnResult.case.case_number})${messageResultText}`,
|
`Warned **${memberToWarn.user.username}#${memberToWarn.user.discriminator}** (Case #${warnResult.case.case_number})${messageResultText}`,
|
||||||
);
|
);
|
||||||
|
|
||||||
pluginData.state.events.emit("warn", user.id, reason);
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
|
@ -127,7 +127,7 @@ export async function banUserId(
|
||||||
banTime: banTime ? humanizeDuration(banTime) : null,
|
banTime: banTime ? humanizeDuration(banTime) : null,
|
||||||
});
|
});
|
||||||
|
|
||||||
pluginData.state.events.emit("ban", user.id, reason);
|
pluginData.state.events.emit("ban", user.id, reason, banOptions.isAutomodAction);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
status: "success",
|
status: "success",
|
||||||
|
|
|
@ -85,7 +85,7 @@ export async function kickMember(
|
||||||
reason,
|
reason,
|
||||||
});
|
});
|
||||||
|
|
||||||
pluginData.state.events.emit("kick", member.id, reason);
|
pluginData.state.events.emit("kick", member.id, reason, kickOptions.isAutomodAction);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
status: "success",
|
status: "success",
|
||||||
|
|
|
@ -82,6 +82,8 @@ export async function warnMember(
|
||||||
reason,
|
reason,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
pluginData.state.events.emit("warn", member.id, reason, warnOptions.isAutomodAction);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
status: "success",
|
status: "success",
|
||||||
case: createdCase,
|
case: createdCase,
|
||||||
|
|
|
@ -48,9 +48,9 @@ export type TConfigSchema = t.TypeOf<typeof ConfigSchema>;
|
||||||
|
|
||||||
export interface ModActionsEvents {
|
export interface ModActionsEvents {
|
||||||
note: (userId: string, reason?: string) => void;
|
note: (userId: string, reason?: string) => void;
|
||||||
warn: (userId: string, reason?: string) => void;
|
warn: (userId: string, reason?: string, isAutomodAction?: boolean) => void;
|
||||||
kick: (userId: string, reason?: string) => void;
|
kick: (userId: string, reason?: string, isAutomodAction?: boolean) => void;
|
||||||
ban: (userId: string, reason?: string) => void;
|
ban: (userId: string, reason?: string, isAutomodAction?: boolean) => void;
|
||||||
unban: (userId: string, reason?: string) => void;
|
unban: (userId: string, reason?: string) => void;
|
||||||
// mute/unmute are in the Mutes plugin
|
// mute/unmute are in the Mutes plugin
|
||||||
}
|
}
|
||||||
|
@ -126,17 +126,20 @@ export interface WarnOptions {
|
||||||
caseArgs?: Partial<CaseArgs> | null;
|
caseArgs?: Partial<CaseArgs> | null;
|
||||||
contactMethods?: UserNotificationMethod[] | null;
|
contactMethods?: UserNotificationMethod[] | null;
|
||||||
retryPromptChannel?: TextChannel | null;
|
retryPromptChannel?: TextChannel | null;
|
||||||
|
isAutomodAction?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface KickOptions {
|
export interface KickOptions {
|
||||||
caseArgs?: Partial<CaseArgs>;
|
caseArgs?: Partial<CaseArgs>;
|
||||||
contactMethods?: UserNotificationMethod[];
|
contactMethods?: UserNotificationMethod[];
|
||||||
|
isAutomodAction?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface BanOptions {
|
export interface BanOptions {
|
||||||
caseArgs?: Partial<CaseArgs>;
|
caseArgs?: Partial<CaseArgs>;
|
||||||
contactMethods?: UserNotificationMethod[];
|
contactMethods?: UserNotificationMethod[];
|
||||||
deleteMessageDays?: number;
|
deleteMessageDays?: number;
|
||||||
|
isAutomodAction?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type ModActionType = "note" | "warn" | "mute" | "unmute" | "kick" | "ban" | "unban";
|
export type ModActionType = "note" | "warn" | "mute" | "unmute" | "kick" | "ban" | "unban";
|
||||||
|
|
|
@ -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,7 +34,7 @@ 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, isAutomodAction?: boolean) => void;
|
||||||
unmute: (userId: string, reason?: string) => void;
|
unmute: (userId: string, reason?: string) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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
Reference in a new issue