diff --git a/CHANGELOG.md b/CHANGELOG.md index bb64b87..fd13ba7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Changelog +## v2.3.0 +* Added `mentionRole` configuration option ([#59](https://github.com/Dragory/modmailbot/pull/59)). This option can be used to set the role that is pinged when new threads are created or the bot is mentioned. See README for more details. + ## v2.2.0 * Added the ability to schedule a thread to close by specifying a time after `!close`, e.g. `!close 1h`. The scheduling is cancelled if a new message is sent to or received from the user. diff --git a/README.md b/README.md index c01ab2d..9eb0d75 100644 --- a/README.md +++ b/README.md @@ -75,3 +75,4 @@ These go in `config.json`. See also `config.example.json`. |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.| |typingProxy|false|If enabled, any time a user is typing to modmail in their DMs, the modmail thread will show the bot as "typing"| |typingProxyReverse|false|If enabled, any time a moderator is typing in a modmail thread, the user will see the bot "typing" in their DMs| +|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.| diff --git a/src/config.js b/src/config.js index c2c79f2..f0ad8dc 100644 --- a/src/config.js +++ b/src/config.js @@ -21,7 +21,7 @@ const defaultConfig = { "responseMessage": "Thank you for your message! Our mod team will reply to you here as soon as possible.", "newThreadCategoryId": null, - "mentionRoleID": null, + "mentionRole": null, "inboxServerPermission": null, "alwaysReply": false, diff --git a/src/data/threads.js b/src/data/threads.js index 85b0ce6..f3b497e 100644 --- a/src/data/threads.js +++ b/src/data/threads.js @@ -79,14 +79,13 @@ async function createNewThreadForUser(user) { const newThread = await findById(newThreadId); - //If no role is set, mention @here - const mention = (config.mentionRoleID == null) ? "@here" : `<@&${config.mentionRoleID}>`; - // Ping moderators of the new thread - await newThread.postNonLogMessage({ - content: `${mention} New modmail thread (${newThread.user_name})`, - disableEveryone: false - }); + if (config.mentionRole) { + await newThread.postNonLogMessage({ + content: `${utils.getInboxMention()}New modmail thread (${newThread.user_name})`, + disableEveryone: false + }); + } // Send auto-reply to the user if (config.responseMessage) { diff --git a/src/main.js b/src/main.js index 4845486..f70d7f7 100644 --- a/src/main.js +++ b/src/main.js @@ -140,11 +140,8 @@ bot.on('messageCreate', async msg => { // If the person who mentioned the bot is blocked, ignore them if (await blocked.isBlocked(msg.author.id)) return; - //If no role is set, mention @here - const mention = (config.mentionRoleID == null) ? "@here" : `<@&${config.mentionRoleID}>`; - bot.createMessage(utils.getLogChannel(bot).id, { - content: `${mention} Bot mentioned in ${msg.channel.mention} by **${msg.author.username}#${msg.author.discriminator}**: "${msg.cleanContent}"`, + content: `${utils.getInboxMention()}Bot mentioned in ${msg.channel.mention} by **${msg.author.username}#${msg.author.discriminator}**: "${msg.cleanContent}"`, disableEveryone: false, }); }); diff --git a/src/utils.js b/src/utils.js index c75bc34..dfbb933 100644 --- a/src/utils.js +++ b/src/utils.js @@ -58,7 +58,7 @@ function postLog(...args) { function postError(str) { getLogChannel().createMessage({ - content: `@here **Error:** ${str.trim()}`, + content: `${getInboxMention()}**Error:** ${str.trim()}`, disableEveryone: false }); } @@ -216,6 +216,13 @@ function convertDelayStringToMS(str) { return ms; } +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}> `; +} + module.exports = { BotError, @@ -237,6 +244,7 @@ module.exports = { getSelfUrl, getMainRole, convertDelayStringToMS, + getInboxMention, chunk, trimAll,