From 814e528eafc0cdca059432d69c5d9de3e527a8ea Mon Sep 17 00:00:00 2001 From: Gnuxie <50846879+Gnuxie@users.noreply.github.com> Date: Fri, 18 Mar 2022 17:20:53 +0000 Subject: [PATCH] Fix incorrect type deceleration in check_username_for_spam (#250) Fixes https://github.com/matrix-org/mjolnir/issues/245 --- synapse_antispam/mjolnir/antispam.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/synapse_antispam/mjolnir/antispam.py b/synapse_antispam/mjolnir/antispam.py index 43c1294..5683fd4 100644 --- a/synapse_antispam/mjolnir/antispam.py +++ b/synapse_antispam/mjolnir/antispam.py @@ -14,7 +14,7 @@ # limitations under the License. import logging -from typing import Dict, Union +from typing import Dict, Union, Optional from .list_rule import ALL_RULE_TYPES, RECOMMENDATION_BAN from .ban_list import BanList from synapse.module_api import UserID @@ -124,9 +124,12 @@ class AntiSpam(object): # 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"] - ) + if user_profile["display_name"] is not None and self.is_user_banned(user_profile["display_name"]): + return True # spam + if self.is_user_banned(user_profile["user_id"]): + return True # spam + + return False # not spam. def user_may_create_room(self, user_id): return True # allowed @@ -175,5 +178,5 @@ class Module: ) -> bool: return self.antispam.user_may_invite(inviter_user_id, invitee_user_id, room_id) - async def check_username_for_spam(self, user_profile: Dict[str, str]) -> bool: + async def check_username_for_spam(self, user_profile: Dict[str, Optional[str]]) -> bool: return self.antispam.check_username_for_spam(user_profile)