Fix incorrect type deceleration in check_username_for_spam

https://github.com/matrix-org/mjolnir/issues/245
This commit is contained in:
gnuxie 2022-03-18 10:54:07 +00:00
parent 1880287ac4
commit 1843260411

View File

@ -14,7 +14,7 @@
# limitations under the License. # limitations under the License.
import logging import logging
from typing import Dict, Union from typing import Dict, Union, Optional
from .list_rule import ALL_RULE_TYPES, RECOMMENDATION_BAN from .list_rule import ALL_RULE_TYPES, RECOMMENDATION_BAN
from .ban_list import BanList from .ban_list import BanList
from synapse.module_api import UserID from synapse.module_api import UserID
@ -125,9 +125,12 @@ class AntiSpam(object):
# Check whether the user ID or display name matches any of the banned # Check whether the user ID or display name matches any of the banned
# patterns. # patterns.
return self.is_user_banned(user_profile["user_id"]) or self.is_user_banned( if user_profile["display_name"] is not None and self.is_user_banned(user_profile["display_name"]):
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): def user_may_create_room(self, user_id):
return True # allowed return True # allowed
@ -169,5 +172,5 @@ class Module:
) -> bool: ) -> bool:
return self.antispam.user_may_invite(inviter_user_id, invitee_user_id, room_id) 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) return self.antispam.check_username_for_spam(user_profile)