From adce3e0cbbefea950fa9d8b4c373fd35e90a4ad1 Mon Sep 17 00:00:00 2001 From: Dragory Date: Sun, 18 Feb 2018 23:29:24 +0200 Subject: [PATCH] Fix missing here ping on new threads. Add threadTimestamps option to revert removal of thread timestamps. --- README.md | 1 + src/config.js | 1 + src/data/Thread.js | 25 +++++++++++++++++-------- src/data/threads.js | 6 ++++++ src/utils.js | 5 ++--- 5 files changed, 27 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index cc1d8a7..7ac3ae2 100644 --- a/README.md +++ b/README.md @@ -67,3 +67,4 @@ These go in `config.json`. See also `config.example.json`. |logChannelId|Server's default channel|Channel where to post links to closed threads and other alerts| |newThreadCategoryId|None|ID of the category where new modmail thread channels should be placed| |relaySmallAttachmentsAsAttachments|false|Whether to relay small (<2MB) attachments from users as attachments rather than links in modmail threads| +|threadTimestamps|false|Whether to show custom timestamps in threads, in addition to Discord's own timestamps. Logs always have accurate timestamps, regardless of this setting.| diff --git a/src/config.js b/src/config.js index d4d8b95..85535b2 100644 --- a/src/config.js +++ b/src/config.js @@ -27,6 +27,7 @@ const defaultConfig = { "alwaysReplyAnon": false, "useNicknames": false, "ignoreAccidentalThreads": false, + "threadTimestamps": false, "enableGreeting": false, "greetingMessage": null, diff --git a/src/data/Thread.js b/src/data/Thread.js index 0240567..f409a7a 100644 --- a/src/data/Thread.js +++ b/src/data/Thread.js @@ -47,14 +47,18 @@ class Thread { } // Build the reply message - const timestamp = utils.getTimestamp(); let dmContent = `**${modUsername}:** ${text}`; let threadContent = `**${logModUsername}:** ${text}`; let logContent = text; - let files = []; + if (config.threadTimestamps) { + const timestamp = utils.getTimestamp(); + threadContent = `[${timestamp}] » ${threadContent}`; + } // Prepare attachments, if any + let files = []; + if (replyAttachments.length > 0) { for (const attachment of replyAttachments) { files.push(await attachments.attachmentToFile(attachment)); @@ -99,6 +103,13 @@ class Thread { let threadContent = `**${msg.author.username}#${msg.author.discriminator}:** ${content}`; let logContent = msg.content; + + if (config.threadTimestamps) { + const timestamp = utils.getTimestamp(msg.timestamp, 'x'); + threadContent = `[${timestamp}] « ${threadContent}`; + } + + // Prepare attachments, if any let attachmentFiles = []; for (const attachment of msg.attachments) { @@ -145,13 +156,11 @@ class Thread { } /** - * @param {String} text - * @param {Eris~MessageFile|Eris~MessageFile[]} file * @returns {Promise} */ - async postToThreadChannel(text, file = null) { + async postToThreadChannel(...args) { try { - return await bot.createMessage(this.channel_id, text, file); + return await bot.createMessage(this.channel_id, ...args); } catch (e) { // Channel not found if (e.code === 10003) { @@ -183,8 +192,8 @@ class Thread { * @param {String} text * @returns {Promise} */ - async postNonLogMessage(text) { - await this.postToThreadChannel(text); + async postNonLogMessage(...args) { + await this.postToThreadChannel(...args); } /** diff --git a/src/data/threads.js b/src/data/threads.js index 9e4d513..47b7c4f 100644 --- a/src/data/threads.js +++ b/src/data/threads.js @@ -79,6 +79,12 @@ async function createNewThreadForUser(user) { const newThread = await findById(newThreadId); + // Ping moderators of the new thread + await newThread.postNonLogMessage({ + content: `@here New modmail thread (${newThread.user_name})`, + disableEveryone: false + }); + // Post the log link to the beginning (but don't save it in thread messages) const logUrl = await newThread.getLogUrl(); await newThread.postNonLogMessage(`Log URL: <${logUrl}>`); diff --git a/src/utils.js b/src/utils.js index cdbdd1a..80fb790 100644 --- a/src/utils.js +++ b/src/utils.js @@ -128,11 +128,10 @@ function getUserMention(str) { /** * Returns the current timestamp in an easily readable form - * @param {String|Date|undefined} date * @returns {String} */ -function getTimestamp(date) { - return moment.utc(date).format('HH:mm'); +function getTimestamp(...momentArgs) { + return moment.utc(...momentArgs).format('HH:mm'); } /**