From 7bfc02ebbd27de44294222bac00e230141df9453 Mon Sep 17 00:00:00 2001 From: Cyberes Date: Wed, 22 Mar 2023 16:41:31 -0600 Subject: [PATCH] catch error --- matrix_gpt/bot/chat_functions.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/matrix_gpt/bot/chat_functions.py b/matrix_gpt/bot/chat_functions.py index a940fda..c3dc865 100644 --- a/matrix_gpt/bot/chat_functions.py +++ b/matrix_gpt/bot/chat_functions.py @@ -7,7 +7,7 @@ from typing import List, Optional, Union import stopit from markdown import markdown -from nio import (AsyncClient, ErrorResponse, Event, MatrixRoom, MegolmEvent, Response, RoomMessageText, RoomSendResponse, SendRetryError, ) +from nio import (AsyncClient, ErrorResponse, Event, MatrixRoom, MegolmEvent, Response, RoomGetEventResponse, RoomMessageText, RoomSendResponse, SendRetryError, ) logger = logging.getLogger('MatrixGPT') @@ -114,9 +114,13 @@ def is_thread(event: RoomMessageText): async def is_this_our_thread(client: AsyncClient, room: MatrixRoom, event: RoomMessageText, command_flag: str): base_event_id = event.source['content'].get('m.relates_to', {}).get('event_id') - logger.debug((await client.room_get_event(room.room_id, base_event_id)).event.body) if base_event_id: - return (await client.room_get_event(room.room_id, base_event_id)).event.body.startswith(f'{command_flag} ') + e = await client.room_get_event(room.room_id, base_event_id) + if not isinstance(e, RoomGetEventResponse): + logger.critical(f'Failed to get event in is_this_our_thread(): {vars(e)}') + return + else: + return e.event.body.startswith(f'{command_flag} ') else: return False