Archived
1
0
Fork 0

Update __init__.py

This commit is contained in:
多羅狼 2023-06-17 02:01:53 +08:00 committed by GitHub
parent a81e999f5a
commit f3e9684438
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -15,14 +15,17 @@ hitokoto = module(
@hitokoto.handle()
@hitokoto.handle('[<msg_type>] {{hitokoto.help.type}}')
async def _(msg: Bot.MessageSession, msg_type: str = None):
url = 'https://v1.hitokoto.cn/'
if msg_type is not None:
if msg_type not in hitokoto_types:
await msg.finish(msg.locale.t('hitokoto.message.error.type'))
url = "https://v1.hitokoto.cn/"
if msg_type:
if msg_type in hitokoto_type:
url += f"?c={msg_type}"
else:
url += "?c=" + msg_type
await msg.finish(msg.locale.t('hitokoto.message.error.type'))
data = await get_url(url, 200, fmt=json)
from_who = data["from_who"] or ""
from_who = data.get("from_who", "")
tp = msg.locale.t('hitokoto.message.type') + msg.locale.t('hitokoto.message.type.' + data['type'])
link = 'https://hitokoto.cn?id='
await msg.finish(f'''{data["hitokoto"]}\n——{from_who}{data["from"]}\n{tp}\n{link}{data["id"]}''')
link = f"https://hitokoto.cn?id={data['id']}"
response = f"{data['hitokoto']}\n——{from_who}{data['from']}\n{tp}\n{link}"
await msg.finish(response)