start support for redaction events

This commit is contained in:
HgO 2022-07-10 14:42:23 +02:00
parent a8bdc80612
commit 56eb1e82b1
2 changed files with 15 additions and 1 deletions

View file

@ -7,6 +7,7 @@ from nio import (
JoinError,
MatrixRoom,
MegolmEvent,
RedactionEvent,
RoomGetEventError,
RoomMessageText,
UnknownEvent,
@ -219,6 +220,18 @@ class Callbacks:
f"commands a second time)."
)
async def redaction(self, room: MatrixRoom, event: RedactionEvent) -> None:
# Ignore events from unauthorized room
if room.room_id != self.config.room_id:
return
# Ignore redactions from ourselves
if event.sender == self.config.user_id:
return
redacted_event = await self.client.room_get_event(room.room_id, event.redacts)
print(redacted_event.source)
async def unknown(self, room: MatrixRoom, event: UnknownEvent) -> None:
"""Callback for when an event with a type that is unknown to matrix-nio is received.
Currently this is used for reaction events, which are not yet part of a released

View file

@ -3,7 +3,6 @@ import asyncio
import logging
import sys
from asyncio import TimeoutError
from time import sleep
from aiohttp import ClientConnectionError, ServerDisconnectedError
from diskcache import Cache
@ -14,6 +13,7 @@ from nio import (
LocalProtocolError,
LoginError,
MegolmEvent,
RedactionEvent,
RoomMessageText,
UnknownEvent,
)
@ -129,6 +129,7 @@ def main() -> None:
)
client.add_event_callback(callbacks.decryption_failure, (MegolmEvent,))
client.add_event_callback(callbacks.unknown, (UnknownEvent,))
client.add_event_callback(callbacks.redaction, (RedactionEvent,))
# Configure webhook server
webhook_server = Webhook(client, cache, config)