Add support for typing status

This commit is contained in:
git-bruh 2020-11-14 19:13:25 +05:30
parent 1c760f760c
commit 0397937130
No known key found for this signature in database
GPG key ID: E1475C50075ADCE6
2 changed files with 35 additions and 1 deletions

View file

@ -1,6 +1,6 @@
# matrix-discord-bridge # matrix-discord-bridge
A simple Matrix-Discord bridge written in Python. A simple bridge between Matrix and Discord written in Python.
## Installation ## Installation
@ -19,3 +19,4 @@ NOTE: [Privileged Intents](https://discordpy.readthedocs.io/en/latest/intents.ht
- [x] Sending messages - [x] Sending messages
- [x] Discord webhooks (with avatars) - [x] Discord webhooks (with avatars)
- [x] Attachments (URL) - [x] Attachments (URL)
- [x] Typing status

33
main.py
View file

@ -67,6 +67,17 @@ async def on_message(message):
await message_send(content) 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): async def process(message, category):
# Replace emote names with emote IDs (Matrix -> Discord) # Replace emote names with emote IDs (Matrix -> Discord)
if category == "emote": if category == "emote":
@ -151,6 +162,8 @@ async def create_matrix_client():
matrix_client.add_event_callback(message_callback, (nio.RoomMessageText, matrix_client.add_event_callback(message_callback, (nio.RoomMessageText,
nio.RoomMessageMedia)) nio.RoomMessageMedia))
matrix_client.add_ephemeral_callback(typing_callback, nio.EphemeralEvent)
# Sync forever # Sync forever
await matrix_client.sync_forever(timeout=timeout) await matrix_client.sync_forever(timeout=timeout)
@ -170,6 +183,10 @@ async def message_send(message):
async def message_callback(room, event): 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 message = event.body
if not message: if not message:
@ -215,6 +232,22 @@ async def message_callback(room, event):
await webhook_send(author, avatar, message) 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(): def main():
# Start Discord bot # Start Discord bot
discord_client.run(config["token"]) discord_client.run(config["token"])