From e0bd96e9596bd57c1e2c2e4619340f4c34434d03 Mon Sep 17 00:00:00 2001 From: Dragory Date: Sun, 18 Feb 2018 21:21:03 +0200 Subject: [PATCH] Logs are posted in the log channel again --- src/main.js | 8 +++++++- src/utils.js | 14 ++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/main.js b/src/main.js index 576b0a2..48021b8 100644 --- a/src/main.js +++ b/src/main.js @@ -163,7 +163,13 @@ bot.registerCommandAlias('ar', 'anonreply'); // Close a thread. Closing a thread saves a log of the channel's contents and then deletes the channel. addInboxServerCommand('close', async (msg, args, thread) => { if (! thread) return; - thread.close(); + await thread.close(); + + const logUrl = await thread.getLogUrl(); + utils.postLog(utils.trimAll(` + Modmail thread with ${thread.user_name} (${thread.user_id}) was closed by ${msg.author.username} + Logs: ${logUrl} + `)); }); addInboxServerCommand('block', (msg, args, thread) => { diff --git a/src/utils.js b/src/utils.js index ea3a08c..cdbdd1a 100644 --- a/src/utils.js +++ b/src/utils.js @@ -52,6 +52,10 @@ function getLogChannel() { return logChannel; } +function postLog(...args) { + getLogChannel().createMessage(...args); +} + function postError(str) { getLogChannel().createMessage({ content: `@here **Error:** ${str.trim()}`, @@ -182,6 +186,13 @@ function chunk(items, chunkSize) { return result; } +function trimAll(str) { + return str + .split('\n') + .map(str => str.trim()) + .join('\n'); +} + module.exports = { BotError, @@ -189,6 +200,7 @@ module.exports = { getMainGuild, getLogChannel, postError, + postLog, isStaff, messageIsOnInboxServer, @@ -201,5 +213,7 @@ module.exports = { disableLinkPreviews, getSelfUrl, getMainRole, + chunk, + trimAll, };