zhenxun_bot/plugins/alapi/poetry.py

43 lines
1.3 KiB
Python
Raw Normal View History

2021-06-24 15:32:06 +08:00
from nonebot import on_command
2021-08-17 23:17:08 +08:00
from nonebot.adapters.cqhttp import Bot, MessageEvent, GroupMessageEvent
2021-06-24 15:32:06 +08:00
from nonebot.typing import T_State
from services.log import logger
2021-08-17 23:17:08 +08:00
from .data_source import get_data
2021-06-24 15:32:06 +08:00
2021-11-04 16:11:50 +08:00
__zx_plugin_name__ = "古诗"
2021-10-03 14:24:07 +08:00
__plugin_usage__ = """usage
平白无故念首诗
示例念诗/来首诗/念首诗
"""
2021-11-04 16:11:50 +08:00
__plugin_des__ = "为什么突然文艺起来了!"
__plugin_cmd__ = ["念诗/来首诗/念首诗"]
2021-10-03 14:24:07 +08:00
__plugin_version__ = 0.1
2021-11-04 16:11:50 +08:00
__plugin_author__ = "HibiKier"
2021-10-03 14:24:07 +08:00
__plugin_settings__ = {
"level": 5,
"default_status": True,
"limit_superuser": False,
2021-11-04 16:11:50 +08:00
"cmd": ["念诗", "来首诗", "念首诗"],
2021-10-03 14:24:07 +08:00
}
2021-06-24 15:32:06 +08:00
2021-11-04 16:11:50 +08:00
poetry = on_command("念诗", aliases={"来首诗", "念首诗"}, priority=5, block=True)
2021-06-24 15:32:06 +08:00
2021-11-04 16:11:50 +08:00
poetry_url = "https://v2.alapi.cn/api/shici"
2021-06-24 15:32:06 +08:00
@poetry.handle()
async def _(bot: Bot, event: MessageEvent, state: T_State):
2021-11-04 16:11:50 +08:00
data, code = await get_data(poetry_url)
2021-06-24 15:32:06 +08:00
if code != 200:
await poetry.finish(data, at_sender=True)
2021-11-04 16:11:50 +08:00
data = data["data"]
content = data["content"]
title = data["origin"]
author = data["author"]
await poetry.send(f"{content}\n\t——{author}{title}")
2021-06-24 15:32:06 +08:00
logger.info(
2021-08-17 23:17:08 +08:00
f"(USER {event.user_id}, GROUP {event.group_id if isinstance(event, GroupMessageEvent) else 'private'})"
2021-11-04 16:11:50 +08:00
f" 发送古诗: f'{content}\n\t--{author}{title}'"
)