Enforce unified lock names by using functions to generate lock keys (#165)

This commit is contained in:
Nils 2021-04-02 15:43:13 +02:00 committed by GitHub
parent fcbb25b7ff
commit c5d68650a3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
18 changed files with 70 additions and 28 deletions

View file

@ -10,6 +10,7 @@ import { BOT_SLOWMODE_PERMISSIONS } from "../requiredPermissions";
import { LogsPlugin } from "../../Logs/LogsPlugin";
import { LogType } from "../../../data/LogType";
import { missingPermissionError } from "../../../utils/missingPermissionError";
import { messageLock } from "../../../utils/lockNameHelpers";
export async function onMessageCreate(pluginData: GuildPluginData<SlowmodePluginType>, msg: SavedMessage) {
if (msg.is_bot) return;
@ -18,7 +19,7 @@ export async function onMessageCreate(pluginData: GuildPluginData<SlowmodePlugin
if (!channel) return;
// Don't apply slowmode if the lock was interrupted earlier (e.g. the message was caught by word filters)
const thisMsgLock = await pluginData.locks.acquire(`message-${msg.id}`);
const thisMsgLock = await pluginData.locks.acquire(messageLock(msg));
if (thisMsgLock.interrupted) return;
// Check if this channel even *has* a bot-maintained slowmode