zhenxun_bot/plugins/yiqing/__init__.py

53 lines
1.7 KiB
Python
Raw Normal View History

2021-05-20 19:25:51 +08:00
from nonebot import on_command
2021-08-04 15:19:45 +08:00
from .data_source import get_yiqing_data
2021-05-20 19:25:51 +08:00
from services.log import logger
2021-07-30 21:21:51 +08:00
from nonebot.adapters.cqhttp import Bot, MessageEvent, GroupMessageEvent
2021-05-20 19:25:51 +08:00
from nonebot.typing import T_State
2021-08-10 23:03:46 +08:00
from utils.utils import get_message_text
2021-05-20 19:25:51 +08:00
2021-10-03 14:24:07 +08:00
__zx_plugin_name__ = "疫情查询"
__plugin_usage__ = """
usage
全国疫情查询
指令
疫情 中国
疫情 [省份/城市]
* 当省份与城市重名时可在后添加 *
示例疫情 吉林 <- []
示例疫情 吉林市 <- []
""".strip()
__plugin_des__ = "实时疫情数据查询"
__plugin_cmd__ = ["疫情 [省份/城市]", "疫情 中国"]
__plugin_type__ = ('一些工具',)
__plugin_version__ = 0.1
__plugin_author__ = "HibiKier"
__plugin_settings__ = {
"level": 5,
"default_status": True,
"limit_superuser": False,
"cmd": ["查询疫情", "疫情", "疫情查询"],
}
2021-05-20 19:25:51 +08:00
yiqing = on_command("疫情", aliases={"查询疫情", "疫情查询"}, priority=5, block=True)
@yiqing.handle()
2021-07-30 21:21:51 +08:00
async def _(bot: Bot, event: MessageEvent, state: T_State):
2021-08-10 23:03:46 +08:00
msg = get_message_text(event.json())
2021-09-09 10:47:26 +08:00
if msg:
result = await get_yiqing_data(msg)
if result:
await yiqing.send(result)
logger.info(
f"(USER {event.user_id}, GROUP "
f"{event.group_id if isinstance(event, GroupMessageEvent) else 'private'}) 查询疫情: {msg}"
)
else:
await yiqing.send("查询失败!!!!", at_sender=True)
logger.info(
f"(USER {event.user_id}, GROUP "
f"{event.group_id if isinstance(event, GroupMessageEvent) else 'private'}) 查询疫情失败"
)