From 8a99f33aa0cf1bd3c4f71153d57f061a6a440103 Mon Sep 17 00:00:00 2001 From: Ben Richeson Date: Wed, 30 Aug 2023 01:20:42 -0400 Subject: [PATCH 1/4] feat(AutomodPlugin): toggle invite action --- .../src/plugins/Automod/actions/availableActions.ts | 3 +++ .../src/plugins/Automod/actions/toggleInvites.ts | 13 +++++++++++++ 2 files changed, 16 insertions(+) create mode 100644 backend/src/plugins/Automod/actions/toggleInvites.ts diff --git a/backend/src/plugins/Automod/actions/availableActions.ts b/backend/src/plugins/Automod/actions/availableActions.ts index 3f253bc05..e723de62c 100644 --- a/backend/src/plugins/Automod/actions/availableActions.ts +++ b/backend/src/plugins/Automod/actions/availableActions.ts @@ -17,6 +17,7 @@ import { SetAntiraidLevelAction } from "./setAntiraidLevel"; import { SetCounterAction } from "./setCounter"; import { SetSlowmodeAction } from "./setSlowmode"; import { StartThreadAction } from "./startThread"; +import { ToggleInvitesAction } from "./toggleInvites"; import { WarnAction } from "./warn"; export const availableActions: Record> = { @@ -38,6 +39,7 @@ export const availableActions: Record> = { start_thread: StartThreadAction, archive_thread: ArchiveThreadAction, change_perms: ChangePermsAction, + toggle_invites: ToggleInvitesAction, }; export const AvailableActions = t.type({ @@ -59,4 +61,5 @@ export const AvailableActions = t.type({ start_thread: StartThreadAction.configType, archive_thread: ArchiveThreadAction.configType, change_perms: ChangePermsAction.configType, + toggle_invites: ToggleInvitesAction.configType, }); diff --git a/backend/src/plugins/Automod/actions/toggleInvites.ts b/backend/src/plugins/Automod/actions/toggleInvites.ts new file mode 100644 index 000000000..fb3652c55 --- /dev/null +++ b/backend/src/plugins/Automod/actions/toggleInvites.ts @@ -0,0 +1,13 @@ +import * as t from "io-ts"; +import { automodAction } from "../helpers"; + +export const ToggleInvitesAction = automodAction({ + configType: t.type({ + enabled: t.boolean, + }), + defaultConfig: {}, + + async apply({ pluginData, actionConfig }) { + await pluginData.guild.disableInvites(!actionConfig.enabled); + }, +}); From d69a9c3dc7f2e966931b99ddcafa23ca2736efcd Mon Sep 17 00:00:00 2001 From: Ben Richeson Date: Wed, 30 Aug 2023 13:32:45 -0400 Subject: [PATCH 2/4] feat: rename and change config shape --- .../src/plugins/Automod/actions/availableActions.ts | 6 +++--- .../src/plugins/Automod/actions/disableInvites.ts | 11 +++++++++++ .../src/plugins/Automod/actions/toggleInvites.ts | 13 ------------- 3 files changed, 14 insertions(+), 16 deletions(-) create mode 100644 backend/src/plugins/Automod/actions/disableInvites.ts delete mode 100644 backend/src/plugins/Automod/actions/toggleInvites.ts diff --git a/backend/src/plugins/Automod/actions/availableActions.ts b/backend/src/plugins/Automod/actions/availableActions.ts index e723de62c..757b224bd 100644 --- a/backend/src/plugins/Automod/actions/availableActions.ts +++ b/backend/src/plugins/Automod/actions/availableActions.ts @@ -8,6 +8,7 @@ import { BanAction } from "./ban"; import { ChangeNicknameAction } from "./changeNickname"; import { ChangePermsAction } from "./changePerms"; import { CleanAction } from "./clean"; +import { DisableInvitesAction } from "./disableInvites"; import { KickAction } from "./kick"; import { LogAction } from "./log"; import { MuteAction } from "./mute"; @@ -17,7 +18,6 @@ import { SetAntiraidLevelAction } from "./setAntiraidLevel"; import { SetCounterAction } from "./setCounter"; import { SetSlowmodeAction } from "./setSlowmode"; import { StartThreadAction } from "./startThread"; -import { ToggleInvitesAction } from "./toggleInvites"; import { WarnAction } from "./warn"; export const availableActions: Record> = { @@ -39,7 +39,7 @@ export const availableActions: Record> = { start_thread: StartThreadAction, archive_thread: ArchiveThreadAction, change_perms: ChangePermsAction, - toggle_invites: ToggleInvitesAction, + disable_invites: DisableInvitesAction, }; export const AvailableActions = t.type({ @@ -61,5 +61,5 @@ export const AvailableActions = t.type({ start_thread: StartThreadAction.configType, archive_thread: ArchiveThreadAction.configType, change_perms: ChangePermsAction.configType, - toggle_invites: ToggleInvitesAction.configType, + disable_invites: DisableInvitesAction.configType, }); diff --git a/backend/src/plugins/Automod/actions/disableInvites.ts b/backend/src/plugins/Automod/actions/disableInvites.ts new file mode 100644 index 000000000..af82a81cd --- /dev/null +++ b/backend/src/plugins/Automod/actions/disableInvites.ts @@ -0,0 +1,11 @@ +import * as t from "io-ts"; +import { automodAction } from "../helpers"; + +export const DisableInvitesAction = automodAction({ + configType: t.boolean, + defaultConfig: true, + + async apply({ pluginData, actionConfig }) { + await pluginData.guild.disableInvites(actionConfig); + }, +}); diff --git a/backend/src/plugins/Automod/actions/toggleInvites.ts b/backend/src/plugins/Automod/actions/toggleInvites.ts deleted file mode 100644 index fb3652c55..000000000 --- a/backend/src/plugins/Automod/actions/toggleInvites.ts +++ /dev/null @@ -1,13 +0,0 @@ -import * as t from "io-ts"; -import { automodAction } from "../helpers"; - -export const ToggleInvitesAction = automodAction({ - configType: t.type({ - enabled: t.boolean, - }), - defaultConfig: {}, - - async apply({ pluginData, actionConfig }) { - await pluginData.guild.disableInvites(!actionConfig.enabled); - }, -}); From 31fcbed7b91a66e1e4bb41c82dae16903947f935 Mon Sep 17 00:00:00 2001 From: Ben Richeson Date: Wed, 30 Aug 2023 13:37:41 -0400 Subject: [PATCH 3/4] refactor: rename disable_invites to pause_invites --- backend/src/plugins/Automod/actions/availableActions.ts | 6 +++--- .../Automod/actions/{disableInvites.ts => pauseInvites.ts} | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) rename backend/src/plugins/Automod/actions/{disableInvites.ts => pauseInvites.ts} (81%) diff --git a/backend/src/plugins/Automod/actions/availableActions.ts b/backend/src/plugins/Automod/actions/availableActions.ts index 757b224bd..b77f39421 100644 --- a/backend/src/plugins/Automod/actions/availableActions.ts +++ b/backend/src/plugins/Automod/actions/availableActions.ts @@ -8,10 +8,10 @@ import { BanAction } from "./ban"; import { ChangeNicknameAction } from "./changeNickname"; import { ChangePermsAction } from "./changePerms"; import { CleanAction } from "./clean"; -import { DisableInvitesAction } from "./disableInvites"; import { KickAction } from "./kick"; import { LogAction } from "./log"; import { MuteAction } from "./mute"; +import { PauseInvitesAction } from "./pauseInvites"; import { RemoveRolesAction } from "./removeRoles"; import { ReplyAction } from "./reply"; import { SetAntiraidLevelAction } from "./setAntiraidLevel"; @@ -39,7 +39,7 @@ export const availableActions: Record> = { start_thread: StartThreadAction, archive_thread: ArchiveThreadAction, change_perms: ChangePermsAction, - disable_invites: DisableInvitesAction, + pause_invites: PauseInvitesAction, }; export const AvailableActions = t.type({ @@ -61,5 +61,5 @@ export const AvailableActions = t.type({ start_thread: StartThreadAction.configType, archive_thread: ArchiveThreadAction.configType, change_perms: ChangePermsAction.configType, - disable_invites: DisableInvitesAction.configType, + pause_invites: PauseInvitesAction.configType, }); diff --git a/backend/src/plugins/Automod/actions/disableInvites.ts b/backend/src/plugins/Automod/actions/pauseInvites.ts similarity index 81% rename from backend/src/plugins/Automod/actions/disableInvites.ts rename to backend/src/plugins/Automod/actions/pauseInvites.ts index af82a81cd..87d927ced 100644 --- a/backend/src/plugins/Automod/actions/disableInvites.ts +++ b/backend/src/plugins/Automod/actions/pauseInvites.ts @@ -1,7 +1,7 @@ import * as t from "io-ts"; import { automodAction } from "../helpers"; -export const DisableInvitesAction = automodAction({ +export const PauseInvitesAction = automodAction({ configType: t.boolean, defaultConfig: true, From 88abb7a9da43a6468d05d3330c77e692f00fe307 Mon Sep 17 00:00:00 2001 From: Ben Richeson Date: Wed, 30 Aug 2023 15:35:18 -0400 Subject: [PATCH 4/4] fix: make options an object, else setting an action to `false` ignores it --- backend/src/plugins/Automod/actions/pauseInvites.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/backend/src/plugins/Automod/actions/pauseInvites.ts b/backend/src/plugins/Automod/actions/pauseInvites.ts index 87d927ced..1bbea34fa 100644 --- a/backend/src/plugins/Automod/actions/pauseInvites.ts +++ b/backend/src/plugins/Automod/actions/pauseInvites.ts @@ -2,10 +2,13 @@ import * as t from "io-ts"; import { automodAction } from "../helpers"; export const PauseInvitesAction = automodAction({ - configType: t.boolean, - defaultConfig: true, + configType: t.type({ + paused: t.boolean, + }), + + defaultConfig: {}, async apply({ pluginData, actionConfig }) { - await pluginData.guild.disableInvites(actionConfig); + await pluginData.guild.disableInvites(actionConfig.paused); }, });