mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-05-10 12:25:02 +00:00
automod: add triggers for mod actions
This commit is contained in:
parent
5ffc3e7cc4
commit
93912541b4
34 changed files with 412 additions and 3 deletions
|
@ -31,6 +31,9 @@ import { RunAutomodOnMemberUpdate } from "./events/RunAutomodOnMemberUpdate";
|
|||
import { CountersPlugin } from "../Counters/CountersPlugin";
|
||||
import { parseCondition } from "../../data/GuildCounters";
|
||||
import { runAutomodOnCounterTrigger } from "./events/runAutomodOnCounterTrigger";
|
||||
import { runAutomodOnModAction } from "./events/runAutomodOnModAction";
|
||||
import { registerEventListenersFromMap } from "../../utils/registerEventListenersFromMap";
|
||||
import { unregisterEventListenersFromMap } from "../../utils/unregisterEventListenersFromMap";
|
||||
|
||||
const defaultOptions = {
|
||||
config: {
|
||||
|
@ -163,7 +166,13 @@ export const AutomodPlugin = zeppelinGuildPlugin<AutomodPluginType>()("automod",
|
|||
showInDocs: true,
|
||||
info: pluginInfo,
|
||||
|
||||
dependencies: [LogsPlugin, ModActionsPlugin, MutesPlugin, CountersPlugin],
|
||||
// prettier-ignore
|
||||
dependencies: [
|
||||
LogsPlugin,
|
||||
ModActionsPlugin,
|
||||
MutesPlugin,
|
||||
CountersPlugin,
|
||||
],
|
||||
|
||||
configSchema: ConfigSchema,
|
||||
defaultOptions,
|
||||
|
@ -173,6 +182,7 @@ export const AutomodPlugin = zeppelinGuildPlugin<AutomodPluginType>()("automod",
|
|||
return criteria?.antiraid_level ? criteria.antiraid_level === pluginData.state.cachedAntiraidLevel : false;
|
||||
},
|
||||
|
||||
// prettier-ignore
|
||||
events: [
|
||||
RunAutomodOnJoinEvt,
|
||||
RunAutomodOnMemberUpdate,
|
||||
|
@ -238,13 +248,45 @@ export const AutomodPlugin = zeppelinGuildPlugin<AutomodPluginType>()("automod",
|
|||
|
||||
countersPlugin.onCounterEvent("trigger", pluginData.state.onCounterTrigger);
|
||||
countersPlugin.onCounterEvent("reverseTrigger", pluginData.state.onCounterReverseTrigger);
|
||||
|
||||
const modActionsEvents = pluginData.getPlugin(ModActionsPlugin).getEventEmitter();
|
||||
pluginData.state.modActionsListeners = new Map();
|
||||
pluginData.state.modActionsListeners.set("note", (userId: string) =>
|
||||
runAutomodOnModAction(pluginData, "note", userId),
|
||||
);
|
||||
pluginData.state.modActionsListeners.set("warn", (userId: string) =>
|
||||
runAutomodOnModAction(pluginData, "warn", userId),
|
||||
);
|
||||
pluginData.state.modActionsListeners.set("kick", (userId: string) =>
|
||||
runAutomodOnModAction(pluginData, "kick", userId),
|
||||
);
|
||||
pluginData.state.modActionsListeners.set("ban", (userId: string) =>
|
||||
runAutomodOnModAction(pluginData, "ban", userId),
|
||||
);
|
||||
pluginData.state.modActionsListeners.set("unban", (userId: string) =>
|
||||
runAutomodOnModAction(pluginData, "unban", userId),
|
||||
);
|
||||
registerEventListenersFromMap(modActionsEvents, pluginData.state.modActionsListeners);
|
||||
|
||||
const mutesEvents = pluginData.getPlugin(MutesPlugin).getEventEmitter();
|
||||
pluginData.state.mutesListeners = new Map();
|
||||
pluginData.state.mutesListeners.set("mute", (userId: string) => runAutomodOnModAction(pluginData, "mute", userId));
|
||||
pluginData.state.mutesListeners.set("unmute", (userId: string) =>
|
||||
runAutomodOnModAction(pluginData, "unmute", userId),
|
||||
);
|
||||
registerEventListenersFromMap(mutesEvents, pluginData.state.mutesListeners);
|
||||
},
|
||||
|
||||
async onBeforeUnload(pluginData) {
|
||||
const countersPlugin = pluginData.getPlugin(CountersPlugin);
|
||||
|
||||
countersPlugin.offCounterEvent("trigger", pluginData.state.onCounterTrigger);
|
||||
countersPlugin.offCounterEvent("reverseTrigger", pluginData.state.onCounterReverseTrigger);
|
||||
|
||||
const modActionsEvents = pluginData.getPlugin(ModActionsPlugin).getEventEmitter();
|
||||
unregisterEventListenersFromMap(modActionsEvents, pluginData.state.modActionsListeners);
|
||||
|
||||
const mutesEvents = pluginData.getPlugin(MutesPlugin).getEventEmitter();
|
||||
unregisterEventListenersFromMap(mutesEvents, pluginData.state.mutesListeners);
|
||||
},
|
||||
|
||||
async onUnload(pluginData) {
|
||||
|
|
27
backend/src/plugins/Automod/events/runAutomodOnModAction.ts
Normal file
27
backend/src/plugins/Automod/events/runAutomodOnModAction.ts
Normal file
|
@ -0,0 +1,27 @@
|
|||
import { GuildPluginData } from "knub";
|
||||
import { AutomodContext, AutomodPluginType } from "../types";
|
||||
import { runAutomod } from "../functions/runAutomod";
|
||||
import { resolveUser, UnknownUser } from "../../../utils";
|
||||
import { ModActionType } from "../../ModActions/types";
|
||||
|
||||
export async function runAutomodOnModAction(
|
||||
pluginData: GuildPluginData<AutomodPluginType>,
|
||||
modAction: ModActionType,
|
||||
userId: string,
|
||||
reason?: string,
|
||||
) {
|
||||
const user = await resolveUser(pluginData.client, userId);
|
||||
|
||||
const context: AutomodContext = {
|
||||
timestamp: Date.now(),
|
||||
user: user instanceof UnknownUser ? undefined : user,
|
||||
modAction: {
|
||||
type: modAction,
|
||||
reason,
|
||||
},
|
||||
};
|
||||
|
||||
pluginData.state.queue.add(async () => {
|
||||
await runAutomod(pluginData, context);
|
||||
});
|
||||
}
|
|
@ -18,6 +18,13 @@ import { RoleAddedTrigger } from "./roleAdded";
|
|||
import { RoleRemovedTrigger } from "./roleRemoved";
|
||||
import { StickerSpamTrigger } from "./stickerSpam";
|
||||
import { CounterTrigger } from "./counter";
|
||||
import { NoteTrigger } from "./note";
|
||||
import { WarnTrigger } from "./warn";
|
||||
import { MuteTrigger } from "./mute";
|
||||
import { UnmuteTrigger } from "./unmute";
|
||||
import { KickTrigger } from "./kick";
|
||||
import { BanTrigger } from "./ban";
|
||||
import { UnbanTrigger } from "./unban";
|
||||
|
||||
export const availableTriggers: Record<string, AutomodTriggerBlueprint<any, any>> = {
|
||||
match_words: MatchWordsTrigger,
|
||||
|
@ -40,6 +47,14 @@ export const availableTriggers: Record<string, AutomodTriggerBlueprint<any, any>
|
|||
sticker_spam: StickerSpamTrigger,
|
||||
|
||||
counter: CounterTrigger,
|
||||
|
||||
note: NoteTrigger,
|
||||
warn: WarnTrigger,
|
||||
mute: MuteTrigger,
|
||||
unmute: UnmuteTrigger,
|
||||
kick: KickTrigger,
|
||||
ban: BanTrigger,
|
||||
unban: UnbanTrigger,
|
||||
};
|
||||
|
||||
export const AvailableTriggers = t.type({
|
||||
|
@ -63,4 +78,12 @@ export const AvailableTriggers = t.type({
|
|||
sticker_spam: StickerSpamTrigger.configType,
|
||||
|
||||
counter: CounterTrigger.configType,
|
||||
|
||||
note: NoteTrigger.configType,
|
||||
warn: WarnTrigger.configType,
|
||||
mute: MuteTrigger.configType,
|
||||
unmute: UnmuteTrigger.configType,
|
||||
kick: KickTrigger.configType,
|
||||
ban: BanTrigger.configType,
|
||||
unban: UnbanTrigger.configType,
|
||||
});
|
||||
|
|
24
backend/src/plugins/Automod/triggers/ban.ts
Normal file
24
backend/src/plugins/Automod/triggers/ban.ts
Normal file
|
@ -0,0 +1,24 @@
|
|||
import * as t from "io-ts";
|
||||
import { automodTrigger } from "../helpers";
|
||||
|
||||
// tslint:disable-next-line:no-empty-interface
|
||||
interface BanTriggerResultType {}
|
||||
|
||||
export const BanTrigger = automodTrigger<BanTriggerResultType>()({
|
||||
configType: t.type({}),
|
||||
defaultConfig: {},
|
||||
|
||||
async match({ context }) {
|
||||
if (context.modAction?.type !== "ban") {
|
||||
return;
|
||||
}
|
||||
|
||||
return {
|
||||
extra: {},
|
||||
};
|
||||
},
|
||||
|
||||
renderMatchInformation({ matchResult }) {
|
||||
return `User was banned`;
|
||||
},
|
||||
});
|
24
backend/src/plugins/Automod/triggers/kick.ts
Normal file
24
backend/src/plugins/Automod/triggers/kick.ts
Normal file
|
@ -0,0 +1,24 @@
|
|||
import * as t from "io-ts";
|
||||
import { automodTrigger } from "../helpers";
|
||||
|
||||
// tslint:disable-next-line:no-empty-interface
|
||||
interface KickTriggerResultType {}
|
||||
|
||||
export const KickTrigger = automodTrigger<KickTriggerResultType>()({
|
||||
configType: t.type({}),
|
||||
defaultConfig: {},
|
||||
|
||||
async match({ context }) {
|
||||
if (context.modAction?.type !== "kick") {
|
||||
return;
|
||||
}
|
||||
|
||||
return {
|
||||
extra: {},
|
||||
};
|
||||
},
|
||||
|
||||
renderMatchInformation({ matchResult }) {
|
||||
return `User was kicked`;
|
||||
},
|
||||
});
|
24
backend/src/plugins/Automod/triggers/mute.ts
Normal file
24
backend/src/plugins/Automod/triggers/mute.ts
Normal file
|
@ -0,0 +1,24 @@
|
|||
import * as t from "io-ts";
|
||||
import { automodTrigger } from "../helpers";
|
||||
|
||||
// tslint:disable-next-line:no-empty-interface
|
||||
interface MuteTriggerResultType {}
|
||||
|
||||
export const MuteTrigger = automodTrigger<MuteTriggerResultType>()({
|
||||
configType: t.type({}),
|
||||
defaultConfig: {},
|
||||
|
||||
async match({ context }) {
|
||||
if (context.modAction?.type !== "mute") {
|
||||
return;
|
||||
}
|
||||
|
||||
return {
|
||||
extra: {},
|
||||
};
|
||||
},
|
||||
|
||||
renderMatchInformation({ matchResult }) {
|
||||
return `User was muted`;
|
||||
},
|
||||
});
|
24
backend/src/plugins/Automod/triggers/note.ts
Normal file
24
backend/src/plugins/Automod/triggers/note.ts
Normal file
|
@ -0,0 +1,24 @@
|
|||
import * as t from "io-ts";
|
||||
import { automodTrigger } from "../helpers";
|
||||
|
||||
// tslint:disable-next-line:no-empty-interface
|
||||
interface NoteTriggerResultType {}
|
||||
|
||||
export const NoteTrigger = automodTrigger<NoteTriggerResultType>()({
|
||||
configType: t.type({}),
|
||||
defaultConfig: {},
|
||||
|
||||
async match({ context }) {
|
||||
if (context.modAction?.type !== "note") {
|
||||
return;
|
||||
}
|
||||
|
||||
return {
|
||||
extra: {},
|
||||
};
|
||||
},
|
||||
|
||||
renderMatchInformation({ matchResult }) {
|
||||
return `Note was added on user`;
|
||||
},
|
||||
});
|
24
backend/src/plugins/Automod/triggers/unban.ts
Normal file
24
backend/src/plugins/Automod/triggers/unban.ts
Normal file
|
@ -0,0 +1,24 @@
|
|||
import * as t from "io-ts";
|
||||
import { automodTrigger } from "../helpers";
|
||||
|
||||
// tslint:disable-next-line:no-empty-interface
|
||||
interface UnbanTriggerResultType {}
|
||||
|
||||
export const UnbanTrigger = automodTrigger<UnbanTriggerResultType>()({
|
||||
configType: t.type({}),
|
||||
defaultConfig: {},
|
||||
|
||||
async match({ context }) {
|
||||
if (context.modAction?.type !== "unban") {
|
||||
return;
|
||||
}
|
||||
|
||||
return {
|
||||
extra: {},
|
||||
};
|
||||
},
|
||||
|
||||
renderMatchInformation({ matchResult }) {
|
||||
return `User was unbanned`;
|
||||
},
|
||||
});
|
24
backend/src/plugins/Automod/triggers/unmute.ts
Normal file
24
backend/src/plugins/Automod/triggers/unmute.ts
Normal file
|
@ -0,0 +1,24 @@
|
|||
import * as t from "io-ts";
|
||||
import { automodTrigger } from "../helpers";
|
||||
|
||||
// tslint:disable-next-line:no-empty-interface
|
||||
interface UnmuteTriggerResultType {}
|
||||
|
||||
export const UnmuteTrigger = automodTrigger<UnmuteTriggerResultType>()({
|
||||
configType: t.type({}),
|
||||
defaultConfig: {},
|
||||
|
||||
async match({ context }) {
|
||||
if (context.modAction?.type !== "unmute") {
|
||||
return;
|
||||
}
|
||||
|
||||
return {
|
||||
extra: {},
|
||||
};
|
||||
},
|
||||
|
||||
renderMatchInformation({ matchResult }) {
|
||||
return `User was unmuted`;
|
||||
},
|
||||
});
|
24
backend/src/plugins/Automod/triggers/warn.ts
Normal file
24
backend/src/plugins/Automod/triggers/warn.ts
Normal file
|
@ -0,0 +1,24 @@
|
|||
import * as t from "io-ts";
|
||||
import { automodTrigger } from "../helpers";
|
||||
|
||||
// tslint:disable-next-line:no-empty-interface
|
||||
interface WarnTriggerResultType {}
|
||||
|
||||
export const WarnTrigger = automodTrigger<WarnTriggerResultType>()({
|
||||
configType: t.type({}),
|
||||
defaultConfig: {},
|
||||
|
||||
async match({ context }) {
|
||||
if (context.modAction?.type !== "warn") {
|
||||
return;
|
||||
}
|
||||
|
||||
return {
|
||||
extra: {},
|
||||
};
|
||||
},
|
||||
|
||||
renderMatchInformation({ matchResult }) {
|
||||
return `User was warned`;
|
||||
},
|
||||
});
|
|
@ -14,6 +14,8 @@ import { RecentActionType } from "./constants";
|
|||
import Timeout = NodeJS.Timeout;
|
||||
import { RegExpRunner } from "../../RegExpRunner";
|
||||
import { CounterEvents } from "../Counters/types";
|
||||
import { ModActionsEvents, ModActionType } from "../ModActions/types";
|
||||
import { MutesEvents } from "../Mutes/types";
|
||||
|
||||
export const Rule = t.type({
|
||||
enabled: t.boolean,
|
||||
|
@ -90,6 +92,9 @@ export interface AutomodPluginType extends BasePluginType {
|
|||
|
||||
onCounterTrigger: CounterEvents["trigger"];
|
||||
onCounterReverseTrigger: CounterEvents["reverseTrigger"];
|
||||
|
||||
modActionsListeners: Map<keyof ModActionsEvents, any>;
|
||||
mutesListeners: Map<keyof MutesEvents, any>;
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -112,6 +117,10 @@ export interface AutomodContext {
|
|||
added?: string[];
|
||||
removed?: string[];
|
||||
};
|
||||
modAction?: {
|
||||
type: ModActionType;
|
||||
reason?: string;
|
||||
};
|
||||
}
|
||||
|
||||
export interface RecentAction {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue