From f23c87d1d6c4b634b0c8d69562cc8dd57e58c515 Mon Sep 17 00:00:00 2001 From: student_2333 Date: Tue, 10 Oct 2023 20:46:31 +0800 Subject: [PATCH] fix --- README.md | 1 + nonebot_plugin_bawiki/command/event.py | 23 +++++++++++++++-------- nonebot_plugin_bawiki/command/raid.py | 23 ++++++++++++++--------- nonebot_plugin_bawiki/command/time_atk.py | 23 +++++++++++++++-------- nonebot_plugin_bawiki/data/bawiki.py | 6 ++++++ nonebot_plugin_bawiki/data/gacha.py | 1 + nonebot_plugin_bawiki/data/schaledb.py | 22 +++++++++++----------- 7 files changed, 63 insertions(+), 36 deletions(-) diff --git a/README.md b/README.md index a3d3633..87c1277 100644 --- a/README.md +++ b/README.md @@ -181,6 +181,7 @@ Telegram:[@lgc2333](https://t.me/lgc2333) ### 0.9.5 +- 修复由于 SchaleDB 数据结构变动导致的一些 Bug - 抽卡总结图现在有半透明和圆角了
diff --git a/nonebot_plugin_bawiki/command/event.py b/nonebot_plugin_bawiki/command/event.py index 88e7cc8..61b813b 100644 --- a/nonebot_plugin_bawiki/command/event.py +++ b/nonebot_plugin_bawiki/command/event.py @@ -8,7 +8,7 @@ from nonebot.params import CommandArg from ..data.bawiki import db_get_event_alias, db_wiki_event -from ..data.schaledb import find_current_event, schale_get_common +from ..data.schaledb import find_current_event, schale_get_config from ..help import FT_E, FT_S from ..util import recover_alia, splice_msg @@ -26,7 +26,7 @@ "图片作者 B站@夜猫咪喵喵猫\n" " \n" "指令默认发送日服和国际服当前的活动攻略\n" - "指令后面跟`日`或`j`开头的文本代表查询日服当前活动攻略,带以`国`或`g`开头的文本同理\n" + "指令后面跟`日`或`j`开头的文本代表查询日服当前活动攻略,带以`国际`或`g`、`国`或`c`开头的文本同理\n" "跟其他文本则代表指定活动名称\n" " \n" "指令示例:\n" @@ -45,18 +45,25 @@ async def _(matcher: Matcher, cmd_arg: Message = CommandArg()): arg = cmd_arg.extract_plain_text().lower().strip() + keys = { + 0: ("日", "j"), + 1: ("国际", "g"), + 2: ("国", "c"), + } + server = [] - if arg.startswith(("日", "j")) or not arg: - server.append(0) - if arg.startswith(("国", "g")) or not arg: - server.append(1) + for k, v in keys.items(): + if (not arg) or arg.startswith(v): + server.append(k) + for kw in v: + arg = arg.replace(kw, "", 1) events = [] if server: try: - common = await schale_get_common() + common = await schale_get_config() for s in server: - ev = common["regions"][s]["current_events"] + ev = common["Regions"][s]["CurrentEvents"] if e := find_current_event(ev): events.append((e[0]["event"]) % 10000) except Exception: diff --git a/nonebot_plugin_bawiki/command/raid.py b/nonebot_plugin_bawiki/command/raid.py index e0610c2..42d9b38 100644 --- a/nonebot_plugin_bawiki/command/raid.py +++ b/nonebot_plugin_bawiki/command/raid.py @@ -10,7 +10,7 @@ from nonebot.rule import ArgumentParser from ..data.bawiki import db_get_raid_alias, db_get_terrain_alias, db_wiki_raid -from ..data.schaledb import find_current_event, schale_get_common +from ..data.schaledb import find_current_event, schale_get_config from ..help import FT_E, FT_S from ..util import recover_alia, splice_msg @@ -52,8 +52,8 @@ "-s", "--server", nargs="*", - help="服务器名称,`j`或`日`代表日服,`g`或`国`代表国际服,可指定多个,默认全选", - default=["j", "g"], + help="服务器名称,`j`或`日`代表日服,`g`或`国际`代表国际服,`c`或`国`代表国服,可指定多个,默认全选", + default=["j", "g", "c"], ) raid_wiki_parser.add_argument("-t", "--terrain", help="指定总力战环境,不指定默认全选,不带Boss名称该参数无效") raid_wiki_parser.add_argument( @@ -79,21 +79,26 @@ async def _(matcher: Matcher, args: Namespace = ShellCommandArgs()): if not args.server: await matcher.finish("请指定server参数") + keys = { + 0: ("日", "j"), + 1: ("国际", "g"), + 2: ("国", "c"), + } + server = set() for s in args.server: - if ("日" in s) or ("j" in s): - server.add(0) - elif ("国" in s) or ("g" in s): - server.add(1) + for i, k in keys.items(): + if s in k: + server.add(i) server = list(server) server.sort() tasks = [] if not args.name: try: - common = await schale_get_common() + common = await schale_get_config() for s in server: - raid = common["regions"][s]["current_raid"] + raid = common["Regions"][s]["CurrentRaid"] if (r := find_current_event(raid)) and (raid := r[0]["raid"]) < 1000: tasks.append( db_wiki_raid(raid, [s], args.wiki, r[0].get("terrain")), diff --git a/nonebot_plugin_bawiki/command/time_atk.py b/nonebot_plugin_bawiki/command/time_atk.py index 2b4e1db..86eff48 100644 --- a/nonebot_plugin_bawiki/command/time_atk.py +++ b/nonebot_plugin_bawiki/command/time_atk.py @@ -8,7 +8,7 @@ from nonebot.params import CommandArg from ..data.bawiki import db_wiki_time_atk -from ..data.schaledb import find_current_event, schale_get_common +from ..data.schaledb import find_current_event, schale_get_config from ..help import FT_E, FT_S from ..util import splice_msg @@ -26,7 +26,7 @@ "图片作者 B站@夜猫咪喵喵猫\n" " \n" "指令默认发送日服和国际服当前的综合战术考试攻略\n" - "指令后面跟`日`或`j`开头的文本代表查询日服当前综合战术考试攻略,带以`国`或`g`开头的文本同理\n" + "指令后面跟`日`或`j`开头的文本代表查询日服当前综合战术考试攻略,带以`国际`或`g`、`国`或`c`开头的文本同理\n" "跟整数则代表指定第几个综合战术考试\n" " \n" "p.s. 综合战术考试 和 合同火力演习 其实是一个东西,翻译不同而已~\n" @@ -53,18 +53,25 @@ async def _(matcher: Matcher, cmd_arg: Message = CommandArg()): arg = cmd_arg.extract_plain_text().lower().strip() + keys = { + 0: ("日", "j"), + 1: ("国际", "g"), + 2: ("国", "c"), + } + server = [] - if arg.startswith(("日", "j")) or not arg: - server.append(0) - if arg.startswith(("国", "g")) or not arg: - server.append(1) + for k, v in keys.items(): + if (not arg) or arg.startswith(v): + server.append(k) + for kw in v: + arg = arg.replace(kw, "", 1) events = [] if server: try: - common = await schale_get_common() + common = await schale_get_config() for s in server: - raid = common["regions"][s]["current_raid"] + raid = common["Regions"][s]["CurrentRaid"] if (r := find_current_event(raid)) and (raid := r[0]["raid"]) >= 1000: events.append(raid) except Exception: diff --git a/nonebot_plugin_bawiki/data/bawiki.py b/nonebot_plugin_bawiki/data/bawiki.py index b7701e5..6bce890 100644 --- a/nonebot_plugin_bawiki/data/bawiki.py +++ b/nonebot_plugin_bawiki/data/bawiki.py @@ -3,6 +3,7 @@ from io import BytesIO from typing import Any, Dict, List, Literal, Optional, cast, overload +from nonebot import logger from nonebot.adapters.onebot.v11 import MessageSegment from pil_utils import BuildImage @@ -89,6 +90,7 @@ async def db_wiki_raid(raid_id, servers=None, is_wiki=False, terrain=None): wiki = (await db_get_wiki_data())["raid"] if not (boss := wiki.get(str(raid_id))): + logger.warning(f"Raid boss {raid_id} not found") return "没有找到该总力战Boss" terrain_raid = None @@ -98,11 +100,13 @@ async def db_wiki_raid(raid_id, servers=None, is_wiki=False, terrain=None): ): terrain_raid = t else: + logger.warning(f"Raid boss {raid_id} terrain {terrain} not found") return "还没有进行过该环境的总力战" img = [] if is_wiki: if not (wiki_url := boss.get("wiki")): + logger.warning(f"Raid boss {raid_id} wiki not found") return "该总力战Boss暂无机制介绍" img.append(wiki_url) else: @@ -121,6 +125,7 @@ async def db_wiki_event(event_id): event_id = str(event_id) wiki = (await db_get_wiki_data())["event"] if not (ev := wiki.get(event_id)): + logger.warning(f"Event {event_id} not found") return "没有找到该活动" return [ MessageSegment.image(x) @@ -133,6 +138,7 @@ async def db_wiki_time_atk(raid_id): raid_id = int(raid_id / 1000) wiki = (await db_get_wiki_data())["time_atk"] if raid_id > len(wiki): + logger.warning(f"Time atk {raid_id} not found") return f"没有找到该综合战术考试(目前共有{len(wiki)}个综合战术考试)" raid_id -= 1 diff --git a/nonebot_plugin_bawiki/data/gacha.py b/nonebot_plugin_bawiki/data/gacha.py index d87e251..daa351a 100644 --- a/nonebot_plugin_bawiki/data/gacha.py +++ b/nonebot_plugin_bawiki/data/gacha.py @@ -269,6 +269,7 @@ def gen_important() -> BuildImage: padding + j * pic.width, padding * 2 + title_height + i * img_size, ), + alpha=True, ) return bg diff --git a/nonebot_plugin_bawiki/data/schaledb.py b/nonebot_plugin_bawiki/data/schaledb.py index a6a3586..0df4097 100644 --- a/nonebot_plugin_bawiki/data/schaledb.py +++ b/nonebot_plugin_bawiki/data/schaledb.py @@ -46,8 +46,8 @@ async def schale_get_stu_data(loc: str = "cn") -> List[Dict[str, Any]]: return await schale_get(f"data/{loc}/students.min.json") -async def schale_get_common() -> Dict[str, Any]: - return await schale_get("data/common.min.json") +async def schale_get_config() -> Dict[str, Any]: + return await schale_get("data/config.min.json") async def schale_get_localization(loc: str = "cn") -> Dict[str, Any]: @@ -78,19 +78,19 @@ async def schale_get_stu_info(stu): async def schale_calender(server: str) -> MessageSegment: - students, common, localization, raids = await asyncio.gather( + students, s_config, localization, raids = await asyncio.gather( schale_get_stu_dict("Id"), - schale_get_common(), + schale_get_config(), schale_get_localization(), schale_get_raids(), ) region_index_map: Dict[str, int] = { - x["name"]: i for i, x in enumerate(common["regions"]) + x["Name"]: i for i, x in enumerate(s_config["Regions"]) } image = await schale_get_calender( region_index_map[server], students, - common, + s_config, localization, raids, ) @@ -112,11 +112,11 @@ def find_current_event(ev, now=None): async def schale_get_calender( server_index: int, students: Dict[str, Dict], - common: dict, + s_config: dict, localization: dict, raids: dict, ): - region = common["regions"][server_index] + region = s_config["Regions"][server_index] now = datetime.now() pic_bg = BuildImage.new("RGBA", (1400, 640), (255, 255, 255, 70)) @@ -135,7 +135,7 @@ async def draw_gacha(): weight="bold", max_fontsize=80, ) - c_gacha = region["current_gacha"] + c_gacha = region["CurrentGacha"] if r := find_current_event(c_gacha): g = r[0] t = format_time(*(r[1:])) @@ -191,7 +191,7 @@ async def draw_event(): weight="bold", max_fontsize=80, ) - c_event = region["current_events"] + c_event = region["CurrentEvents"] if r := find_current_event(c_event): g = r[0] t = format_time(*(r[1:])) @@ -261,7 +261,7 @@ async def draw_event(): async def draw_raid(): pic = pic_bg.copy() - if r := find_current_event(region["current_raid"]): + if r := find_current_event(region["CurrentRaid"]): ri = r[0] t = format_time(*(r[1:])) pic = pic.paste(