warn about encryption failure

This commit is contained in:
Cyberes 2023-03-18 14:03:47 -06:00
parent 4271e2668f
commit 7dc2bf12b6
1 changed files with 12 additions and 7 deletions

View File

@ -5,7 +5,7 @@ import time
from nio import (AsyncClient, InviteMemberEvent, JoinError, MatrixRoom, MegolmEvent, RoomMessageText, UnknownEvent, )
from .bot_commands import Command
from .chat_functions import check_authorized, get_thread_content, is_thread, process_chat, react_to_event
from .chat_functions import check_authorized, get_thread_content, is_thread, process_chat, react_to_event, send_text_to_room
# from .config import Config
from .storage import Storage
@ -75,13 +75,18 @@ class Callbacks:
thread_content = await get_thread_content(self.client, room, event)
api_data = []
for event in thread_content:
api_data.append({'role': 'assistant' if event.sender == self.client.user_id else 'user', 'content': event.body if not event.body.startswith(self.command_prefix) else event.body[
len(self.command_prefix):].strip()}) # if len(thread_content) >= 2 and thread_content[0].body.startswith(self.command_prefix): # if thread_content[len(thread_content) - 2].sender == self.client.user
if isinstance(event, MegolmEvent):
await send_text_to_room(self.client, room.room_id, 'Decryption Failure', reply_to_event_id=event.event_id, thread=True, thread_root_id=thread_content[0].event_id)
else:
api_data.append({
'role': 'assistant' if event.sender == self.client.user_id else 'user',
'content': event.body if not event.body.startswith(self.command_prefix) else event.body[len(self.command_prefix):].strip()
}) # if len(thread_content) >= 2 and thread_content[0].body.startswith(self.command_prefix): # if thread_content[len(thread_content) - 2].sender == self.client.user
# message = Message(self.client, self.store, msg, room, event, self.reply_in_thread)
# await message.process()
api_data.append({'role': 'user', 'content': event.body})
await process_chat(self.client, room, event, api_data, self.store, self.openai, thread_root_id=thread_content[0].event_id, system_prompt=self.system_prompt)
# message = Message(self.client, self.store, msg, room, event, self.reply_in_thread)
# await message.process()
api_data.append({'role': 'user', 'content': event.body})
await process_chat(self.client, room, event, api_data, self.store, self.openai, thread_root_id=thread_content[0].event_id, system_prompt=self.system_prompt)
return
elif msg.startswith(f'{self.command_prefix} ') or room.member_count == 2:
# Otherwise if this is in a 1-1 with the bot or features a command prefix, treat it as a command.