From 7a57e3eb456550dcc0f6e8866796544bc2e492d6 Mon Sep 17 00:00:00 2001 From: Dragory <2606411+Dragory@users.noreply.github.com> Date: Sun, 9 Jun 2019 19:24:00 +0300 Subject: [PATCH] Add support for multiple mentionRole values --- README.md | 2 +- src/utils.js | 13 +++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 7728c6f..19782b8 100644 --- a/README.md +++ b/README.md @@ -88,7 +88,7 @@ These go in `config.json`. See also `config.example.json`. |ignoreAccidentalThreads|false|If set to true, the bot attempts to ignore common "accidental" messages that would start a new thread, such as "ok", "thanks", etc.| |inboxServerPermission|None|Permission required to use bot commands on the inbox server| |timeOnServerDeniedMessage|"You haven't been a member of the server for long enough to contact modmail."|See `requiredTimeOnServer` below| -|mentionRole|"here"|Role that is mentioned when new threads are created or the bot is mentioned. Accepted values are "here", "everyone", or a role id as a string. Set to null to disable these pings entirely.| +|mentionRole|"here"|Role that is mentioned when new threads are created or the bot is mentioned. Accepted values are "here", "everyone", or a role id as a string. Set to null to disable these pings entirely. Multiple values in an array are supported.| |mentionUserInThreadHeader|false|If set to true, mentions the thread's user in the thread header| |newThreadCategoryId|None|ID of the category where new modmail thread channels should be placed| |pingOnBotMention|true|If enabled, the bot will mention staff (see mentionRole above) on the inbox server when the bot is mentioned on the main server.| diff --git a/src/utils.js b/src/utils.js index 3b93ce8..52c21c0 100644 --- a/src/utils.js +++ b/src/utils.js @@ -250,10 +250,15 @@ function convertDelayStringToMS(str) { } function getInboxMention() { - if (config.mentionRole == null) return ''; - else if (config.mentionRole === 'here') return '@here '; - else if (config.mentionRole === 'everyone') return '@everyone '; - else return `<@&${config.mentionRole}> `; + const mentionRoles = Array.isArray(config.mentionRole) ? config.mentionRole : [config.mentionRole]; + const mentions = []; + for (const role of mentionRoles) { + if (role == null) continue; + else if (role === 'here') mentions.push('@here'); + else if (role === 'everyone') mentions.push('@everyone'); + else mentions.push(`<@&${role}>`); + } + return mentions.join(' ') + ' '; } function postSystemMessageWithFallback(channel, thread, text) {