|
@ -1,6 +1,6 @@ |
|
|
import asyncio |
|
|
import asyncio |
|
|
import nio |
|
|
import nio |
|
|
from nio import (AsyncClient, AsyncClientConfig, MatrixRoom, RoomMessageText, InviteEvent, UploadResponse) |
|
|
from nio import (AsyncClient, AsyncClientConfig, MatrixRoom, RoomMessageText, InviteEvent, UploadResponse, RedactionEvent) |
|
|
|
|
|
|
|
|
import os, sys |
|
|
import os, sys |
|
|
import time |
|
|
import time |
|
@ -265,6 +265,16 @@ class Callbacks(object): |
|
|
else: |
|
|
else: |
|
|
logger.error("Error joining room: {}".format(str(result))) |
|
|
logger.error("Error joining room: {}".format(str(result))) |
|
|
|
|
|
|
|
|
|
|
|
async def redaction_cb(self, room: MatrixRoom, event: RedactionEvent) -> None: |
|
|
|
|
|
logger.info(f"event redacted in room {room.room_id}. event_id: {event.redacts}") |
|
|
|
|
|
for bot in bots: |
|
|
|
|
|
# for room in bot.chat_history.chat_rooms.keys(): |
|
|
|
|
|
if room.display_name in bot.chat_history.chat_rooms: |
|
|
|
|
|
logger.info("room found") |
|
|
|
|
|
if bot.chat_history.chat_rooms[room.display_name].exists_id(event.redacts): |
|
|
|
|
|
logger.info("found it") |
|
|
|
|
|
bot.chat_history.chat_rooms[room.display_name].remove_id(event.redacts) |
|
|
|
|
|
|
|
|
class ChatBot(object): |
|
|
class ChatBot(object): |
|
|
"""Main chatbot""" |
|
|
"""Main chatbot""" |
|
|
|
|
|
|
|
@ -338,6 +348,7 @@ class ChatBot(object): |
|
|
self.callbacks = Callbacks(self.client, self) |
|
|
self.callbacks = Callbacks(self.client, self) |
|
|
self.client.add_event_callback(self.callbacks.message_cb, RoomMessageText) |
|
|
self.client.add_event_callback(self.callbacks.message_cb, RoomMessageText) |
|
|
self.client.add_event_callback(self.callbacks.invite_cb, InviteEvent) |
|
|
self.client.add_event_callback(self.callbacks.invite_cb, InviteEvent) |
|
|
|
|
|
self.client.add_event_callback(self.callbacks.redaction_cb, RedactionEvent) |
|
|
|
|
|
|
|
|
sync_task = asyncio.create_task(self.watch_for_sync(self.client.synced)) |
|
|
sync_task = asyncio.create_task(self.watch_for_sync(self.client.synced)) |
|
|
event_loop = asyncio.create_task(self.event_loop()) |
|
|
event_loop = asyncio.create_task(self.event_loop()) |
|
|