minor refactors, embeds

This commit is contained in:
git-bruh 2021-04-18 07:53:21 +00:00
parent 2958b1b90e
commit 7e454a14a5
No known key found for this signature in database
GPG key ID: E1475C50075ADCE6
3 changed files with 12 additions and 13 deletions

View file

@ -23,7 +23,6 @@ class AppService(bottle.Bottle):
self.http = http
self.logger = logging.getLogger("appservice")
# TODO better method.
# Map events to functions.
self.mapping = {
"m.room.member": "on_member",

View file

@ -33,8 +33,11 @@ class Gateway(object):
while True:
try:
await self.gateway_handler(self.get_gateway_url())
except websockets.ConnectionClosedError:
# TODO reconnect ?
except (
websockets.ConnectionClosedError,
websockets.InvalidMessage,
):
# TODO reconnect
self.logger.exception("Quitting, connection lost.")
break
@ -63,9 +66,6 @@ class Gateway(object):
self.query_ev.set()
def handle_otype(self, data: dict, otype: str) -> None:
if data.get("embeds"):
return # TODO embeds
if otype == "MESSAGE_CREATE" or otype == "MESSAGE_UPDATE":
obj = discord.Message(data)
elif otype == "MESSAGE_DELETE":
@ -193,6 +193,8 @@ class Gateway(object):
json.dumps(self.Payloads.QUERY(guild_id, name))
)
# TODO clean this mess.
# Wait for our websocket to receive the chunk.
await asyncio.wait_for(self.query_ev.wait(), timeout=5)

View file

@ -30,9 +30,6 @@ class MatrixClient(AppService):
self.emote_cache: Dict[str, str] = {}
self.format = "_discord_" # "{@,#}_discord_1234:localhost"
def to_return(self, event: matrix.Event) -> bool:
return event.sender.startswith(("@_discord", self.user_id))
def handle_bridge(self, message: matrix.Event) -> None:
# Ignore events that aren't for us.
if message.sender.split(":")[
@ -77,7 +74,10 @@ class MatrixClient(AppService):
self.join_room(event.room_id)
def on_message(self, message: matrix.Event) -> None:
if self.to_return(message):
if (
message.sender.startswith((f"@{self.format}", self.user_id))
or not message.body
):
return
# Handle bridging commands.
@ -106,9 +106,6 @@ class MatrixClient(AppService):
)
else:
if not message.body:
return
message.body = self.process_message(channel_id, message.body)
message_cache[message.event_id] = {
"message_id": self.discord.send_webhook(
@ -428,6 +425,7 @@ class DiscordClient(Gateway):
def to_return(self, message: discord.Message) -> bool:
return (
message.channel_id not in self.app.db.list_channels()
or not message.content
or not message.author
or message.author.discriminator == "0000"
)