Skip to content
Open
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
4 changes: 4 additions & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions src/data/Thread.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down Expand Up @@ -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: {
Expand Down
1 change: 1 addition & 0 deletions src/data/cfg.jsdoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
4 changes: 4 additions & 0 deletions src/data/cfg.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,10 @@
"$ref": "#/definitions/customBoolean",
"default": false
},
"ignoreAccidentalScheduledCloseReplies": {
"$ref": "#/definitions/customBoolean",
"default": false
},
"threadTimestamps": {
"$ref": "#/definitions/customBoolean",
"default": false
Expand Down
11 changes: 11 additions & 0 deletions src/data/constants.js
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -74,4 +83,6 @@ module.exports = {
"okey np",
"cheers"
],

shouldIgnoreAccidentalThreadMessage,
};
4 changes: 2 additions & 2 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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",
Expand Down