From 0eee9da7ee85bc7d5255a02a73105d247ba39328 Mon Sep 17 00:00:00 2001 From: qinyi Date: Fri, 21 Jun 2024 16:27:05 +0800 Subject: [PATCH 1/4] =?UTF-8?q?perf:=E6=B7=BB=E5=8A=A0=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- nonebot_plugin_splatoon3_nso/data/data_source.py | 1 + 1 file changed, 1 insertion(+) diff --git a/nonebot_plugin_splatoon3_nso/data/data_source.py b/nonebot_plugin_splatoon3_nso/data/data_source.py index 413fccf..30ff44c 100644 --- a/nonebot_plugin_splatoon3_nso/data/data_source.py +++ b/nonebot_plugin_splatoon3_nso/data/data_source.py @@ -166,6 +166,7 @@ def model_get_or_set_user(platform, user_id, **kwargs) -> UserTable: else: user = get_insert_or_update_obj(UserTable, filter_dict) if user: + # 这里的session.add本质上执行了create或update的操作,现有user对象所绑定的session已经close,直接用user去commit会报错 session.add(copy.deepcopy(user)) session.commit() session.close() From 5a584722211134fd21fbbe46bf2217579780db2c Mon Sep 17 00:00:00 2001 From: cypas Date: Mon, 24 Jun 2024 04:50:14 +0800 Subject: [PATCH 2/4] =?UTF-8?q?feat:/last=E6=9F=A5=E8=AF=A2battle=E5=8A=A0?= =?UTF-8?q?=E5=85=A5BX=E5=BE=BD=E7=AB=A0=E4=BC=B0=E5=88=86=E6=98=BE?= =?UTF-8?q?=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../handle/b_or_c_tools.py | 34 +++++++++- nonebot_plugin_splatoon3_nso/handle/battle.py | 26 ++++++-- nonebot_plugin_splatoon3_nso/handle/utils.py | 65 +++++++++++++++++++ nonebot_plugin_splatoon3_nso/utils/utils.py | 4 +- pyproject.toml | 2 +- 5 files changed, 120 insertions(+), 11 deletions(-) diff --git a/nonebot_plugin_splatoon3_nso/handle/b_or_c_tools.py b/nonebot_plugin_splatoon3_nso/handle/b_or_c_tools.py index 4cb91b1..0f34b00 100644 --- a/nonebot_plugin_splatoon3_nso/handle/b_or_c_tools.py +++ b/nonebot_plugin_splatoon3_nso/handle/b_or_c_tools.py @@ -106,7 +106,7 @@ def get_battle_group_idx(groups, battle_id) -> int: return group_idx -async def get_top_all_name(name, icon, player_code): +async def get_top_all_username(name, icon, player_code): """对top all榜单上有名的玩家额外渲染name""" top_all = model_get_max_power_top_all(player_code) if not top_all: @@ -127,16 +127,18 @@ async def get_top_all_name(name, icon, player_code): return name, icon, float(max_power or 0) -async def get_top_user(name, icon, player_code): - """获取top玩家md信息""" +async def get_x_username(name, icon, player_code): + """对x榜单上有名的玩家额外渲染name""" top_user = model_get_top_player(player_code) if not top_user: return name, icon, 0 _x = 'x' if ':8:' in top_user.top_type else 'X' if '-a:' in top_user.top_type: + # 美服 color = "#fc0390" else: + # 日服 color = "red" name = name.replace('`', '`').replace('|', '|') name = name.strip() + f'
{_x}{top_user.rank}({top_user.power})' @@ -152,6 +154,32 @@ async def get_top_user(name, icon, player_code): return name, icon, _power +async def get_badge_username(name, icon, area, ranking, max_badge, badge_badge_point): + """根据徽章估算x分对玩家额外渲染name""" + _x = 'BX' + if area == "e": + # 美服 + color = "#fc0390" + else: + # 日服 + color = "red" + name = name.replace('`', '`').replace('|', '|') + ranking_str = "" + if ranking != "2000+": + ranking_str = f"{ranking}↑" + + name = name.strip() + f'
{_x}{ranking_str}({badge_badge_point})' + # 武器图片 + img_type = "badges" + weapon_main_img = await model_get_temp_image_path(img_type, max_badge) + if weapon_main_img: + # 高优先级显示徽章图片而不是头像 + icon = f"" + _power = badge_badge_point + + return name, icon, _power + + async def get_user_name_color(player_name, player_code, is_myself=False): """取用户名颜色""" img = "" diff --git a/nonebot_plugin_splatoon3_nso/handle/battle.py b/nonebot_plugin_splatoon3_nso/handle/battle.py index 5d6a584..2525d02 100644 --- a/nonebot_plugin_splatoon3_nso/handle/battle.py +++ b/nonebot_plugin_splatoon3_nso/handle/battle.py @@ -1,8 +1,8 @@ from datetime import datetime as dt, timedelta -from .b_or_c_tools import get_b_point_and_process, get_x_power_and_process, get_top_user, get_top_all_name, \ - PushStatistics, get_user_name_color -from .utils import get_game_sp_id_and_name, dict_b_mode_trans, get_icon_path +from .b_or_c_tools import get_b_point_and_process, get_x_power_and_process, get_x_username, get_top_all_username, \ + PushStatistics, get_user_name_color, get_badge_username +from .utils import get_game_sp_id_and_name, dict_b_mode_trans, get_icon_path, get_badges_point from ..data.data_source import model_get_temp_image_path, model_get_user_friend from ..data.db_sqlite import UserFriendTable from ..s3s.splatoon import Splatoon @@ -183,6 +183,9 @@ async def get_battle_msg_md(b_info, battle_detail, get_equip=False, idx=0, splat f'
        ' \ f'X12(3000) :日服五百强排名及分数,' \ f'X12(3000) :美服五百强排名及分数' \ + f'
        ' \ + f'BX50000↑(2144.4) :日服根据其展示徽章对X赛排名,分数的估算,' \ + f'BX50000↑(2014) :美服徽章估分' \ f'
