mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-05-13 21:35:02 +00:00
Automod actions + ModActions public interface
This commit is contained in:
parent
0f0728bc1c
commit
86023877a2
22 changed files with 508 additions and 16 deletions
backend/src/plugins/Automod/functions
|
@ -0,0 +1,12 @@
|
|||
import { PluginData } from "knub";
|
||||
import { AutomodPluginType } from "../types";
|
||||
import { RECENT_NICKNAME_CHANGE_EXPIRY_TIME, RECENT_SPAM_EXPIRY_TIME } from "../constants";
|
||||
|
||||
export function clearOldRecentNicknameChanges(pluginData: PluginData<AutomodPluginType>) {
|
||||
const now = Date.now();
|
||||
for (const [userId, { timestamp }] of pluginData.state.recentNicknameChanges) {
|
||||
if (timestamp + RECENT_NICKNAME_CHANGE_EXPIRY_TIME <= now) {
|
||||
pluginData.state.recentNicknameChanges.delete(userId);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
import { disableUserNotificationStrings, UserNotificationMethod } from "../../../utils";
|
||||
import { ERRORS, RecoverablePluginError } from "../../../RecoverablePluginError";
|
||||
import { TextChannel } from "eris";
|
||||
import { PluginData } from "knub";
|
||||
import { AutomodPluginType } from "../types";
|
||||
|
||||
export function resolveActionContactMethods(
|
||||
pluginData: PluginData<AutomodPluginType>,
|
||||
actionConfig: {
|
||||
notify?: string;
|
||||
notifyChannel?: string;
|
||||
},
|
||||
): UserNotificationMethod[] | null {
|
||||
if (actionConfig.notify === "dm") {
|
||||
return [{ type: "dm" }];
|
||||
} else if (actionConfig.notify === "channel") {
|
||||
if (!actionConfig.notifyChannel) {
|
||||
throw new RecoverablePluginError(ERRORS.NO_USER_NOTIFICATION_CHANNEL);
|
||||
}
|
||||
|
||||
const channel = pluginData.guild.channels.get(actionConfig.notifyChannel);
|
||||
if (!(channel instanceof TextChannel)) {
|
||||
throw new RecoverablePluginError(ERRORS.INVALID_USER_NOTIFICATION_CHANNEL);
|
||||
}
|
||||
|
||||
return [{ type: "channel", channel }];
|
||||
} else if (actionConfig.notify && disableUserNotificationStrings.includes(actionConfig.notify)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
|
@ -25,7 +25,6 @@ export async function runAutomod(pluginData: PluginData<AutomodPluginType>, cont
|
|||
if (!rule.affects_bots && user.bot) continue;
|
||||
|
||||
let matchResult: AutomodTriggerMatchResult<any>;
|
||||
let matchSummary: string;
|
||||
let contexts: AutomodContext[];
|
||||
|
||||
triggerLoop: for (const triggerItem of rule.triggers) {
|
||||
|
@ -45,17 +44,7 @@ export async function runAutomod(pluginData: PluginData<AutomodPluginType>, cont
|
|||
_context.actioned = true;
|
||||
}
|
||||
|
||||
if (matchResult.silentClean) {
|
||||
await CleanAction.apply({
|
||||
ruleName,
|
||||
pluginData,
|
||||
contexts,
|
||||
actionConfig: true,
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
matchSummary = await trigger.renderMatchInformation({
|
||||
matchResult.summary = await trigger.renderMatchInformation({
|
||||
ruleName,
|
||||
pluginData,
|
||||
contexts,
|
||||
|
@ -63,6 +52,17 @@ export async function runAutomod(pluginData: PluginData<AutomodPluginType>, cont
|
|||
triggerConfig,
|
||||
});
|
||||
|
||||
if (matchResult.silentClean) {
|
||||
await CleanAction.apply({
|
||||
ruleName,
|
||||
pluginData,
|
||||
contexts,
|
||||
actionConfig: true,
|
||||
matchResult,
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
break triggerLoop;
|
||||
}
|
||||
}
|
||||
|
@ -76,6 +76,7 @@ export async function runAutomod(pluginData: PluginData<AutomodPluginType>, cont
|
|||
pluginData,
|
||||
contexts,
|
||||
actionConfig,
|
||||
matchResult,
|
||||
});
|
||||
}
|
||||
|
||||
|
|
18
backend/src/plugins/Automod/functions/setAntiraidLevel.ts
Normal file
18
backend/src/plugins/Automod/functions/setAntiraidLevel.ts
Normal file
|
@ -0,0 +1,18 @@
|
|||
import { User } from "eris";
|
||||
import { PluginData } from "knub";
|
||||
import { AutomodPluginType } from "../types";
|
||||
|
||||
export async function setAntiraidLevel(
|
||||
pluginData: PluginData<AutomodPluginType>,
|
||||
newLevel: string | null,
|
||||
user?: User,
|
||||
) {
|
||||
pluginData.state.cachedAntiraidLevel = newLevel;
|
||||
await pluginData.state.antiraidLevels.set(newLevel);
|
||||
|
||||
if (user) {
|
||||
// TODO: Log user action
|
||||
} else {
|
||||
// TODO: Log automatic action
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue