Auto-close threads if their inbox server channel is deleted

master
Dragory 2018-03-11 22:15:16 +02:00
parent c3b702d7a7
commit 32260fd22c
2 changed files with 20 additions and 0 deletions

View File

@ -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"`)

View File

@ -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) => {