用户名右侧头像或武器: 一般都为浅蓝色用户的头像,如果是武器,则是以上榜单用户上榜时所用的武器' # # b_info唯二有用的地方,显示祭典当前等级,但全是日文 @@ -356,11 +359,24 @@ async def get_row_user_stats(k_idx, p, mask=False, is_last_player=False, team_po if not p.get('isMyself'): name, icon = await get_user_name_color(name, player_code) + origin_name = name # X 五百强分数 - name, icon, power = await get_top_user(name, icon, player_code) + name, icon, power = await get_x_username(origin_name, icon, player_code) if (not power) and (not p.get('isMyself')): # 其他排行榜分数 - name, icon, power = await get_top_all_name(name, icon, player_code) + name, icon, power = await get_top_all_username(origin_name, icon, player_code) + + # 通过徽章算分 + badges_list = [] + for b in (p.get('nameplate') or {}).get('badges') or []: + if not b: + continue + badge_name = b.get('id') or '' + badges_list.append(badge_name) + area, ranking, max_badge, badge_badge_point = get_badges_point(badges_list) + if badge_badge_point > power: + # 徽章置分 + name, icon, power = await get_badge_username(origin_name, icon, area, ranking, max_badge, badge_badge_point) if power and isinstance(team_power, list): team_power.append(power) diff --git a/nonebot_plugin_splatoon3_nso/handle/utils.py b/nonebot_plugin_splatoon3_nso/handle/utils.py index 0a1588b..59f12d3 100644 --- a/nonebot_plugin_splatoon3_nso/handle/utils.py +++ b/nonebot_plugin_splatoon3_nso/handle/utils.py @@ -27,6 +27,52 @@ 'S+': -180, } +# 徽章排名 +dict_badges_ranking = { + "QmFkZ2UtMzEwMTAwMA==": "j3000", # 绿X 3000名 仅按日服计算 Badge-3101000 + "QmFkZ2UtMzEwMTAwMQ==": "j500", # 银X 500名 Badge-3101001 + "QmFkZ2UtMzEwMTAwMg==": "j10", # 金X 10名 Badge-3101002 + "QmFkZ2UtMzEwMTEwMA==": "j2000+", # 日服 2000+章 Badge-3101100 + "QmFkZ2UtMzEwMTEwMQ==": "e2000+", # 美服 2000+章 Badge-3101101 + "QmFkZ2UtMzEwMTIwMA==": "j2000+", # 日服 x2000+时连赢15局 Badge-3101200 + "QmFkZ2UtMzEwMTIwMQ==": "e2000+", # 美服 x2000+时连赢15局 Badge-3101201 + "QmFkZ2UtMzEwMTIxMA==": "j2000+", # 日服 x2000+时连赢70局 Badge-3101210 + "QmFkZ2UtMzEwMTIxMQ==": "e2000+", # 美服 x2000+时连赢70局 Badge-3101211 + "QmFkZ2UtMzEwMTIyMA==": "j2000+", # 日服 x2000+时连赢350局 Badge-3101220 + "QmFkZ2UtMzEwMTIyMQ==": "e2000+", # 美服 x2000+时连赢350局 Badge-3101221 + + "QmFkZ2UtMzEwMTMwMA==": "j50000", # 日服 50000 Badge-3101300 + "QmFkZ2UtMzEwMTMwMQ==": "e50000", # 美服 50000 Badge-3101301 + "QmFkZ2UtMzEwMTMxMA==": "j30000", # 日服 30000 Badge-3101310 + "QmFkZ2UtMzEwMTMxMQ==": "e30000", # 美服 30000 Badge-3101311 + "QmFkZ2UtMzEwMTMyMA==": "j10000", # 日服 10000 Badge-3101320 + "QmFkZ2UtMzEwMTMyMQ==": "e10000", # 美服 10000 Badge-3101321 + "QmFkZ2UtMzEwMTMzMA==": "j5000", # 日服 5000 Badge-3101330 + "QmFkZ2UtMzEwMTMzMQ==": "e5000", # 美服 5000 Badge-3101331 + "QmFkZ2UtMzEwMTM0MA==": "j3000", # 日服 3000 Badge-3101340 + "QmFkZ2UtMzEwMTM0MQ==": "e3000", # 美服 3000 Badge-3101341 + "QmFkZ2UtMzEwMTM1MA==": "j1000", # 日服 1000 Badge-3101350 + "QmFkZ2UtMzEwMTM1MQ==": "e1000", # 美服 1000 Badge-3101351 + "QmFkZ2UtMzEwMTM2MA==": "j500", # 日服 500 Badge-3101360 + "QmFkZ2UtMzEwMTM2MQ==": "e500", # 美服 500 Badge-3101361 + "QmFkZ2UtMzEwMTM3MA==": "j10", # 日服 10 Badge-3101370 + "QmFkZ2UtMzEwMTM3MQ==": "e10", # 美服 10 Badge-3101371 +} + +# 排名对应分数 2024年6月统计 +dict_ranking_point = { + "j50000": 2144.4, # 日服排名分数估算 + "j30000": 2255.9, + "j10000": 2489.6, + "j5000": 2577.7, + "j3000": 2641.5, + "j1000": 2793.9, + "j500": 2910.5, + "j10": 3449.8, + "j2000+": 2000, + "e2000+": 2000, +} + # 对战模式翻译 dict_b_mode_trans = { "LEAGUE": "活动比赛", @@ -65,6 +111,25 @@ } +def get_badges_point(badges_list: list[str]) -> tuple: + """获取全部徽章内的最高估计x分数""" + area = "" + ranking = "" + max_badge = "" + max_badge_point = 0 + for badge in badges_list: + if badge in dict_badges_ranking: + ranking = dict_badges_ranking.get(badge) # 排名 + if ranking in dict_ranking_point: + point = dict_ranking_point.get(ranking) # 分数 + if point > max_badge_point: + area = ranking[0] + ranking = ranking[1:] # 排名 + max_badge = badge + max_badge_point = point # 最大值 + return area, ranking, max_badge, float(max_badge_point) + + def get_icon_path(name, ext_name="png"): """获取图标文件路径""" if name in dict_icon_file_map: diff --git a/nonebot_plugin_splatoon3_nso/utils/utils.py b/nonebot_plugin_splatoon3_nso/utils/utils.py index d18f54d..82769a6 100644 --- a/nonebot_plugin_splatoon3_nso/utils/utils.py +++ b/nonebot_plugin_splatoon3_nso/utils/utils.py @@ -1,8 +1,8 @@ import os -BOT_VERSION = "2.7.2" +BOT_VERSION = "2.7.3" DIR_RESOURCE = f"{os.path.abspath(os.path.join(__file__, os.pardir, os.pardir))}/resource" -plugin_release_time = "2024-01-30 02:35:58" # 预留 2.0.0重构版nso插件发布时间,预计发布时对全部用户先显示一周,之后再判断用户创建时间 +plugin_release_time = "2024-06-24 04:35:58" # 预留 2.0.0重构版nso插件发布时间,预计发布时对全部用户先显示一周,之后再判断用户创建时间 def multiple_replace(text, _dict): diff --git a/pyproject.toml b/pyproject.toml index 89f34ee..e09d6fa 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "nonebot-plugin-splatoon3-nso" -version = "1.5.2" +version = "1.5.3" description = "一个基于nonebot2框架的splatoon3游戏nso数据查询插件" authors = ["cypas "] readme = "README.md" From 6e1567f508a35b32960766f3f88e31f376f44e79 Mon Sep 17 00:00:00 2001 From: cypas Date: Mon, 24 Jun 2024 04:56:11 +0800 Subject: [PATCH 3/4] =?UTF-8?q?feat:/last=E6=9F=A5=E8=AF=A2battle=E5=8A=A0?= =?UTF-8?q?=E5=85=A5BX=E5=BE=BD=E7=AB=A0=E4=BC=B0=E5=88=86=E6=98=BE?= =?UTF-8?q?=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- nonebot_plugin_splatoon3_nso/handle/battle.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nonebot_plugin_splatoon3_nso/handle/battle.py b/nonebot_plugin_splatoon3_nso/handle/battle.py index 2525d02..e0cf4f4 100644 --- a/nonebot_plugin_splatoon3_nso/handle/battle.py +++ b/nonebot_plugin_splatoon3_nso/handle/battle.py @@ -184,8 +184,8 @@ async def get_battle_msg_md(b_info, battle_detail, get_equip=False, idx=0, splat f'X12(3000) :日服五百强排名及分数,' \ f'X12(3000) :美服五百强排名及分数' \ f'
        ' \ - f'BX50000↑(2144.4) :日服根据其展示徽章对X赛排名,分数的估算,' \ - f'BX50000↑(2014) :美服徽章估分' \ + f'BX50000(2144.4↑) :日服根据其展示徽章对X赛排名,分数的估算,' \ + f'BX50000(2014↑) :美服徽章估分' \ f'
