diff --git a/README.md b/README.md index 56127817..f1aadf0a 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/synapse_antispam/mjolnir/antispam.py b/synapse_antispam/mjolnir/antispam.py index 2c8dad02..df71fa9b 100644 --- a/synapse_antispam/mjolnir/antispam.py +++ b/synapse_antispam/mjolnir/antispam.py @@ -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 @@ -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 @@ -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