mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2026-10-09 13:50:00 +08:00
fit nonebot.beta2
This commit is contained in:
@@ -1,9 +1,8 @@
|
||||
from nonebot import on_command
|
||||
from .data_source import get_yiqing_data, get_city_and_province_list
|
||||
from services.log import logger
|
||||
from nonebot.adapters.cqhttp import Bot, MessageEvent, GroupMessageEvent
|
||||
from nonebot.typing import T_State
|
||||
from utils.utils import get_message_text
|
||||
from nonebot.adapters.onebot.v11 import MessageEvent, GroupMessageEvent, Message
|
||||
from nonebot.params import CommandArg
|
||||
from configs.config import NICKNAME
|
||||
from .other_than import get_other_data
|
||||
|
||||
@@ -35,8 +34,8 @@ yiqing = on_command("疫情", aliases={"查询疫情", "疫情查询"}, priority
|
||||
|
||||
|
||||
@yiqing.handle()
|
||||
async def _(bot: Bot, event: MessageEvent, state: T_State):
|
||||
msg = get_message_text(event.json())
|
||||
async def _(event: MessageEvent, arg: Message = CommandArg()):
|
||||
msg = arg.extract_plain_text().strip()
|
||||
city_and_province_list = get_city_and_province_list()
|
||||
if msg:
|
||||
if msg in city_and_province_list or msg[:-1] in city_and_province_list:
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
from configs.path_config import TEXT_PATH
|
||||
from typing import List, Union
|
||||
from pathlib import Path
|
||||
from utils.http_utils import AsyncHttpx
|
||||
from utils.image_utils import text2image
|
||||
from utils.message_builder import image
|
||||
from nonebot.adapters.cqhttp import MessageSegment
|
||||
from nonebot.adapters.onebot.v11 import MessageSegment
|
||||
import ujson as json
|
||||
|
||||
china_city = Path(TEXT_PATH) / "china_city.json"
|
||||
china_city = TEXT_PATH / "china_city.json"
|
||||
|
||||
data = {}
|
||||
|
||||
@@ -71,21 +70,21 @@ async def get_yiqing_data(area: str) -> Union[str, MessageSegment]:
|
||||
heal_rate = f"{heal / confirm * 100:.2f}" # 治愈率
|
||||
|
||||
x = f"{city}市" if city else f"{province}{province_type}"
|
||||
return image(b64=await text2image(
|
||||
f"""
|
||||
{x} 疫情数据 {f"(<f font_color={_grade_color}>{grade}</f>)" if grade else ""}:
|
||||
return image(b64=(await text2image(
|
||||
f"""
|
||||
{x} 疫情数据 {f"(<f font_color={_grade_color}>{grade}</f>)" if grade else ""}:
|
||||
目前确诊:
|
||||
确诊人数:<f font_color=red>{now_confirm}(+{add_confirm})</f>
|
||||
-----------------
|
||||
-----------------
|
||||
累计数据:
|
||||
确诊人数:<f font_color=red>{confirm}</f>
|
||||
治愈人数:<f font_color=#39de4b>{heal}</f>
|
||||
死亡人数:<f font_color=#191d19>{dead}</f>
|
||||
治愈率:{heal_rate}%
|
||||
死亡率:{dead_rate}%
|
||||
更新日期:{last_update_time}
|
||||
更新日期:{last_update_time}
|
||||
""", font_size=30, color="#f9f6f2"
|
||||
))
|
||||
)).pic2bs4())
|
||||
|
||||
|
||||
def get_city_and_province_list() -> List[str]:
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
# @File : other_than.py
|
||||
# @Software: PyCharm
|
||||
from utils.http_utils import AsyncHttpx
|
||||
from nonebot.adapters.cqhttp import MessageSegment
|
||||
from nonebot.adapters.onebot.v11 import MessageSegment
|
||||
from typing import Optional
|
||||
from services.log import logger
|
||||
from utils.image_utils import text2image
|
||||
@@ -54,7 +54,7 @@ async def get_other_data(place: str, count: int = 0) -> Optional[MessageSegment]
|
||||
for country in other_country:
|
||||
if place == country["name2"]:
|
||||
return image(
|
||||
b64=await text2image(
|
||||
b64=(await text2image(
|
||||
f" {place} 疫情数据:\n"
|
||||
"——————————————\n"
|
||||
f" 新增病例:<f font_color=red>{intcomma(country['quezhen_add'])}</f>\n"
|
||||
@@ -69,13 +69,13 @@ async def get_other_data(place: str, count: int = 0) -> Optional[MessageSegment]
|
||||
font_size=30,
|
||||
color="#f9f6f2",
|
||||
padding=15
|
||||
)
|
||||
)).pic2bs4()
|
||||
)
|
||||
else:
|
||||
for city in country["child"]:
|
||||
if place == city["name3"]:
|
||||
return image(
|
||||
b64=await text2image(
|
||||
b64=(await text2image(
|
||||
f"\n{place} 疫情数据:\n"
|
||||
"——————————————\n"
|
||||
f"\t新增病例:<f font_color=red>{intcomma(city['quezhen_add'])}</f>\n"
|
||||
@@ -86,7 +86,7 @@ async def get_other_data(place: str, count: int = 0) -> Optional[MessageSegment]
|
||||
font_size=30,
|
||||
color="#f9f6f2",
|
||||
padding=15
|
||||
)
|
||||
)).pic2bs4()
|
||||
)
|
||||
except Exception as e:
|
||||
logger.error(f"疫情查询发生错误 {type(e)}:{e}")
|
||||
|
||||
Reference in New Issue
Block a user