From 56e36da13c3d5df0b8aa76dca9c2c6cffd17c619 Mon Sep 17 00:00:00 2001 From: git-bruh Date: Tue, 1 Dec 2020 10:28:06 +0530 Subject: [PATCH] fix --- main.py | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/main.py b/main.py index af3091a..3ed257a 100644 --- a/main.py +++ b/main.py @@ -127,6 +127,22 @@ class MatrixClient(object): event_id=message ) + async def webhook_send(self, author, avatar, message, event_id): + # Create webhook if it doesn't exist + hook_name = "matrix_bridge" + hooks = await channel.webhooks() + hook = discord.utils.get(hooks, name=hook_name) + if not hook: + hook = await channel.create_webhook(name=hook_name) + + # 'wait=True' allows us to store the sent message + try: + hook = await hook.send(username=author, avatar_url=avatar, + content=message, wait=True) + message_store[event_id] = hook + except discord.errors.HTTPException as e: + matrix_logger.warning(f"Failed to send message {event_id}: {e}") + class DiscordClient(discord.Client): def __init__(self, *args, **kwargs): @@ -174,22 +190,6 @@ class DiscordClient(discord.Client): # Send typing event await matrix_client.room_typing(config["room_id"], timeout=0) - async def webhook_send(self, author, avatar, message, event_id): - # Create webhook if it doesn't exist - hook_name = "matrix_bridge" - hooks = await channel.webhooks() - hook = discord.utils.get(hooks, name=hook_name) - if not hook: - hook = await channel.create_webhook(name=hook_name) - - # 'wait=True' allows us to store the sent message - try: - hook = await hook.send(username=author, avatar_url=avatar, - content=message, wait=True) - message_store[event_id] = hook - except discord.errors.HTTPException as e: - matrix_logger.warning(f"Failed to send message {event_id}: {e}") - class Callbacks(object): async def message_callback(self, room, event): @@ -245,7 +245,7 @@ class Callbacks(object): avatar = f"{url}/{homeserver}/{avatar}" break - await DiscordClient().webhook_send( + await MatrixClient().webhook_send( author, avatar, message, event.event_id) async def redaction_callback(self, room, event): @@ -305,9 +305,6 @@ class Process(object): return content, replied_event async def matrix(self, message): - message = message.replace("@everyone", "@\u200Beveryone") - message = message.replace("@here", "@\u200Bhere") - mentions = re.findall(r"(^|\s)(@(\w*))", message) emotes = re.findall(r":(.*?):", message) @@ -323,6 +320,9 @@ class Process(object): if member: message = message.replace(mention[1], member[0].mention) + message = message.replace("@everyone", "@\u200Beveryone") + message = message.replace("@here", "@\u200Bhere") + return message