Add support of short path messages, which are not send to the AI but just added to the history.

This commit is contained in:
OK
2023-03-24 13:42:10 +01:00
parent 2e848db333
commit 78591ef13a
3 changed files with 39 additions and 0 deletions
+22
View File
@@ -74,6 +74,28 @@ class TestFunctionality(TestBotBase):
await self.bot.on_message(message)
message.channel.send.assert_called_once_with("Hello!", suppress_embeds=True)
async def test_on_message_stort_path(self) -> None:
async def acreate(*a, **kw):
answer = {'answer': 'Hello!',
'answer_needed': True,
'staff': None,
'picture': None,
'hack': False}
return {'choices': [{'message': {'content': json.dumps(answer)}}]}
message = self.create_message("Hello there! How are you?")
message.author.name = 'madeup_name'
message.channel.name = 'some_channel'
self.bot.config['short-path'] = [[r'some.*', r'madeup.*']]
with patch.object(openai.ChatCompletion, 'acreate', new=acreate):
await self.bot.on_message(message)
self.assertEqual(self.bot.airesponder.history[-1]["content"],
'{"user": "madeup_name", "message": "Hello, how are you?", "channel": "some_channel"}')
message.author.name = 'different_name'
await self.bot.on_message(message)
self.assertEqual(self.bot.airesponder.history[-2]["content"],
'{"user": "different_name", "message": "Hello, how are you?", "channel": "some_channel"}')
message.channel.send.assert_called_once_with("Hello!", suppress_embeds=True)
async def test_on_message_event2(self) -> None:
async def acreate(*a, **kw):
answer = {'answer': 'Hello!',