feat: option to trigger antiraid_level only on change (#424)
Co-authored-by: Almeida <github@almeidx.dev>
This commit is contained in:
parent
d51461ee3a
commit
8a4a2d3647
4 changed files with 16 additions and 3 deletions
|
@ -5,13 +5,15 @@ import { AutomodContext, AutomodPluginType } from "../types";
|
|||
|
||||
export async function runAutomodOnAntiraidLevel(
|
||||
pluginData: GuildPluginData<AutomodPluginType>,
|
||||
level: string | null,
|
||||
newLevel: string | null,
|
||||
oldLevel: string | null,
|
||||
user?: User,
|
||||
) {
|
||||
const context: AutomodContext = {
|
||||
timestamp: Date.now(),
|
||||
antiraid: {
|
||||
level,
|
||||
level: newLevel,
|
||||
oldLevel,
|
||||
},
|
||||
user,
|
||||
};
|
||||
|
|
|
@ -9,10 +9,11 @@ export async function setAntiraidLevel(
|
|||
newLevel: string | null,
|
||||
user?: User,
|
||||
) {
|
||||
const oldLevel = pluginData.state.cachedAntiraidLevel;
|
||||
pluginData.state.cachedAntiraidLevel = newLevel;
|
||||
await pluginData.state.antiraidLevels.set(newLevel);
|
||||
|
||||
runAutomodOnAntiraidLevel(pluginData, newLevel, user);
|
||||
runAutomodOnAntiraidLevel(pluginData, newLevel, oldLevel, user);
|
||||
|
||||
const logs = pluginData.getPlugin(LogsPlugin);
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@ interface AntiraidLevelTriggerResult {}
|
|||
export const AntiraidLevelTrigger = automodTrigger<AntiraidLevelTriggerResult>()({
|
||||
configType: t.type({
|
||||
level: tNullable(t.string),
|
||||
only_on_change: tNullable(t.boolean),
|
||||
}),
|
||||
|
||||
defaultConfig: {},
|
||||
|
@ -20,6 +21,14 @@ export const AntiraidLevelTrigger = automodTrigger<AntiraidLevelTriggerResult>()
|
|||
return;
|
||||
}
|
||||
|
||||
if (
|
||||
triggerConfig.only_on_change &&
|
||||
context.antiraid.oldLevel !== undefined &&
|
||||
context.antiraid.level === context.antiraid.oldLevel
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
return {
|
||||
extra: {},
|
||||
};
|
||||
|
|
|
@ -130,6 +130,7 @@ export interface AutomodContext {
|
|||
};
|
||||
antiraid?: {
|
||||
level: string | null;
|
||||
oldLevel?: string | null;
|
||||
};
|
||||
threadChange?: {
|
||||
created?: ThreadChannel;
|
||||
|
|
Loading…
Add table
Reference in a new issue