Add support for typing status
This commit is contained in:
parent
1c760f760c
commit
0397937130
2 changed files with 35 additions and 1 deletions
|
@ -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
|
||||
|
|
33
main.py
33
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"])
|
||||
|
|
Loading…
Reference in a new issue