From 6a7a7922d720df0a2514961ea71b16a06a886482 Mon Sep 17 00:00:00 2001 From: seeyebe Date: Fri, 26 Jun 2026 15:13:48 +0300 Subject: [PATCH] feat: ignore accidental scheduled close replies --- docs/configuration.md | 4 ++++ src/data/Thread.js | 4 ++-- src/data/cfg.jsdoc.js | 1 + src/data/cfg.schema.json | 4 ++++ src/data/constants.js | 11 +++++++++++ src/main.js | 4 ++-- 6 files changed, 24 insertions(+), 4 deletions(-) diff --git a/docs/configuration.md b/docs/configuration.md index 4b62e5f6..0802578b 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -250,6 +250,10 @@ Alias for [`serverGreetings`](#serverGreetings) **Default:** `off` If enabled, the bot attempts to ignore common "accidental" messages that would start a new thread, such as "ok", "thanks", etc. +#### ignoreAccidentalScheduledCloseReplies +**Default:** `off` +If enabled, common "accidental" replies such as "ok" or "thanks" will not cancel a scheduled thread close. + #### inboxServerPermission **Default:** `manageMessages` **Accepts multiple values.** Permission name, user id, or role id required to use bot commands on the inbox server. diff --git a/src/data/Thread.js b/src/data/Thread.js index ac466e07..4817ac17 100644 --- a/src/data/Thread.js +++ b/src/data/Thread.js @@ -18,7 +18,7 @@ const { getModeratorThreadDisplayRoleName } = require("./displayRoles"); const ThreadMessage = require("./ThreadMessage"); -const {THREAD_MESSAGE_TYPE, THREAD_STATUS, DISCORD_MESSAGE_ACTIVITY_TYPES} = require("./constants"); +const {THREAD_MESSAGE_TYPE, THREAD_STATUS, DISCORD_MESSAGE_ACTIVITY_TYPES, shouldIgnoreAccidentalThreadMessage} = require("./constants"); const {isBlocked} = require("./blocked"); const {messageContentToAdvancedMessageContent} = require("../utils"); @@ -587,7 +587,7 @@ class Thread { }); // Interrupt scheduled closing, if in progress - if (this.scheduled_close_at) { + if (this.scheduled_close_at && (! config.ignoreAccidentalScheduledCloseReplies || ! shouldIgnoreAccidentalThreadMessage(msg.content))) { await this.cancelScheduledClose(); await this.postSystemMessage(`<@!${this.scheduled_close_id}> Thread that was scheduled to be closed got a new reply. Cancelling.`, { allowedMentions: { diff --git a/src/data/cfg.jsdoc.js b/src/data/cfg.jsdoc.js index b97bf77d..cfa1369b 100644 --- a/src/data/cfg.jsdoc.js +++ b/src/data/cfg.jsdoc.js @@ -27,6 +27,7 @@ * @property {boolean} [useDisplaynames=true] * @property {boolean} [anonymizeChannelName=false] * @property {boolean} [ignoreAccidentalThreads=false] + * @property {boolean} [ignoreAccidentalScheduledCloseReplies=false] * @property {boolean} [threadTimestamps=false] * @property {boolean} [allowMove=false] * @property {boolean} [syncPermissionsOnMove=true] diff --git a/src/data/cfg.schema.json b/src/data/cfg.schema.json index e7aebc59..06625580 100644 --- a/src/data/cfg.schema.json +++ b/src/data/cfg.schema.json @@ -149,6 +149,10 @@ "$ref": "#/definitions/customBoolean", "default": false }, + "ignoreAccidentalScheduledCloseReplies": { + "$ref": "#/definitions/customBoolean", + "default": false + }, "threadTimestamps": { "$ref": "#/definitions/customBoolean", "default": false diff --git a/src/data/constants.js b/src/data/constants.js index 886313ff..2b5bca33 100644 --- a/src/data/constants.js +++ b/src/data/constants.js @@ -1,3 +1,12 @@ +function shouldIgnoreAccidentalThreadMessage(str) { + const normalizedMessage = (str || "") + .trim() + .toLowerCase() + .replace(/[!?.]+$/g, ""); + + return module.exports.ACCIDENTAL_THREAD_MESSAGES.includes(normalizedMessage); +} + module.exports = { THREAD_STATUS: { OPEN: 1, @@ -74,4 +83,6 @@ module.exports = { "okey np", "cheers" ], + + shouldIgnoreAccidentalThreadMessage, }; diff --git a/src/main.js b/src/main.js index 41da3cfd..bb460428 100644 --- a/src/main.js +++ b/src/main.js @@ -15,7 +15,7 @@ const blocked = require("./data/blocked"); const threads = require("./data/threads"); const updates = require("./data/updates"); -const { ACCIDENTAL_THREAD_MESSAGES } = require("./data/constants"); +const { shouldIgnoreAccidentalThreadMessage } = require("./data/constants"); const {getOrFetchChannel} = require("./utils"); module.exports = { @@ -183,7 +183,7 @@ function initBaseMessageHandlers() { // New thread if (createNewThread) { // Ignore messages that shouldn't usually open new threads, such as "ok", "thanks", etc. - if (config.ignoreAccidentalThreads && msg.content && ACCIDENTAL_THREAD_MESSAGES.includes(msg.content.trim().toLowerCase())) return; + if (config.ignoreAccidentalThreads && shouldIgnoreAccidentalThreadMessage(msg.content)) return; thread = await threads.createNewThreadForUser(msg.author, { source: "dm",