diff --git a/synapse_antispam/mjolnir/antispam.py b/synapse_antispam/mjolnir/antispam.py index 7bde80d..43c1294 100644 --- a/synapse_antispam/mjolnir/antispam.py +++ b/synapse_antispam/mjolnir/antispam.py @@ -162,7 +162,13 @@ class Module: async def check_event_for_spam( self, event: "synapse.events.EventBase" ) -> Union[bool, str]: - return self.antispam.check_event_for_spam(event) or self.message_max_length.check_event_for_spam(event) + if self.antispam.check_event_for_spam(event): + # The event was marked by a banlist rule. + return True + if self.message_max_length.check_event_for_spam(event): + # Message too long. + return True + return False # not spam. async def user_may_invite( self, inviter_user_id: str, invitee_user_id: str, room_id: str diff --git a/synapse_antispam/mjolnir/message_max_length.py b/synapse_antispam/mjolnir/message_max_length.py index 7f75478..a606f5e 100644 --- a/synapse_antispam/mjolnir/message_max_length.py +++ b/synapse_antispam/mjolnir/message_max_length.py @@ -30,13 +30,13 @@ class MessageMaxLength(object): self.remote_servers: bool = config.get("remote_servers", False) self.api = api - def check_event_for_spam(self, event): + def check_event_for_spam(self, event: "synapse.events.EventBase") -> bool: if self.threshold is None: return False # not spam, MessageMaxLength hasn't been configured to do anything. sender = UserID.from_string(event.get("sender", "")) # check if the event is from us or we if we are limiting message length from remote servers too. - if sender.domain == self.api.server_name or sender.domain in self.remote_servers: + if sender.domain == self.api.server_name or self.remote_servers: body = event.get("content", {}).get("body", "") if len(body) > self.threshold: room_id = event.get("room_id", "")