Small fixes.

This commit is contained in:
Fjerkroa Auto 2023-03-22 23:49:36 +01:00
parent 95e810db7a
commit 7007a0bfd5
2 changed files with 7 additions and 1 deletions

View File

@ -99,6 +99,8 @@ class AIResponder(object):
if type(answer) != dict: if type(answer) != dict:
answer = answer.to_dict() answer = answer.to_dict()
response = json.loads(answer['content']) response = json.loads(answer['content'])
if 'hack' not in response or type(response.get('picture', None)) not in (type(None), str):
continue
logging.info(f"got this answer:\n{pformat(response)}") logging.info(f"got this answer:\n{pformat(response)}")
except openai.error.InvalidRequestError as err: except openai.error.InvalidRequestError as err:
if 'maximum context length is' in str(err) and limit > 4: if 'maximum context length is' in str(err) and limit > 4:

View File

@ -72,7 +72,11 @@ class FjerkroaBot(commands.Bot):
message_content = str(message.content).strip() message_content = str(message.content).strip()
if len(message_content) < 1: if len(message_content) < 1:
return return
msg = AIMessage(message.author.name, message_content, str(message.channel.name)) if hasattr(message.channel, 'name'):
channel_name = str(message.channel.name)
else:
channel_name = str(message.channel.id)
msg = AIMessage(message.author.name, message_content, channel_name)
await self.respond(msg, message.channel) await self.respond(msg, message.channel)
async def respond(self, message: AIMessage, channel: TextChannel) -> None: async def respond(self, message: AIMessage, channel: TextChannel) -> None: