aioappsrv/appservice/matrix.py
git-bruh 4713a00016
cleanup
* Use websocket events to sync usernames/avatars instead of periodic syncing.

* Use caches for fetched room_ids, room state (for usernames and avatars). Also switch to using a single cache with locks.

* Don't store full message objects in cache, just store the relation of matrix event IDs to discord message IDs and vice-versa. Content can be fetched from the server instead.

* Don't rely on websocket events for mentioning Discord users, mentions are now done by mentioning the dummy matrix user. The ID to be mentioned is extracted from the MXID instead.

* General clean-ups.
2021-05-13 15:51:58 +05:30

28 lines
849 B
Python

from dataclasses import dataclass
@dataclass
class User:
avatar_url: str = ""
display_name: str = ""
class Event:
def __init__(self, event: dict):
content = event.get("content", {})
self.attachment = content.get("url")
self.body = content.get("body", "").strip()
self.formatted_body = content.get("formatted_body", "")
self.id = event["event_id"]
self.is_direct = content.get("is_direct", False)
self.redacts = event.get("redacts", "")
self.room_id = event["room_id"]
self.sender = event["sender"]
self.state_key = event.get("state_key", "")
rel = content.get("m.relates_to", {})
self.relates_to = rel.get("event_id")
self.reltype = rel.get("rel_type")
self.new_body = content.get("m.new_content", {}).get("body", "")