Handle messages as direct, when bot is mentioned.

This commit is contained in:
OK
2023-04-10 13:50:35 +02:00
parent 545db1f79d
commit 9a411a3fed
2 changed files with 10 additions and 7 deletions
+4 -2
View File
@@ -114,7 +114,7 @@ class AIResponder(object):
logging.warning(f"Failed to generate image {repr(description)}: {repr(err)}")
raise RuntimeError(f"Failed to generate image {repr(description)} after multiple retries")
async def post_process(self, response: Dict[str, Any]) -> AIResponse:
async def post_process(self, message: AIMessage, response: Dict[str, Any]) -> AIResponse:
for fld in ('answer', 'staff', 'picture'):
if str(response[fld]).strip().lower() in ('none', '', 'null'):
response[fld] = None
@@ -129,6 +129,8 @@ class AIResponder(object):
response['answer'] = str(response['answer'])
response['answer'] = re.sub(r'@\[([^\]]*)\]\([^\)]*\)', r'\1', response['answer'])
response['answer'] = re.sub(r'\[[^\]]*\]\(([^\)]*)\)', r'\1', response['answer'])
if message.direct or message.user in message.message:
response['answer_needed'] = True
return AIResponse(response['answer'],
response['answer_needed'],
parse_maybe_json(response['staff']),
@@ -232,5 +234,5 @@ class AIResponder(object):
continue
logging.info(f"got this answer:\n{pp(response)}")
self.update_history(messages[-1], answer, limit)
return await self.post_process(response)
return await self.post_process(message, response)
raise RuntimeError("Failed to generate answer after multiple retries")