Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix typingProxy + Add some features #799

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
17 changes: 17 additions & 0 deletions src/data/blocked.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,28 @@ async function getExpiredBlocks() {
return blocks.map(_block => _block.user_id);
}

/**
* Returns the list of all blocked users
* @returns {Promise<Array<{ userId: string, userName: string, blockedBy: string, blockedAt: string, expiresAt: string }>>}
*/
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,
block,
unblock,
updateExpiryTime,
getExpiredBlocks,
getBlockedUsers,
};
1 change: 1 addition & 0 deletions src/data/cfg.jsdoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
33 changes: 33 additions & 0 deletions src/data/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"
],
};
3 changes: 3 additions & 0 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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,
Expand Down
17 changes: 17 additions & 0 deletions src/modules/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

};
2 changes: 1 addition & 1 deletion src/modules/typingProxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down