Archived
1
0
Fork 0
This repository has been archived on 2024-04-26. You can view files and clone it, but cannot push or open issues or pull requests.
akari-bot/modules/hitokoto/__init__.py

33 lines
1.1 KiB
Python
Raw Normal View History

from core.builtins import Bot
from core.component import module
from core.utils.http import get_url
2023-05-04 12:58:21 +00:00
hitokoto_types = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l"]
hitokoto = module(
'hitokoto',
2023-06-01 17:08:10 +00:00
developers=['bugungu','DoroWolf'],
desc='{hitokoto.help.desc}',
2023-06-01 17:08:10 +00:00
alias='htkt',
support_languages=['zh_cn'])
2023-05-27 11:37:21 +00:00
@hitokoto.handle()
2023-05-04 12:58:21 +00:00
@hitokoto.handle('[<type>] {{hitokoto.help.type}}')
2023-05-04 11:57:13 +00:00
async def _(msg: Bot.MessageSession):
2023-05-27 10:43:31 +00:00
try:
set_type = msg.parsed_msg.get('<type>')
except AttributeError:
set_type = None
2023-05-04 12:58:21 +00:00
url = 'https://v1.hitokoto.cn/?'
2023-05-27 10:43:31 +00:00
if set_type is not None:
2023-05-04 12:58:21 +00:00
if set_type not in hitokoto_types:
2023-05-04 13:02:02 +00:00
await msg.finish(msg.locale.t('hitokoto.message.error.type'))
2023-05-04 12:58:21 +00:00
else:
url += "c=" + set_type
data = await get_url(url, 200, fmt='json')
2023-05-04 11:57:13 +00:00
from_who = data["from_who"] or ""
2023-05-27 10:43:31 +00:00
_type = msg.locale.t('hitokoto.message.type') + msg.locale.t('hitokoto.message.type.' + data['type'])
2023-05-04 12:19:38 +00:00
link = 'https://hitokoto.cn?id='
await msg.finish(f'''{data["hitokoto"]}\n——{from_who}{data["from"]}\n{_type}\n{link}{data["id"]}''')