diff --git a/src/data/threads.js b/src/data/threads.js index c4429d6..240fd12 100644 --- a/src/data/threads.js +++ b/src/data/threads.js @@ -198,17 +198,6 @@ async function createNewThreadForUser(user, opts = {}) { allowedMentions: utils.getInboxMentionAllowedMentions(), }); } - - // Send auto-reply to the user - if (config.responseMessage) { - const responseMessage = utils.readMultilineConfigValue(config.responseMessage); - - try { - await newThread.sendSystemMessageToUser(responseMessage); - } catch (err) { - responseMessageError = err; - } - } } // Post some info to the beginning of the new thread @@ -276,11 +265,6 @@ async function createNewThreadForUser(user, opts = {}) { } } - // If there were errors sending a response to the user, note that - if (responseMessageError) { - await newThread.postSystemMessage(`**NOTE:** Could not send auto-response to the user. The error given was: \`${responseMessageError.message}\``); - } - // Return the thread return newThread; } diff --git a/src/main.js b/src/main.js index 384b02a..788d0ef 100644 --- a/src/main.js +++ b/src/main.js @@ -147,9 +147,10 @@ function initBaseMessageHandlers() { // Private message handling is queued so e.g. multiple message in quick succession don't result in multiple channels being created messageQueue.add(async () => { let thread = await threads.findOpenThreadByUserId(msg.author.id); + const createNewThread = (thread == null); // New thread - if (! 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; @@ -161,6 +162,19 @@ function initBaseMessageHandlers() { if (thread) { await thread.receiveUserReply(msg); + + if (createNewThread) { + // Send auto-reply to the user + if (config.responseMessage) { + const responseMessage = utils.readMultilineConfigValue(config.responseMessage); + + try { + await thread.sendSystemMessageToUser(responseMessage); + } catch (err) { + await thread.postSystemMessage(`**NOTE:** Could not send auto-response to the user. The error given was: \`${err.message}\``); + } + } + } } }); });