Ver Fonte

Initialize self.me so early events cannot crash the adapter

self.me was only assigned in connect(); realtime events arriving before
that raised AttributeError in the self-event filter and mention check.
Paul Klumpp há 1 semana atrás
pai
commit
c15d85d6de
1 ficheiros alterados com 6 adições e 2 exclusões
  1. 6 2
      adapter.py

+ 6 - 2
adapter.py

@@ -119,6 +119,10 @@ class ChattoAdapter(BasePlatformAdapter):
         # SDK runtime handle (injected by Hermes); annotate for Pylance
         self.sdk: Any = getattr(self, "sdk", None)
 
+        # Our own user, filled in by connect(). Events arriving before connect()
+        # completes must not blow up on an undefined attribute.
+        self.me: Optional[User] = None
+
         # --- Runtime state ---
         self._user_id: str = ""
         self._user_display: str = ""
@@ -430,7 +434,7 @@ class ChattoAdapter(BasePlatformAdapter):
         logger.info("message_body: %s room_kind: %s", message_body, room_kind)
 
         mentioned = False
-        if (room_kind == RoomKind.CHANNEL and self.chatto_config.require_mention.value):
+        if (room_kind == RoomKind.CHANNEL and self.chatto_config.require_mention.value and self.me):
             if self.me.login and not mentioned:
                 mentioned = bool(f"@{self.me.login}" in message_body)
             if self.me.display_name and not mentioned:
@@ -494,7 +498,7 @@ class ChattoAdapter(BasePlatformAdapter):
             # Self-event filter — the actor_id on the envelope is authoritative
             # (chattolib does NOT filter this itself; see chatto-bridge notes).
             actor_id = event.actor_id
-            if actor_id and actor_id == self.me.id:
+            if actor_id and self.me and actor_id == self.me.id:
                 return
 
             await self._dispatch_message_posted(event_payload)