Update data_source.py

This commit is contained in:
HibiKier 2021-07-06 21:29:23 +08:00 committed by GitHub
parent 54928478a3
commit 1be9305755
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -32,6 +32,7 @@ async def get_qqbot_chat_result(text: str, img_url: str, user_id: int, user_name
for key in keys: for key in keys:
if text.find(key) != -1: if text.find(key) != -1:
return random.choice(anime_data[key]).replace('', user_name) return random.choice(anime_data[key]).replace('', user_name)
try:
if text: if text:
req = { req = {
"perception": "perception":
@ -80,6 +81,9 @@ async def get_qqbot_chat_result(text: str, img_url: str, user_id: int, user_name
"userId": str(user_id) "userId": str(user_id)
} }
} }
except IndexError:
index = 0
return no_result()
async with aiohttp.ClientSession() as sess: async with aiohttp.ClientSession() as sess:
async with sess.post(url, json=req) as response: async with sess.post(url, json=req) as response:
if response.status != 200: if response.status != 200: