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(
|
export async function runAutomodOnAntiraidLevel(
|
||||||
pluginData: GuildPluginData<AutomodPluginType>,
|
pluginData: GuildPluginData<AutomodPluginType>,
|
||||||
level: string | null,
|
newLevel: string | null,
|
||||||
|
oldLevel: string | null,
|
||||||
user?: User,
|
user?: User,
|
||||||
) {
|
) {
|
||||||
const context: AutomodContext = {
|
const context: AutomodContext = {
|
||||||
timestamp: Date.now(),
|
timestamp: Date.now(),
|
||||||
antiraid: {
|
antiraid: {
|
||||||
level,
|
level: newLevel,
|
||||||
|
oldLevel,
|
||||||
},
|
},
|
||||||
user,
|
user,
|
||||||
};
|
};
|
||||||
|
|
|
@ -9,10 +9,11 @@ export async function setAntiraidLevel(
|
||||||
newLevel: string | null,
|
newLevel: string | null,
|
||||||
user?: User,
|
user?: User,
|
||||||
) {
|
) {
|
||||||
|
const oldLevel = pluginData.state.cachedAntiraidLevel;
|
||||||
pluginData.state.cachedAntiraidLevel = newLevel;
|
pluginData.state.cachedAntiraidLevel = newLevel;
|
||||||
await pluginData.state.antiraidLevels.set(newLevel);
|
await pluginData.state.antiraidLevels.set(newLevel);
|
||||||
|
|
||||||
runAutomodOnAntiraidLevel(pluginData, newLevel, user);
|
runAutomodOnAntiraidLevel(pluginData, newLevel, oldLevel, user);
|
||||||
|
|
||||||
const logs = pluginData.getPlugin(LogsPlugin);
|
const logs = pluginData.getPlugin(LogsPlugin);
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,7 @@ interface AntiraidLevelTriggerResult {}
|
||||||
export const AntiraidLevelTrigger = automodTrigger<AntiraidLevelTriggerResult>()({
|
export const AntiraidLevelTrigger = automodTrigger<AntiraidLevelTriggerResult>()({
|
||||||
configType: t.type({
|
configType: t.type({
|
||||||
level: tNullable(t.string),
|
level: tNullable(t.string),
|
||||||
|
only_on_change: tNullable(t.boolean),
|
||||||
}),
|
}),
|
||||||
|
|
||||||
defaultConfig: {},
|
defaultConfig: {},
|
||||||
|
@ -20,6 +21,14 @@ export const AntiraidLevelTrigger = automodTrigger<AntiraidLevelTriggerResult>()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
triggerConfig.only_on_change &&
|
||||||
|
context.antiraid.oldLevel !== undefined &&
|
||||||
|
context.antiraid.level === context.antiraid.oldLevel
|
||||||
|
) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
extra: {},
|
extra: {},
|
||||||
};
|
};
|
||||||
|
|
|
@ -130,6 +130,7 @@ export interface AutomodContext {
|
||||||
};
|
};
|
||||||
antiraid?: {
|
antiraid?: {
|
||||||
level: string | null;
|
level: string | null;
|
||||||
|
oldLevel?: string | null;
|
||||||
};
|
};
|
||||||
threadChange?: {
|
threadChange?: {
|
||||||
created?: ThreadChannel;
|
created?: ThreadChannel;
|
||||||
|
|
Loading…
Add table
Reference in a new issue