diff --git a/README.md b/README.md index e4ea1b6..e9ad445 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # matrix-discord-bridge -A simple Matrix-Discord bridge written in Python. +A simple bridge between Matrix and Discord written in Python. ## Installation @@ -19,3 +19,4 @@ NOTE: [Privileged Intents](https://discordpy.readthedocs.io/en/latest/intents.ht - [x] Sending messages - [x] Discord webhooks (with avatars) - [x] Attachments (URL) +- [x] Typing status diff --git a/main.py b/main.py index 3fd256b..ebec26b 100644 --- a/main.py +++ b/main.py @@ -67,6 +67,17 @@ async def on_message(message): await message_send(content) +@discord_client.event +async def on_typing(channel, user, when): + # Don't act on bots + if user.bot: + return + + if channel == channel_: + # Send typing event + await matrix_client.room_typing(config["room_id"], timeout=0) + + async def process(message, category): # Replace emote names with emote IDs (Matrix -> Discord) if category == "emote": @@ -151,6 +162,8 @@ async def create_matrix_client(): matrix_client.add_event_callback(message_callback, (nio.RoomMessageText, nio.RoomMessageMedia)) + matrix_client.add_ephemeral_callback(typing_callback, nio.EphemeralEvent) + # Sync forever await matrix_client.sync_forever(timeout=timeout) @@ -170,6 +183,10 @@ async def message_send(message): async def message_callback(room, event): + # Don't act on activities in other rooms + if room.room_id != config["room_id"]: + return + message = event.body if not message: @@ -215,6 +232,22 @@ async def message_callback(room, event): await webhook_send(author, avatar, message) +async def typing_callback(room, event): + # Don't act on activities in other rooms + if room.room_id != config["room_id"]: + return + + if room.typing_users: + # Don't act on ourselves + if len(room.typing_users) == 1 \ + and room.typing_users[0] == matrix_client.user: + return + + # Send typing event + async with channel_.typing(): + pass + + def main(): # Start Discord bot discord_client.run(config["token"])