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

18 lines
816 B
Python
Raw Normal View History

from core.builtins import Bot
from core.component import module
from core.builtins.message import MessageSession
from core.dirty_check import check
from core.utils.http import get_url
2023-05-04 11:09:16 +00:00
hitokoto = module('hitokoto', developers=['bugungu'], desc='{hitokoto.help.desc}')
2023-05-04 11:09:16 +00:00
@hitokoto.handle('{{hitokoto.help}}')
2023-05-04 11:57:13 +00:00
async def _(msg: Bot.MessageSession):
url = 'https://v1.hitokoto.cn/?encode=json'
2023-05-04 11:57:13 +00:00
responce = await get_url(url, 200, fmt = 'json')
data = json.loads(response)
from_who = data["from_who"] or ""
types = msg.locale.t('hitokoto.message.type') + msg.locale.t('hitokoto.message.type.' + responce['type'])
hitokoto_url = 'https://hitokoto.cn?id={data["id"]}'
await msg.sendMessage(f'''{data["hitokoto"]}\n——{from_who}{data["from"]}\n{types}\n{hitokoto_url}''')