diff --git a/src/bot.js b/src/bot.js index 666869a..1338d03 100644 --- a/src/bot.js +++ b/src/bot.js @@ -20,6 +20,11 @@ const intents = [ const bot = new Eris.Client(config.token, { restMode: true, intents: Array.from(new Set(intents)), + allowedMentions: { + everyone: false, + roles: false, + users: false, + }, }); /** diff --git a/src/data/Thread.js b/src/data/Thread.js index 37526a7..4ed6f8c 100644 --- a/src/data/Thread.js +++ b/src/data/Thread.js @@ -331,19 +331,25 @@ class Thread { // Interrupt scheduled closing, if in progress if (this.scheduled_close_at) { await this.cancelScheduledClose(); - await this.postSystemMessage(`<@!${this.scheduled_close_id}> Thread that was scheduled to be closed got a new reply. Cancelling.`); + await this.postSystemMessage({ + content: `<@!${this.scheduled_close_id}> Thread that was scheduled to be closed got a new reply. Cancelling.`, + allowedMentions: { + users: [this.scheduled_close_id], + }, + }); } if (this.alert_ids) { const ids = this.alert_ids.split(","); - let mentions = ""; - - ids.forEach(id => { - mentions += `<@!${id}> `; - }); + const mentionsStr = ids.map(id => `<@!${id}> `).join(""); await this.deleteAlerts(); - await this.postSystemMessage(`${mentions}New message from ${this.user_name}`); + await this.postSystemMessage({ + content: `${mentionsStr}New message from ${this.user_name}`, + allowedMentions: { + users: ids, + }, + }); } } diff --git a/src/data/threads.js b/src/data/threads.js index 2d986d0..305f9ec 100644 --- a/src/data/threads.js +++ b/src/data/threads.js @@ -186,7 +186,7 @@ async function createNewThreadForUser(user, opts = {}) { if (config.mentionRole) { await newThread.postNonLogMessage({ content: `${utils.getInboxMention()}New modmail thread (${newThread.user_name})`, - disableEveryone: false + allowedMentions: utils.getInboxMentionAllowedMentions(), }); } @@ -255,7 +255,10 @@ async function createNewThreadForUser(user, opts = {}) { infoHeader += "\n────────────────"; - await newThread.postSystemMessage(infoHeader); + await newThread.postSystemMessage({ + content: infoHeader, + allowedMentions: config.mentionUserInThreadHeader ? { users: [user.id] } : undefined, + }); if (config.updateNotifications) { const availableUpdate = await updates.getAvailableUpdate(); diff --git a/src/main.js b/src/main.js index 460e02c..600b3c6 100644 --- a/src/main.js +++ b/src/main.js @@ -243,6 +243,7 @@ function initBaseMessageHandlers() { let content; const mainGuilds = utils.getMainGuilds(); const staffMention = (config.pingOnBotMention ? utils.getInboxMention() : ""); + const allowedMentions = (config.pingOnBotMention ? utils.getInboxMentionAllowedMentions() : undefined); if (mainGuilds.length === 1) { content = `${staffMention}Bot mentioned in ${msg.channel.mention} by **${msg.author.username}#${msg.author.discriminator}(${msg.author.id})**: "${msg.cleanContent}"\n\n`; @@ -252,7 +253,7 @@ function initBaseMessageHandlers() { bot.createMessage(utils.getLogChannel().id, { content, - disableEveryone: false, + allowedMentions, }); // Send an auto-response to the mention, if enabled diff --git a/src/modules/block.js b/src/modules/block.js index 5eea8fd..6a73822 100644 --- a/src/modules/block.js +++ b/src/modules/block.js @@ -9,7 +9,12 @@ module.exports = ({ bot, knex, config, commands }) => { const logChannel = utils.getLogChannel(); for (const userId of expiredBlocks) { await blocked.unblock(userId); - logChannel.createMessage(`Block of <@!${userId}> (id \`${userId}\`) expired`); + logChannel.createMessage({ + content: `Block of <@!${userId}> (id \`${userId}\`) expired`, + allowedMentions: { + users: [userId], + }, + }); } } @@ -88,12 +93,21 @@ module.exports = ({ bot, knex, config, commands }) => { const blockStatus = await blocked.getBlockStatus(userIdToCheck); if (blockStatus.isBlocked) { if (blockStatus.expiresAt) { - msg.channel.createMessage(`<@!${userIdToCheck}> (id \`${userIdToCheck}\`) is blocked until ${blockStatus.expiresAt} (UTC)`); + msg.channel.createMessage({ + content: `<@!${userIdToCheck}> (id \`${userIdToCheck}\`) is blocked until ${blockStatus.expiresAt} (UTC)`, + allowedMentions: { users: [userIdToCheck] }, + }); } else { - msg.channel.createMessage(`<@!${userIdToCheck}> (id \`${userIdToCheck}\`) is blocked indefinitely`); + msg.channel.createMessage({ + content: `<@!${userIdToCheck}> (id \`${userIdToCheck}\`) is blocked indefinitely`, + allowedMentions: { users: [userIdToCheck] }, + }); } } else { - msg.channel.createMessage(`<@!${userIdToCheck}> (id \`${userIdToCheck}\`) is NOT blocked`); + msg.channel.createMessage({ + content: `<@!${userIdToCheck}> (id \`${userIdToCheck}\`) is NOT blocked`, + allowedMentions: { users: [userIdToCheck] }, + }); } }); }; diff --git a/src/utils.js b/src/utils.js index 6c537cf..1d5f238 100644 --- a/src/utils.js +++ b/src/utils.js @@ -46,18 +46,18 @@ function getMainGuilds() { * @returns {Eris~TextChannel} */ function getLogChannel() { - const inboxGuild = getInboxGuild(); - const logChannel = inboxGuild.channels.get(config.logChannelId); + const _inboxGuild = getInboxGuild(); + const _logChannel = _inboxGuild.channels.get(config.logChannelId); - if (! logChannel) { + if (! _logChannel) { throw new BotError("Log channel (logChannelId) not found!"); } - if (! (logChannel instanceof Eris.TextChannel)) { + if (! (_logChannel instanceof Eris.TextChannel)) { throw new BotError("Make sure the logChannelId option is set to a text channel!"); } - return logChannel; + return _logChannel; } function postLog(...args) { @@ -217,7 +217,7 @@ function chunk(items, chunkSize) { function trimAll(str) { return str .split("\n") - .map(str => str.trim()) + .map(_str => _str.trim()) .join("\n"); } @@ -263,6 +263,22 @@ function getInboxMention() { return mentions.join(" ") + " "; } +function getInboxMentionAllowedMentions() { + const mentionRoles = Array.isArray(config.mentionRole) ? config.mentionRole : [config.mentionRole]; + const allowedMentions = { + everyone: false, + roles: [], + }; + + for (const role of mentionRoles) { + if (role == null) continue; + else if (role === "here" || role === "everyone") allowedMentions.everyone = true; + else allowedMentions.roles.push(role); + } + + return allowedMentions; +} + function postSystemMessageWithFallback(channel, thread, text) { if (thread) { thread.postSystemMessage(text); @@ -343,6 +359,7 @@ module.exports = { delayStringRegex, convertDelayStringToMS, getInboxMention, + getInboxMentionAllowedMentions, postSystemMessageWithFallback, chunk,