mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-03-15 05:41:51 +00:00
automod: add antiraid_level trigger
This commit is contained in:
parent
13294ad351
commit
b28186aa0a
5 changed files with 114 additions and 0 deletions
|
@ -0,0 +1,16 @@
|
|||
import { GuildPluginData } from "knub";
|
||||
import { AutomodContext, AutomodPluginType } from "../types";
|
||||
import { runAutomod } from "../functions/runAutomod";
|
||||
|
||||
export async function runAutomodOnAntiraidLevel(pluginData: GuildPluginData<AutomodPluginType>, level: string | null) {
|
||||
const context: AutomodContext = {
|
||||
timestamp: Date.now(),
|
||||
antiraid: {
|
||||
level,
|
||||
},
|
||||
};
|
||||
|
||||
pluginData.state.queue.add(async () => {
|
||||
await runAutomod(pluginData, context);
|
||||
});
|
||||
}
|
|
@ -4,6 +4,7 @@ import { AutomodPluginType } from "../types";
|
|||
import { LogsPlugin } from "../../Logs/LogsPlugin";
|
||||
import { LogType } from "../../../data/LogType";
|
||||
import { stripObjectToScalars } from "../../../utils";
|
||||
import { runAutomodOnAntiraidLevel } from "../events/runAutomodOnAntiraidLevel";
|
||||
|
||||
export async function setAntiraidLevel(
|
||||
pluginData: GuildPluginData<AutomodPluginType>,
|
||||
|
@ -13,6 +14,8 @@ export async function setAntiraidLevel(
|
|||
pluginData.state.cachedAntiraidLevel = newLevel;
|
||||
await pluginData.state.antiraidLevels.set(newLevel);
|
||||
|
||||
runAutomodOnAntiraidLevel(pluginData, newLevel);
|
||||
|
||||
const logs = pluginData.getPlugin(LogsPlugin);
|
||||
|
||||
if (user) {
|
||||
|
|
32
backend/src/plugins/Automod/triggers/antiraidLevel.ts
Normal file
32
backend/src/plugins/Automod/triggers/antiraidLevel.ts
Normal file
|
@ -0,0 +1,32 @@
|
|||
import * as t from "io-ts";
|
||||
import { automodTrigger } from "../helpers";
|
||||
import { tNullable } from "../../../utils";
|
||||
|
||||
// tslint:disable-next-line
|
||||
interface AntiraidLevelTriggerResult {}
|
||||
|
||||
export const AntiraidLevelTrigger = automodTrigger<AntiraidLevelTriggerResult>()({
|
||||
configType: t.type({
|
||||
level: tNullable(t.string),
|
||||
}),
|
||||
|
||||
defaultConfig: {},
|
||||
|
||||
async match({ triggerConfig, context, pluginData }) {
|
||||
if (!context.antiraid) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (context.antiraid.level !== triggerConfig.level) {
|
||||
return;
|
||||
}
|
||||
|
||||
return {
|
||||
extra: {},
|
||||
};
|
||||
},
|
||||
|
||||
renderMatchInformation({ matchResult, pluginData, contexts, triggerConfig }) {
|
||||
return `Antiraid level was set to ...`;
|
||||
},
|
||||
});
|
|
@ -123,6 +123,9 @@ export interface AutomodContext {
|
|||
type: ModActionType;
|
||||
reason?: string;
|
||||
};
|
||||
antiraid?: {
|
||||
level: string | null;
|
||||
};
|
||||
}
|
||||
|
||||
export interface RecentAction {
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
<template v-slot:content>
|
||||
<CodeBlock>
|
||||
plugins:
|
||||
|
||||
counters:
|
||||
config:
|
||||
counters:
|
||||
|
@ -90,6 +91,7 @@
|
|||
<template v-slot:content>
|
||||
<CodeBlock code-lang="yaml">
|
||||
plugins:
|
||||
|
||||
counters:
|
||||
config:
|
||||
counters:
|
||||
|
@ -150,6 +152,7 @@
|
|||
<template v-slot:content>
|
||||
<CodeBlock>
|
||||
plugins:
|
||||
|
||||
counters:
|
||||
config:
|
||||
counters:
|
||||
|
@ -230,6 +233,7 @@
|
|||
<template v-slot:content>
|
||||
<CodeBlock code-lang="yaml">
|
||||
plugins:
|
||||
|
||||
counters:
|
||||
config:
|
||||
counters:
|
||||
|
@ -282,6 +286,62 @@
|
|||
</CodeBlock>
|
||||
</template>
|
||||
</Expandable>
|
||||
|
||||
<h3>Auto-disable antiraid</h3>
|
||||
<p>
|
||||
This example disables antiraid after a specific delay.
|
||||
</p>
|
||||
|
||||
<Expandable class="wide">
|
||||
<template v-slot:title>Click to view example</template>
|
||||
<template v-slot:content>
|
||||
<CodeBlock code-lang="yaml">
|
||||
plugins:
|
||||
|
||||
counters:
|
||||
config:
|
||||
counters:
|
||||
|
||||
antiraid_decay:
|
||||
triggers:
|
||||
disable:
|
||||
condition: "=0"
|
||||
decay:
|
||||
amount: 1
|
||||
every: 1m
|
||||
|
||||
automod:
|
||||
config:
|
||||
rules:
|
||||
|
||||
start_antiraid_timer_low:
|
||||
triggers:
|
||||
- antiraid_level:
|
||||
level: "low"
|
||||
actions:
|
||||
set_counter:
|
||||
counter: "antiraid_decay"
|
||||
amount: 10 # "Disable after 10min"
|
||||
|
||||
start_antiraid_timer_high:
|
||||
triggers:
|
||||
- antiraid_level:
|
||||
level: "high"
|
||||
actions:
|
||||
set_counter:
|
||||
counter: "antiraid_decay"
|
||||
amount: 20 # "Disable after 20min"
|
||||
|
||||
disable_antiraid_after_timer:
|
||||
triggers:
|
||||
- counter_trigger:
|
||||
counter: "antiraid_decay"
|
||||
trigger: "disable"
|
||||
actions:
|
||||
set_antiraid_level: null
|
||||
</CodeBlock>
|
||||
</template>
|
||||
</Expandable>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue