diff --git a/docs/configuration.md b/docs/configuration.md index a715be3..39d4299 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -133,6 +133,15 @@ Controls how attachments in modmail threads are stored. Possible values: **Default:** *None* When using attachmentStorage is set to "discord", the id of the channel on the inbox server where attachments are saved +#### autoAlert +**Default:** `off` +When enabled, the last moderator to reply to a modmail thread will be automatically alerted when the thread gets a new reply. +This alert kicks in after a delay, set by the `autoAlertDelay` option below. + +#### autoAlertDelay +**Default:** `2m` +The delay after which `autoAlert` kicks in. Uses the same format as timed close; for example `1m30s` for 1 minute and 30 seconds. + #### botMentionResponse **Default:** *None* If set, the bot auto-replies to bot mentions (pings) with this message. Use `{userMention}` in the text to ping the user back. diff --git a/src/data/Thread.js b/src/data/Thread.js index 00e775a..ef0ecc8 100644 --- a/src/data/Thread.js +++ b/src/data/Thread.js @@ -169,6 +169,7 @@ class Thread { /** * @returns {Promise} + * @private */ async _getAndIncrementNextMessageNumber() { return knex.transaction(async trx => { @@ -186,6 +187,21 @@ class Thread { }); } + /** + * Adds the specified moderator to the thread's alert list after config.autoAlertDelay + * @param {string} modId + * @returns {Promise} + * @private + */ + async _startAutoAlertTimer(modId) { + clearTimeout(this._autoAlertTimeout); + const autoAlertDelay = utils.convertDelayStringToMS(config.autoAlertDelay); + this._autoAlertTimeout = setTimeout(() => { + if (this.status !== THREAD_STATUS.OPEN) return; + this.addAlert(modId); + }, autoAlertDelay); + } + /** * @param {Eris.Member} moderator * @param {string} text @@ -296,6 +312,11 @@ class Thread { await this.postSystemMessage("Cancelling scheduled closing of this thread due to new reply"); } + // If enabled, set up a reply alert for the moderator after a slight delay + if (config.autoAlert) { + this._startAutoAlertTimer(moderator.id); + } + return true; } diff --git a/src/data/cfg.jsdoc.js b/src/data/cfg.jsdoc.js index 4431a30..f743562 100644 --- a/src/data/cfg.jsdoc.js +++ b/src/data/cfg.jsdoc.js @@ -62,6 +62,8 @@ * @property {boolean} [errorOnUnknownInlineSnippet=true] * @property {boolean} [allowChangingDisplayRole=true] * @property {string} [fallbackRoleName=null] + * @property {boolean} [autoAlert=false] + * @property {string} [autoAlertDelay="2m"] Delay before auto-alert kicks in. Uses the same format as timed close; for example 1m30s for 1 minute and 30 seconds. * @property {string} [logStorage="local"] * @property {object} [logOptions] * @property {string} logOptions.attachmentDirectory diff --git a/src/data/cfg.schema.json b/src/data/cfg.schema.json index e490195..6d2bc30 100644 --- a/src/data/cfg.schema.json +++ b/src/data/cfg.schema.json @@ -346,6 +346,17 @@ "default": null }, + "autoAlert": { + "$ref": "#/definitions/customBoolean", + "default": false + }, + + "autoAlertDelay": { + "type": "string", + "default": "2m", + "description": "Delay before auto-alert kicks in. Uses the same format as timed close; for example 1m30s for 1 minute and 30 seconds." + }, + "logStorage": { "type": "string", "default": "local" diff --git a/src/modules/reply.js b/src/modules/reply.js index 17b5678..31ca967 100644 --- a/src/modules/reply.js +++ b/src/modules/reply.js @@ -1,6 +1,5 @@ const attachments = require("../data/attachments"); const utils = require("../utils"); -const config = require("../cfg"); const Thread = require("../data/Thread"); module.exports = ({ bot, knex, config, commands }) => {