用户名右侧头像或武器: 一般都为浅蓝色用户的头像,如果是武器,则是以上榜单用户上榜时所用的武器' # # b_info唯二有用的地方,显示祭典当前等级,但全是日文 From eab685f8f8f6383b40363a7b92d007e352f47fb9 Mon Sep 17 00:00:00 2001 From: cypas Date: Mon, 24 Jun 2024 05:13:54 +0800 Subject: [PATCH 4/4] =?UTF-8?q?perf:=E4=BC=98=E5=8C=96BX=E6=96=87=E6=9C=AC?= =?UTF-8?q?=E6=A0=BC=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- nonebot_plugin_splatoon3_nso/handle/b_or_c_tools.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/nonebot_plugin_splatoon3_nso/handle/b_or_c_tools.py b/nonebot_plugin_splatoon3_nso/handle/b_or_c_tools.py index 0f34b00..db8a02d 100644 --- a/nonebot_plugin_splatoon3_nso/handle/b_or_c_tools.py +++ b/nonebot_plugin_splatoon3_nso/handle/b_or_c_tools.py @@ -165,10 +165,11 @@ async def get_badge_username(name, icon, area, ranking, max_badge, badge_badge_p color = "red" name = name.replace('`', '`').replace('|', '|') ranking_str = "" + badge_badge_point_str = f"{badge_badge_point}↑" if ranking != "2000+": - ranking_str = f"{ranking}↑" + ranking_str = f"{ranking}" - name = name.strip() + f'
{_x}{ranking_str}({badge_badge_point})' + name = name.strip() + f'
{_x}{ranking_str}({badge_badge_point_str})' # 武器图片 img_type = "badges" weapon_main_img = await model_get_temp_image_path(img_type, max_badge)