Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to trigger antiraid_level only on change #424

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down
3 changes: 2 additions & 1 deletion backend/src/plugins/Automod/functions/setAntiraidLevel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
9 changes: 9 additions & 0 deletions backend/src/plugins/Automod/triggers/antiraidLevel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {},
Expand All @@ -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: {},
};
Expand Down
1 change: 1 addition & 0 deletions backend/src/plugins/Automod/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ export interface AutomodContext {
};
antiraid?: {
level: string | null;
oldLevel?: string | null;
};
threadChange?: {
created?: ThreadChannel;
Expand Down
Loading