diff --git a/backend/src/plugins/Slowmode/SlowmodePlugin.ts b/backend/src/plugins/Slowmode/SlowmodePlugin.ts index 8bdc76e2..abd0d884 100644 --- a/backend/src/plugins/Slowmode/SlowmodePlugin.ts +++ b/backend/src/plugins/Slowmode/SlowmodePlugin.ts @@ -42,7 +42,11 @@ export const SlowmodePlugin = zeppelinGuildPlugin()({ prettyName: "Slowmode", }, - dependencies: () => [LogsPlugin], + // prettier-ignore + dependencies: () => [ + LogsPlugin, + ], + configSchema: ConfigSchema, defaultOptions, @@ -61,6 +65,7 @@ export const SlowmodePlugin = zeppelinGuildPlugin()({ state.slowmodes = GuildSlowmodes.getGuildInstance(guild.id); state.savedMessages = GuildSavedMessages.getGuildInstance(guild.id); state.logs = new GuildLogs(guild.id); + state.channelSlowmodeCache = new Map(); }, afterLoad(pluginData) { diff --git a/backend/src/plugins/Slowmode/commands/SlowmodeSetCmd.ts b/backend/src/plugins/Slowmode/commands/SlowmodeSetCmd.ts index 3b316c6f..192c2f43 100644 --- a/backend/src/plugins/Slowmode/commands/SlowmodeSetCmd.ts +++ b/backend/src/plugins/Slowmode/commands/SlowmodeSetCmd.ts @@ -144,7 +144,12 @@ export const SlowmodeSetCmd = slowmodeCmd({ }); } + // Set bot-maintained slowmode await pluginData.state.slowmodes.setChannelSlowmode(channel.id, rateLimitSeconds); + + // Update cache + const slowmode = await pluginData.state.slowmodes.getChannelSlowmode(channel.id); + await pluginData.state.channelSlowmodeCache.set(channel.id, slowmode ?? null); } const humanizedSlowmodeTime = humanizeDuration(args.time); diff --git a/backend/src/plugins/Slowmode/types.ts b/backend/src/plugins/Slowmode/types.ts index 7679df34..21f0de69 100644 --- a/backend/src/plugins/Slowmode/types.ts +++ b/backend/src/plugins/Slowmode/types.ts @@ -3,6 +3,7 @@ import { BasePluginType, typedGuildCommand, typedGuildEventListener } from "knub import { GuildLogs } from "../../data/GuildLogs"; import { GuildSavedMessages } from "../../data/GuildSavedMessages"; import { GuildSlowmodes } from "../../data/GuildSlowmodes"; +import { SlowmodeChannel } from "../../data/entities/SlowmodeChannel"; export const ConfigSchema = t.type({ use_native_slowmode: t.boolean, @@ -20,6 +21,7 @@ export interface SlowmodePluginType extends BasePluginType { logs: GuildLogs; clearInterval: NodeJS.Timeout; serverLogs: GuildLogs; + channelSlowmodeCache: Map; onMessageCreateFn; }; diff --git a/backend/src/plugins/Slowmode/util/disableBotSlowmodeForChannel.ts b/backend/src/plugins/Slowmode/util/disableBotSlowmodeForChannel.ts index 43d6cb55..7b273c1a 100644 --- a/backend/src/plugins/Slowmode/util/disableBotSlowmodeForChannel.ts +++ b/backend/src/plugins/Slowmode/util/disableBotSlowmodeForChannel.ts @@ -24,5 +24,8 @@ export async function disableBotSlowmodeForChannel( } } + // Clear cache + pluginData.state.channelSlowmodeCache.set(channel.id, null); + return { failedUsers }; } diff --git a/backend/src/plugins/Slowmode/util/onMessageCreate.ts b/backend/src/plugins/Slowmode/util/onMessageCreate.ts index 2af5a9bf..cfe1af95 100644 --- a/backend/src/plugins/Slowmode/util/onMessageCreate.ts +++ b/backend/src/plugins/Slowmode/util/onMessageCreate.ts @@ -10,6 +10,7 @@ import { LogsPlugin } from "../../Logs/LogsPlugin"; import { BOT_SLOWMODE_PERMISSIONS } from "../requiredPermissions"; import { SlowmodePluginType } from "../types"; import { applyBotSlowmodeToUserId } from "./applyBotSlowmodeToUserId"; +import { SlowmodeChannel } from "../../../data/entities/SlowmodeChannel"; export async function onMessageCreate(pluginData: GuildPluginData, msg: SavedMessage) { if (msg.is_bot) return; @@ -22,8 +23,16 @@ export async function onMessageCreate(pluginData: GuildPluginData