From fa84fa603407a0145e3454e023e3df24db1fc111 Mon Sep 17 00:00:00 2001 From: Dragory <2606411+Dragory@users.noreply.github.com> Date: Tue, 27 Oct 2020 18:27:30 +0200 Subject: [PATCH] Fix thread channel being deleted before the close message is sent --- src/modules/close.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/modules/close.js b/src/modules/close.js index 196ba7e..5e20e8e 100644 --- a/src/modules/close.js +++ b/src/modules/close.js @@ -66,6 +66,7 @@ module.exports = ({ bot, knex, config, commands }) => { let hasCloseMessage = !! config.closeMessage; let silentClose = false; + let suppressSystemMessages = false; if (msg.channel instanceof Eris.PrivateChannel) { // User is closing the thread by themselves (if enabled) @@ -79,7 +80,7 @@ module.exports = ({ bot, knex, config, commands }) => { // between showing the close command in the thread and closing the thread await messageQueue.add(async () => { thread.postSystemMessage("Thread closed by user, closing..."); - await thread.close(true); + suppressSystemMessages = true; }); closedBy = "the user"; @@ -133,7 +134,6 @@ module.exports = ({ bot, knex, config, commands }) => { } // Regular close - await thread.close(false, silentClose); closedBy = msg.author.username; } @@ -143,6 +143,8 @@ module.exports = ({ bot, knex, config, commands }) => { await thread.sendSystemMessageToUser(closeMessage).catch(() => {}); } + await thread.close(suppressSystemMessages, silentClose); + await sendCloseNotification(thread, `Modmail thread with ${thread.user_name} (${thread.user_id}) was closed by ${closedBy}`); });