Skip to content
This repository has been archived by the owner on Jan 20, 2025. It is now read-only.

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
lgc2333 committed Oct 10, 2023
1 parent be50fdc commit f23c87d
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 36 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ Telegram:[@lgc2333](https://t.me/lgc2333)

### 0.9.5

- 修复由于 SchaleDB 数据结构变动导致的一些 Bug
- 抽卡总结图现在有半透明和圆角了

<details>
Expand Down
23 changes: 15 additions & 8 deletions nonebot_plugin_bawiki/command/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -26,7 +26,7 @@
"图片作者 B站@夜猫咪喵喵猫\n"
" \n"
"指令默认发送日服和国际服当前的活动攻略\n"
"指令后面跟`日`或`j`开头的文本代表查询日服当前活动攻略,带以``或`g`开头的文本同理\n"
"指令后面跟`日`或`j`开头的文本代表查询日服当前活动攻略,带以`国际`或`g`、`国`或`c`开头的文本同理\n"
"跟其他文本则代表指定活动名称\n"
" \n"
"指令示例:\n"
Expand All @@ -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:
Expand Down
23 changes: 14 additions & 9 deletions nonebot_plugin_bawiki/command/raid.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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(
Expand All @@ -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")),
Expand Down
23 changes: 15 additions & 8 deletions nonebot_plugin_bawiki/command/time_atk.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -26,7 +26,7 @@
"图片作者 B站@夜猫咪喵喵猫\n"
" \n"
"指令默认发送日服和国际服当前的综合战术考试攻略\n"
"指令后面跟`日`或`j`开头的文本代表查询日服当前综合战术考试攻略,带以``或`g`开头的文本同理\n"
"指令后面跟`日`或`j`开头的文本代表查询日服当前综合战术考试攻略,带以`国际`或`g`、`国`或`c`开头的文本同理\n"
"跟整数则代表指定第几个综合战术考试\n"
" \n"
"p.s. 综合战术考试 和 合同火力演习 其实是一个东西,翻译不同而已~\n"
Expand All @@ -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:
Expand Down
6 changes: 6 additions & 0 deletions nonebot_plugin_bawiki/data/bawiki.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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:
Expand All @@ -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)
Expand All @@ -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

Expand Down
1 change: 1 addition & 0 deletions nonebot_plugin_bawiki/data/gacha.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ def gen_important() -> BuildImage:
padding + j * pic.width,
padding * 2 + title_height + i * img_size,
),
alpha=True,
)
return bg

Expand Down
22 changes: 11 additions & 11 deletions nonebot_plugin_bawiki/data/schaledb.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Expand Down Expand Up @@ -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,
)
Expand All @@ -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))
Expand All @@ -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:]))
Expand Down Expand Up @@ -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:]))
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit f23c87d

Please sign in to comment.