From eea6a1c2b788126bde6839828406c11d2e92c851 Mon Sep 17 00:00:00 2001 From: Liam Date: Thu, 5 Nov 2020 16:32:43 +0000 Subject: [PATCH] Add allowBlock, allowSuspend, and allowSnippets as configuration options (#498) Co-authored-by: Miikka <2606411+Dragory@users.noreply.github.com> --- docs/configuration.md | 18 +++++++++++++++--- src/data/Thread.js | 2 +- src/data/cfg.jsdoc.js | 3 +++ src/data/cfg.schema.json | 13 ++++++++++++- src/modules/block.js | 1 + src/modules/snippets.js | 1 + src/modules/suspend.js | 1 + 7 files changed, 34 insertions(+), 5 deletions(-) diff --git a/docs/configuration.md b/docs/configuration.md index 9a774ca..86d73cc 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -97,17 +97,29 @@ If enabled, staff members can delete their own replies in modmail threads with ` **Default:** `on` If enabled, staff members can edit their own replies in modmail threads with `!edit` +#### allowBlock +**Default:** `on` +If enabled, staff members can block a user from using modmail with `!block` + +#### allowSuspend +**Default:** `on` +If enabled, staff members can suspend a user from using modmail with `!suspend` + +#### allowSnippets +**Default:** `on` +If enabled, staff members can use [Snippets](snippets.md) + #### allowInlineSnippets **Default:** `on` -If enabled, snippets can be included *within* replies by wrapping the snippet's name in {{ and }}. +If `allowSnippets` is enabled, this option controls whether the snippets can be included *within* replies by wrapping the snippet's name in {{ and }}. E.g. `!r Hello! {{rules}}` +See [inlineSnippetStart](#inlineSnippetStart) and [inlineSnippetEnd](#inlineSnippetEnd) to customize the symbols used. + #### allowChangingDisplayRole **Default:** `on` If enabled, moderators can change the role that's shown with their replies to any role they currently have using the `!role` command. -See [inlineSnippetStart](#inlineSnippetStart) and [inlineSnippetEnd](#inlineSnippetEnd) to customize the symbols used. - #### alwaysReply **Default:** `off` If enabled, all messages in modmail threads will be sent to the user without having to use `!r`. diff --git a/src/data/Thread.js b/src/data/Thread.js index dd95b95..54bbce9 100644 --- a/src/data/Thread.js +++ b/src/data/Thread.js @@ -215,7 +215,7 @@ class Thread { const moderatorName = config.useNicknames && moderator.nick ? moderator.nick : moderator.user.username; const roleName = await getModeratorThreadDisplayRoleName(moderator, this.id); - if (config.allowInlineSnippets) { + if (config.allowSnippets && config.allowInlineSnippets) { // Replace {{snippet}} with the corresponding snippet // The beginning and end of the variable - {{ and }} - can be changed with the config options // config.inlineSnippetStart and config.inlineSnippetEnd diff --git a/src/data/cfg.jsdoc.js b/src/data/cfg.jsdoc.js index e3fd3bf..a2f1fc9 100644 --- a/src/data/cfg.jsdoc.js +++ b/src/data/cfg.jsdoc.js @@ -33,6 +33,9 @@ * @property {boolean} [rolesInThreadHeader=false] * @property {boolean} [allowStaffEdit=true] * @property {boolean} [allowStaffDelete=true] + * @property {boolean} [allowBlock=true] + * @property {boolean} [allowSuspend=true] + * @property {boolean} [allowSnippets=true] * @property {boolean} [enableGreeting=false] * @property {string} [greetingMessage] * @property {string} [greetingAttachment] diff --git a/src/data/cfg.schema.json b/src/data/cfg.schema.json index 766671e..92b5b93 100644 --- a/src/data/cfg.schema.json +++ b/src/data/cfg.schema.json @@ -173,7 +173,18 @@ "$ref": "#/definitions/customBoolean", "default": true }, - + "allowBlock": { + "$ref": "#/definitions/customBoolean", + "default": true + }, + "allowSuspend": { + "$ref": "#/definitions/customBoolean", + "default": true + }, + "allowSnippets": { + "$ref": "#/definitions/customBoolean", + "default": true + }, "enableGreeting": { "$ref": "#/definitions/customBoolean", "default": false diff --git a/src/modules/block.js b/src/modules/block.js index 252be93..348dd5a 100644 --- a/src/modules/block.js +++ b/src/modules/block.js @@ -4,6 +4,7 @@ const blocked = require("../data/blocked"); const utils = require("../utils"); module.exports = ({ bot, knex, config, commands }) => { + if (! config.allowBlock) return; async function removeExpiredBlocks() { const expiredBlocks = await blocked.getExpiredBlocks(); const logChannel = utils.getLogChannel(); diff --git a/src/modules/snippets.js b/src/modules/snippets.js index 1c7a45e..94e8c8e 100644 --- a/src/modules/snippets.js +++ b/src/modules/snippets.js @@ -7,6 +7,7 @@ const whitespaceRegex = /\s/; const quoteChars = ["'", "\""]; module.exports = ({ bot, knex, config, commands }) => { + if (! config.allowSnippets) return; /** * "Renders" a snippet by replacing all argument placeholders e.g. {1} {2} with their corresponding arguments. * The number in the placeholder is the argument's order in the argument list, i.e. {1} is the first argument (= index 0) diff --git a/src/modules/suspend.js b/src/modules/suspend.js index bddb756..6ccc305 100644 --- a/src/modules/suspend.js +++ b/src/modules/suspend.js @@ -6,6 +6,7 @@ const config = require("../cfg"); const {THREAD_STATUS} = require("../data/constants"); module.exports = ({ bot, knex, config, commands }) => { + if (! config.allowSuspend) return; // Check for threads that are scheduled to be suspended and suspend them async function applyScheduledSuspensions() { const threadsToBeSuspended = await threads.getThreadsThatShouldBeSuspended();