Add autoAlert/autoAlertDelay options

cshd
Dragory 2020-11-01 22:51:05 +02:00
parent 53dc6edb6a
commit dd4640bfff
No known key found for this signature in database
GPG Key ID: 5F387BA66DF8AAC1
5 changed files with 43 additions and 1 deletions

View File

@ -133,6 +133,15 @@ Controls how attachments in modmail threads are stored. Possible values:
**Default:** *None* **Default:** *None*
When using attachmentStorage is set to "discord", the id of the channel on the inbox server where attachments are saved 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 #### botMentionResponse
**Default:** *None* **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. If set, the bot auto-replies to bot mentions (pings) with this message. Use `{userMention}` in the text to ping the user back.

View File

@ -169,6 +169,7 @@ class Thread {
/** /**
* @returns {Promise<Number>} * @returns {Promise<Number>}
* @private
*/ */
async _getAndIncrementNextMessageNumber() { async _getAndIncrementNextMessageNumber() {
return knex.transaction(async trx => { 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<void>}
* @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 {Eris.Member} moderator
* @param {string} text * @param {string} text
@ -296,6 +312,11 @@ class Thread {
await this.postSystemMessage("Cancelling scheduled closing of this thread due to new reply"); 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; return true;
} }

View File

@ -62,6 +62,8 @@
* @property {boolean} [errorOnUnknownInlineSnippet=true] * @property {boolean} [errorOnUnknownInlineSnippet=true]
* @property {boolean} [allowChangingDisplayRole=true] * @property {boolean} [allowChangingDisplayRole=true]
* @property {string} [fallbackRoleName=null] * @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 {string} [logStorage="local"]
* @property {object} [logOptions] * @property {object} [logOptions]
* @property {string} logOptions.attachmentDirectory * @property {string} logOptions.attachmentDirectory

View File

@ -346,6 +346,17 @@
"default": null "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": { "logStorage": {
"type": "string", "type": "string",
"default": "local" "default": "local"

View File

@ -1,6 +1,5 @@
const attachments = require("../data/attachments"); const attachments = require("../data/attachments");
const utils = require("../utils"); const utils = require("../utils");
const config = require("../cfg");
const Thread = require("../data/Thread"); const Thread = require("../data/Thread");
module.exports = ({ bot, knex, config, commands }) => { module.exports = ({ bot, knex, config, commands }) => {