zhenxun_bot/plugins/yiqing/__init__.py

66 lines
2.5 KiB
Python
Raw Normal View History

2021-05-20 19:25:51 +08:00
from nonebot import on_command
2021-10-04 22:57:59 +08:00
from .data_source import get_yiqing_data, get_city_and_province_list
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-10-04 22:57:59 +08:00
from configs.config import NICKNAME
from .other_than import get_other_data
2021-10-03 14:24:07 +08:00
__zx_plugin_name__ = "疫情查询"
__plugin_usage__ = """
usage
全国疫情查询
指令
2021-12-24 10:09:53 +08:00
疫情 中国/美国/英国...
2021-10-03 14:24:07 +08:00
疫情 [省份/城市]
2021-10-04 22:57:59 +08:00
* 当省份与城市重名时可在后添加 "" "" *
2021-10-03 14:24:07 +08:00
示例疫情 吉林 <- []
示例疫情 吉林市 <- []
""".strip()
__plugin_des__ = "实时疫情数据查询"
__plugin_cmd__ = ["疫情 [省份/城市]", "疫情 中国"]
__plugin_type__ = ('一些工具',)
__plugin_version__ = 0.1
2021-12-24 10:09:53 +08:00
__plugin_author__ = "HibiKier & yzyyz1387"
2021-10-03 14:24:07 +08:00
__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-10-04 22:57:59 +08:00
city_and_province_list = get_city_and_province_list()
2021-09-09 10:47:26 +08:00
if msg:
2021-10-04 22:57:59 +08:00
if msg in city_and_province_list or msg[:-1] in city_and_province_list:
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'}) 查询疫情失败"
)
2021-09-09 10:47:26 +08:00
else:
2021-12-24 10:09:53 +08:00
rely = await get_other_data(msg)
if rely:
await yiqing.send(rely)
logger.info(
f"(USER {event.user_id}, GROUP "
f"{event.group_id if isinstance(event, GroupMessageEvent) else 'private'}) 查询疫情失败"
)
else:
2021-12-24 10:09:53 +08:00
await yiqing.send(f"{NICKNAME}没有查到{msg}的疫情查询...")