mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2026-10-05 03:39:59 +08:00
fit nonebot.beta2
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
from nonebot import on_command, on_regex
|
||||
from .query_resource import get_resource_type_list, query_resource, init, check_resource_exists
|
||||
from utils.utils import get_message_text, scheduler
|
||||
from nonebot.adapters.cqhttp import Bot, MessageEvent, GroupMessageEvent, Message
|
||||
from nonebot.typing import T_State
|
||||
from nonebot.adapters.onebot.v11 import Bot, MessageEvent, GroupMessageEvent, Message
|
||||
from utils.utils import scheduler
|
||||
from services.log import logger
|
||||
from configs.config import NICKNAME
|
||||
from nonebot.permission import SUPERUSER
|
||||
from nonebot.params import CommandArg
|
||||
import re
|
||||
|
||||
try:
|
||||
@@ -51,8 +51,8 @@ update_info = on_command("更新原神资源信息", permission=SUPERUSER, prior
|
||||
|
||||
|
||||
@qr.handle()
|
||||
async def _(bot: Bot, event: MessageEvent, state: T_State):
|
||||
resource_name = get_message_text(event.json())
|
||||
async def _(event: MessageEvent, arg: Message = CommandArg()):
|
||||
resource_name = arg.extract_plain_text().strip()
|
||||
if check_resource_exists(resource_name):
|
||||
await qr.send("正在生成位置....")
|
||||
resource = await query_resource(resource_name)
|
||||
@@ -66,9 +66,9 @@ async def _(bot: Bot, event: MessageEvent, state: T_State):
|
||||
|
||||
|
||||
@rex_qr.handle()
|
||||
async def _(bot: Bot, event: MessageEvent, state: T_State):
|
||||
msg = get_message_text(event.json())
|
||||
if msg.find("在哪") != -1:
|
||||
async def _(event: MessageEvent, arg: Message = CommandArg()):
|
||||
msg = arg.extract_plain_text().strip()
|
||||
if "在哪" in msg:
|
||||
rs = re.search("(.*)在哪.*?", msg)
|
||||
resource_name = rs.group(1) if rs else ""
|
||||
else:
|
||||
@@ -86,7 +86,7 @@ async def _(bot: Bot, event: MessageEvent, state: T_State):
|
||||
|
||||
|
||||
@qr_lst.handle()
|
||||
async def _(bot: Bot, event: MessageEvent, state: T_State):
|
||||
async def _(bot: Bot, event: MessageEvent):
|
||||
txt = get_resource_type_list()
|
||||
txt_list = txt.split("\n")
|
||||
if isinstance(event, GroupMessageEvent):
|
||||
@@ -113,7 +113,7 @@ async def _(bot: Bot, event: MessageEvent, state: T_State):
|
||||
|
||||
|
||||
@update_info.handle()
|
||||
async def _(bot: Bot, event: MessageEvent, state: T_State):
|
||||
async def _():
|
||||
await init(True)
|
||||
await update_info.send("更新原神资源信息完成...")
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
from pathlib import Path
|
||||
from configs.path_config import IMAGE_PATH, TEXT_PATH
|
||||
from utils.image_utils import BuildImage
|
||||
from typing import Tuple, List
|
||||
@@ -10,10 +9,10 @@ try:
|
||||
except ModuleNotFoundError:
|
||||
import json
|
||||
|
||||
icon_path = Path(IMAGE_PATH) / "genshin" / "genshin_icon"
|
||||
map_path = Path(IMAGE_PATH) / "genshin" / "map" / "map.png"
|
||||
resource_label_file = Path(TEXT_PATH) / "genshin" / "resource_label_file.json"
|
||||
resource_point_file = Path(TEXT_PATH) / "genshin" / "resource_point_file.json"
|
||||
icon_path = IMAGE_PATH / "genshin" / "genshin_icon"
|
||||
map_path = IMAGE_PATH / "genshin" / "map" / "map.png"
|
||||
resource_label_file = TEXT_PATH / "genshin" / "resource_label_file.json"
|
||||
resource_point_file = TEXT_PATH / "genshin" / "resource_point_file.json"
|
||||
|
||||
|
||||
class Map:
|
||||
|
||||
@@ -9,7 +9,6 @@ from asyncio import Semaphore
|
||||
from utils.image_utils import is_valid
|
||||
from utils.http_utils import AsyncHttpx
|
||||
from httpx import ConnectTimeout
|
||||
from pathlib import Path
|
||||
from .map import Map
|
||||
import asyncio
|
||||
import nonebot
|
||||
@@ -26,11 +25,11 @@ LABEL_URL = "https://api-static.mihoyo.com/common/blackboard/ys_obc/v1/map/label
|
||||
POINT_LIST_URL = "https://api-static.mihoyo.com/common/blackboard/ys_obc/v1/map/point/list?map_id=2&app_sn=ys_obc"
|
||||
MAP_URL = "https://api-static.mihoyo.com/common/map_user/ys_obc/v1/map/info?map_id=2&app_sn=ys_obc&lang=zh-cn"
|
||||
|
||||
icon_path = Path(IMAGE_PATH) / "genshin" / "genshin_icon"
|
||||
map_path = Path(IMAGE_PATH) / "genshin" / "map"
|
||||
resource_label_file = Path(TEXT_PATH) / "genshin" / "resource_label_file.json"
|
||||
resource_point_file = Path(TEXT_PATH) / "genshin" / "resource_point_file.json"
|
||||
resource_type_file = Path(TEXT_PATH) / "genshin" / "resource_type_file.json"
|
||||
icon_path = IMAGE_PATH / "genshin" / "genshin_icon"
|
||||
map_path = IMAGE_PATH / "genshin" / "map"
|
||||
resource_label_file = TEXT_PATH / "genshin" / "resource_label_file.json"
|
||||
resource_point_file = TEXT_PATH / "genshin" / "resource_point_file.json"
|
||||
resource_type_file = TEXT_PATH / "genshin" / "resource_type_file.json"
|
||||
|
||||
# 地图中心坐标
|
||||
CENTER_POINT: Optional[Tuple[int, int]] = None
|
||||
@@ -115,7 +114,7 @@ async def download_resource_data(semaphore: Semaphore):
|
||||
icon_path.mkdir(parents=True, exist_ok=True)
|
||||
resource_label_file.parent.mkdir(parents=True, exist_ok=True)
|
||||
try:
|
||||
response = await AsyncHttpx.get(POINT_LIST_URL)
|
||||
response = await AsyncHttpx.get(POINT_LIST_URL, timeout=5)
|
||||
if response.status_code == 200:
|
||||
data = response.json()
|
||||
if data["message"] == "OK":
|
||||
@@ -167,7 +166,7 @@ async def download_map_init(
|
||||
if _map.exists() and os.path.getsize(_map) > 1024 * 1024 * 30:
|
||||
_map.unlink()
|
||||
try:
|
||||
response = await AsyncHttpx.get(MAP_URL)
|
||||
response = await AsyncHttpx.get(MAP_URL, timeout=5)
|
||||
if response.status_code == 200:
|
||||
data = response.json()
|
||||
if data["message"] == "OK":
|
||||
@@ -206,7 +205,7 @@ async def download_map_init(
|
||||
async def download_resource_type():
|
||||
resource_type_file.parent.mkdir(parents=True, exist_ok=True)
|
||||
try:
|
||||
response = await AsyncHttpx.get(LABEL_URL)
|
||||
response = await AsyncHttpx.get(LABEL_URL, timeout=5)
|
||||
if response.status_code == 200:
|
||||
data = response.json()
|
||||
if data["message"] == "OK":
|
||||
@@ -252,7 +251,7 @@ async def download_image(
|
||||
async with semaphore:
|
||||
try:
|
||||
if not os.path.exists(path) or not is_valid or force_flag:
|
||||
if await AsyncHttpx.download_file(img_url, path):
|
||||
if await AsyncHttpx.download_file(img_url, path, timeout=5):
|
||||
logger.info(f"下载原神资源图标:{img_url}")
|
||||
if gen_flag:
|
||||
gen_icon(path)
|
||||
|
||||
Reference in New Issue
Block a user