diff --git a/docs/configuration.md b/docs/configuration.md index e53b193b1..810424e8f 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -244,6 +244,10 @@ Alias for [`serverGreetings`](#serverGreetings) **Default:** `off` If enabled, the bot attempts to ignore common "accidental" messages that would start a new thread, such as "ok", "thanks", etc. +#### ignoreOffensiveThreads +**Default:** `off` +If enabled, the bot attempts to ignore common "offensive" messages that would start a new thread, such as "fuck", "idiot", etc. + #### inboxServerPermission **Default:** `manageMessages` **Accepts multiple values.** Permission name, user id, or role id required to use bot commands on the inbox server. diff --git a/src/data/blocked.js b/src/data/blocked.js index 0d3dce7fc..60444f1ec 100644 --- a/src/data/blocked.js +++ b/src/data/blocked.js @@ -84,6 +84,22 @@ async function getExpiredBlocks() { return blocks.map(_block => _block.user_id); } +/** + * Returns the list of all blocked users + * @returns {Promise>} + */ +async function getBlockedUsers() { + const rows = await knex("blocked_users").select(); + + return rows.map(row => ({ + userId: row.user_id, + userName: row.user_name, + blockedBy: row.blocked_by, + blockedAt: row.blocked_at, + expiresAt: row.expires_at + })); +} + module.exports = { getBlockStatus, isBlocked, @@ -91,4 +107,5 @@ module.exports = { unblock, updateExpiryTime, getExpiredBlocks, + getBlockedUsers, }; diff --git a/src/data/cfg.jsdoc.js b/src/data/cfg.jsdoc.js index bed89b5aa..ffe25a0e9 100644 --- a/src/data/cfg.jsdoc.js +++ b/src/data/cfg.jsdoc.js @@ -26,6 +26,7 @@ * @property {boolean} [useNicknames=false] * @property {boolean} [anonymizeChannelName=false] * @property {boolean} [ignoreAccidentalThreads=false] + * @property {boolean} [ignoreOffensiveThreads=false] * @property {boolean} [threadTimestamps=false] * @property {boolean} [allowMove=false] * @property {boolean} [syncPermissionsOnMove=true] diff --git a/src/data/constants.js b/src/data/constants.js index 886313ffa..5ce4fc63d 100644 --- a/src/data/constants.js +++ b/src/data/constants.js @@ -74,4 +74,37 @@ module.exports = { "okey np", "cheers" ], + + OFFENSIVE_THREAD_MESSAGES: [ + "idiot", + "moron", + "stupid", + "dumb", + "fool", + "jerk", + "loser", + "imbecile", + "asshole", + "bastard", + "bitch", + "douchebag", + "scumbag", + "prick", + "cretin", + "twit", + "twat", + "git", + "wanker", + "slut", + "whore", + "dickhead", + "fuckface", + "shithead", + "cocksucker", + "asshat", + "dipshit", + "nutcase", + "bonehead", + "jackass" + ], }; diff --git a/src/main.js b/src/main.js index bce3385bc..db538e987 100644 --- a/src/main.js +++ b/src/main.js @@ -16,6 +16,7 @@ const threads = require("./data/threads"); const updates = require("./data/updates"); const { ACCIDENTAL_THREAD_MESSAGES } = require("./data/constants"); +const { OFFENSIVE_THREAD_MESSAGES } = require("./data/constants"); const {getOrFetchChannel} = require("./utils"); module.exports = { @@ -181,6 +182,8 @@ function initBaseMessageHandlers() { // Ignore messages that shouldn't usually open new threads, such as "ok", "thanks", etc. if (config.ignoreAccidentalThreads && msg.content && ACCIDENTAL_THREAD_MESSAGES.includes(msg.content.trim().toLowerCase())) return; + if (config.ignoreOffensiveThreads && msg.content && OFFENSIVE_THREAD_MESSAGES.includes(msg.content.trim().toLowerCase())) return; + thread = await threads.createNewThreadForUser(msg.author, { source: "dm", message: msg, diff --git a/src/modules/block.js b/src/modules/block.js index 0f6e21983..7179536f1 100644 --- a/src/modules/block.js +++ b/src/modules/block.js @@ -142,4 +142,21 @@ module.exports = ({ bot, knex, config, commands }) => { }); } }); + + commands.addInboxServerCommand("blocklist", "", async (msg, args, thread) => { + const blockedUsers = await blocked.getBlockedUsers(); + if (blockedUsers.length === 0) { + msg.channel.createMessage("No users are currently blocked."); + return; + } + + let reply = "List of blocked users:\n"; + for (const user of blockedUsers) { + const userInfo = `**<@!${user.userId}> (id \`${user.userId}\`)** - Blocked by <@${user.blockedBy}>${user.expiresAt ? ` until ${user.expiresAt} (UTC)` : " permanently"}`; + reply += userInfo + "\n"; + } + + msg.channel.createMessage(reply); + }); + }; diff --git a/src/modules/typingProxy.js b/src/modules/typingProxy.js index e84d085ed..2a87acbcb 100644 --- a/src/modules/typingProxy.js +++ b/src/modules/typingProxy.js @@ -12,7 +12,7 @@ module.exports = ({ bot }) => { } // config.typingProxy: forward user typing in a DM to the modmail thread - if (config.typingProxy && (channel instanceof Eris.PrivateChannel)) { + if (config.typingProxy && !(channel instanceof Eris.GuildChannel)) { const thread = await threads.findOpenThreadByUserId(user.id); if (! thread) return;