3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-05-10 04:25:01 +00:00
zeppelin/backend/src/plugins/Automod/functions/setAntiraidLevel.ts

31 lines
945 B
TypeScript

import { GuildPluginData } from "knub";
import { AutomodPluginType } from "../types";
import { LogsPlugin } from "../../Logs/LogsPlugin";
import { LogType } from "../../../data/LogType";
import { stripObjectToScalars } from "../../../utils";
import { runAutomodOnAntiraidLevel } from "../events/runAutomodOnAntiraidLevel";
import { User } from "discord.js";
export async function setAntiraidLevel(
pluginData: GuildPluginData<AutomodPluginType>,
newLevel: string | null,
user?: User,
) {
pluginData.state.cachedAntiraidLevel = newLevel;
await pluginData.state.antiraidLevels.set(newLevel);
runAutomodOnAntiraidLevel(pluginData, newLevel, user);
const logs = pluginData.getPlugin(LogsPlugin);
if (user) {
logs.log(LogType.SET_ANTIRAID_USER, {
level: newLevel ?? "off",
user: stripObjectToScalars(user),
});
} else {
logs.log(LogType.SET_ANTIRAID_AUTO, {
level: newLevel ?? "off",
});
}
}