Send response message after creating thread

This way the response message is shown in the right order
in the created thread.
cshd
Dragory 2020-10-25 04:27:12 +02:00
parent 4663886629
commit 012a819242
No known key found for this signature in database
GPG Key ID: 5F387BA66DF8AAC1
2 changed files with 15 additions and 17 deletions

View File

@ -198,17 +198,6 @@ async function createNewThreadForUser(user, opts = {}) {
allowedMentions: utils.getInboxMentionAllowedMentions(), 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 // 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 the thread
return newThread; return newThread;
} }

View File

@ -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 // Private message handling is queued so e.g. multiple message in quick succession don't result in multiple channels being created
messageQueue.add(async () => { messageQueue.add(async () => {
let thread = await threads.findOpenThreadByUserId(msg.author.id); let thread = await threads.findOpenThreadByUserId(msg.author.id);
const createNewThread = (thread == null);
// New thread // New thread
if (! thread) { if (createNewThread) {
// Ignore messages that shouldn't usually open new threads, such as "ok", "thanks", etc. // 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 && msg.content && ACCIDENTAL_THREAD_MESSAGES.includes(msg.content.trim().toLowerCase())) return;
@ -161,6 +162,19 @@ function initBaseMessageHandlers() {
if (thread) { if (thread) {
await thread.receiveUserReply(msg); 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}\``);
}
}
}
} }
}); });
}); });