zhenxun_bot/plugins/quotations.py

41 lines
1.2 KiB
Python
Raw Normal View History

2022-08-21 18:32:24 +08:00
from nonebot import on_regex
2021-05-20 19:27:31 +08:00
from services.log import logger
2022-02-19 18:20:19 +08:00
from nonebot.adapters.onebot.v11 import Bot, MessageEvent, GroupMessageEvent
2021-05-20 19:27:31 +08:00
from nonebot.typing import T_State
2021-11-23 21:44:59 +08:00
from utils.http_utils import AsyncHttpx
2021-05-20 19:27:31 +08:00
2021-10-03 14:24:07 +08:00
__zx_plugin_name__ = "一言二次元语录"
__plugin_usage__ = """
usage
一言二次元语录
指令
语录/二次元
""".strip()
__plugin_des__ = "二次元语录给你力量"
__plugin_cmd__ = ["语录/二次元"]
__plugin_version__ = 0.1
__plugin_author__ = "HibiKier"
__plugin_settings__ = {
"level": 5,
"default_status": True,
"limit_superuser": False,
"cmd": ["语录", "二次元"],
}
2021-05-20 19:27:31 +08:00
quotations = on_regex("^(语录|二次元)$", priority=5, block=True)
2021-05-20 19:27:31 +08:00
2021-07-30 21:21:51 +08:00
url = "https://international.v1.hitokoto.cn/?c=a"
2021-05-26 20:08:13 +08:00
2021-05-20 19:27:31 +08:00
@quotations.handle()
async def _(bot: Bot, event: MessageEvent, state: T_State):
2021-11-23 21:44:59 +08:00
data = (await AsyncHttpx.get(url, timeout=5)).json()
2021-06-04 18:01:33 +08:00
result = f'{data["hitokoto"]}\t——{data["from"]}'
2021-05-26 20:08:13 +08:00
await quotations.send(result)
2021-05-20 19:27:31 +08:00
logger.info(
2021-07-30 21:21:51 +08:00
f"(USER {event.user_id}, GROUP {event.group_id if isinstance(event, GroupMessageEvent) else 'private'}) 发送语录:"
+ result
)