From 1be930575545dbaee563cc5e200827bc009799d8 Mon Sep 17 00:00:00 2001 From: HibiKier <45528451+HibiKier@users.noreply.github.com> Date: Tue, 6 Jul 2021 21:29:23 +0800 Subject: [PATCH] Update data_source.py --- plugins/ai/data_source.py | 98 ++++++++++++++++++++------------------- 1 file changed, 51 insertions(+), 47 deletions(-) diff --git a/plugins/ai/data_source.py b/plugins/ai/data_source.py index 8e6484ee..978df78e 100644 --- a/plugins/ai/data_source.py +++ b/plugins/ai/data_source.py @@ -32,54 +32,58 @@ async def get_qqbot_chat_result(text: str, img_url: str, user_id: int, user_name for key in keys: if text.find(key) != -1: return random.choice(anime_data[key]).replace('你', user_name) - if text: - req = { - "perception": - { - "inputText": - { - "text": text - }, - "selfInfo": - { - "location": - { - "city": "陨石坑", - "province": "火星", - "street": "第5坑位" - } - } - }, - "userInfo": - { - "apiKey": TL_KEY[index], - "userId": str(user_id) - } - } - elif img_url: - req = { - "reqType": 1, - "perception": - { - "inputImage": { - "url": img_url + try: + if text: + req = { + "perception": + { + "inputText": + { + "text": text + }, + "selfInfo": + { + "location": + { + "city": "陨石坑", + "province": "火星", + "street": "第5坑位" + } + } }, - "selfInfo": - { - "location": - { - "city": "陨石坑", - "province": "火星", - "street": "第5坑位" - } - } - }, - "userInfo": - { - "apiKey": TL_KEY[index], - "userId": str(user_id) - } - } + "userInfo": + { + "apiKey": TL_KEY[index], + "userId": str(user_id) + } + } + elif img_url: + req = { + "reqType": 1, + "perception": + { + "inputImage": { + "url": img_url + }, + "selfInfo": + { + "location": + { + "city": "陨石坑", + "province": "火星", + "street": "第5坑位" + } + } + }, + "userInfo": + { + "apiKey": TL_KEY[index], + "userId": str(user_id) + } + } + except IndexError: + index = 0 + return no_result() async with aiohttp.ClientSession() as sess: async with sess.post(url, json=req) as response: if response.status != 200: