diff --git a/CHANGELOG.md b/CHANGELOG.md index 1623a9e..443ffe8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Changelog +## v2.3.2 +* Auto-close threads if their modmail channel is deleted + ## v2.3.1 * Fixed incorrect default value for `mentionRole` (was `null`, should've been `"here"`) diff --git a/src/main.js b/src/main.js index f70d7f7..1714d24 100644 --- a/src/main.js +++ b/src/main.js @@ -200,6 +200,23 @@ async function closeLoop() { closeLoop(); +// Auto-close threads if their channel is deleted +bot.on('channelDelete', async (channel) => { + if (! (channel instanceof Eris.TextChannel)) return; + if (channel.guild.id !== utils.getInboxGuild().id) return; + const thread = await threads.findOpenThreadByChannelId(channel.id); + if (! thread) return; + + console.log(`[INFO] Auto-closing thread with ${thread.user_name} because the channel was deleted`); + await thread.close(true); + + const logUrl = await thread.getLogUrl(); + utils.postLog(utils.trimAll(` + Modmail thread with ${thread.user_name} (${thread.user_id}) was closed automatically because the channel was deleted + Logs: ${logUrl} + `)); +}); + // Mods can reply to modmail threads using !r or !reply // These messages get relayed back to the DM thread between the bot and the user addInboxServerCommand('reply', async (msg, args, thread) => {