Skip to content

Commit

Permalink
Merge pull request #72 from Cypas/dev_cypas
Browse files Browse the repository at this point in the history
feat:/last查询battle加入BX徽章估分显示
  • Loading branch information
Cypas authored Jun 23, 2024
2 parents b77bb12 + eab685f commit 87e3adf
Show file tree
Hide file tree
Showing 6 changed files with 122 additions and 11 deletions.
1 change: 1 addition & 0 deletions nonebot_plugin_splatoon3_nso/data/data_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
35 changes: 32 additions & 3 deletions nonebot_plugin_splatoon3_nso/handle/b_or_c_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand 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'</br><span style="color:{color}">{_x}{top_user.rank}({top_user.power})</span>'
Expand All @@ -152,6 +154,33 @@ 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('`', '&#96;').replace('|', '&#124;')
ranking_str = ""
badge_badge_point_str = f"{badge_badge_point}↑"
if ranking != "2000+":
ranking_str = f"{ranking}"

name = name.strip() + f'</br><span style="color:{color}">{_x}{ranking_str}({badge_badge_point_str})</span>'
# 武器图片
img_type = "badges"
weapon_main_img = await model_get_temp_image_path(img_type, max_badge)
if weapon_main_img:
# 高优先级显示徽章图片而不是头像
icon = f"<img height='36px' src='{weapon_main_img}'/>"
_power = badge_badge_point

return name, icon, _power


async def get_user_name_color(player_name, player_code, is_myself=False):
"""取用户名颜色"""
img = ""
Expand Down
26 changes: 21 additions & 5 deletions nonebot_plugin_splatoon3_nso/handle/battle.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -183,6 +183,9 @@ async def get_battle_msg_md(b_info, battle_detail, get_equip=False, idx=0, splat
f'</br>&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&nbsp;' \
f'<span style="color:red">X12(3000) </span> :日服五百强排名及分数,' \
f'<span style="color:#fc0390">X12(3000) </span> :美服五百强排名及分数' \
f'</br>&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&nbsp;' \
f'<span style="color:red">BX50000(2144.4↑) </span> :日服根据其展示徽章对X赛排名,分数的估算,' \
f'<span style="color:#fc0390">BX50000(2014↑) </span> :美服徽章估分' \
f'</br>用户名右侧头像或武器: 一般都为<span style="color:skyblue">浅蓝色</span>用户的头像,如果是武器,则是以上榜单用户上榜时所用的武器'

# # b_info唯二有用的地方,显示祭典当前等级,但全是日文
Expand Down Expand Up @@ -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)
Expand Down
65 changes: 65 additions & 0 deletions nonebot_plugin_splatoon3_nso/handle/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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": "活动比赛",
Expand Down Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions nonebot_plugin_splatoon3_nso/utils/utils.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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 <ayano05@outlook.com>"]
readme = "README.md"
Expand Down

0 comments on commit 87e3adf

Please sign in to comment.