Skip to content

Commit

Permalink
Add a flag for disabling checking of usernames for spam.
Browse files Browse the repository at this point in the history
  • Loading branch information
clokep committed Feb 13, 2020
1 parent 92c6f3f commit 70f353f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ spam_checker:
# this means that spammy messages will appear as empty to users. Default
# false.
block_messages: false
# Remove users from the user directory search by filtering matrix IDs and
# display names by the entries in the user ban list. Default false.
block_usernames: false
# The room IDs of the ban lists to honour. Unlike other parts of Mjolnir,
# this list cannot be room aliases or permalinks. This server is expected
# to already be joined to the room - Mjolnir will not automatically join
Expand Down
14 changes: 9 additions & 5 deletions synapse_antispam/mjolnir/antispam.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class AntiSpam(object):
def __init__(self, config, api):
self.block_invites = config.get("block_invites", True)
self.block_messages = config.get("block_messages", False)
self.block_usernames = config.get("block_usernames", False)
self.list_room_ids = config.get("ban_lists", [])
self.rooms_to_lists = {} # type: Dict[str, BanList]
self.api = api
Expand Down Expand Up @@ -106,6 +107,14 @@ def user_may_invite(self, inviter_user_id, invitee_user_id, room_id):

return True # allowed (as far as we're concerned)

def check_username_for_spam(self, user_profile):
if not self.block_usernames:
return True # allowed (we aren't blocking based on usernames)

# Check whether the user ID or display name matches any of the banned
# patterns.
return self.is_user_banned(user_profile["user_id"]) or self.is_user_banned(user_profile["display_name"])

def user_may_create_room(self, user_id):
return True # allowed

Expand All @@ -115,11 +124,6 @@ def user_may_create_room_alias(self, user_id, room_alias):
def user_may_publish_room(self, user_id, room_id):
return True # allowed

def check_username_for_spam(self, user_profile):
# Check whether the user ID or display name matches any of the banned
# patterns.
return self.is_user_banned(user_profile["user_id"]) or self.is_user_banned(user_profile["display_name"])

@staticmethod
def parse_config(config):
return config # no parsing needed

0 comments on commit 70f353f

Please sign in to comment.