nonebot-plugin-efthelper 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- nonebot_plugin_efthelper/__init__.py +1195 -0
- nonebot_plugin_efthelper/api.py +668 -0
- nonebot_plugin_efthelper/assets/README.md +27 -0
- nonebot_plugin_efthelper/assets/bear.png +0 -0
- nonebot_plugin_efthelper/assets/usec.png +0 -0
- nonebot_plugin_efthelper/card.py +1112 -0
- nonebot_plugin_efthelper/circle.py +380 -0
- nonebot_plugin_efthelper/config.py +310 -0
- nonebot_plugin_efthelper/eftforge.py +177 -0
- nonebot_plugin_efthelper/endings.py +86 -0
- nonebot_plugin_efthelper/format.py +339 -0
- nonebot_plugin_efthelper/image.py +96 -0
- nonebot_plugin_efthelper/index.py +313 -0
- nonebot_plugin_efthelper/registry.py +164 -0
- nonebot_plugin_efthelper-0.1.0.dist-info/METADATA +105 -0
- nonebot_plugin_efthelper-0.1.0.dist-info/RECORD +19 -0
- nonebot_plugin_efthelper-0.1.0.dist-info/WHEEL +5 -0
- nonebot_plugin_efthelper-0.1.0.dist-info/licenses/LICENSE +21 -0
- nonebot_plugin_efthelper-0.1.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
"""eftforge Atlas 玩家档案适配层。
|
|
2
|
+
|
|
3
|
+
把 eftforge 的 `/atlas/api/lookup` 响应转成 tarkov.dev 档案的结构,
|
|
4
|
+
这样格式化与卡片渲染完全不用改,两条数据源可以无缝切换、随时回退。
|
|
5
|
+
|
|
6
|
+
实测的结构差异:
|
|
7
|
+
|
|
8
|
+
统计计数器 eftforge: [[["Sessions","Pmc"], 193], ...]
|
|
9
|
+
tarkov.dev: [{"Key": ["Sessions","Pmc"], "Value": 193}, ...]
|
|
10
|
+
|
|
11
|
+
成就 eftforge: {"done": [{"id","at","ch":{"name"}, ...}]}
|
|
12
|
+
tarkov.dev: {"<id>": <timestamp>},名字还要另查 tasks_en
|
|
13
|
+
|
|
14
|
+
等级 eftforge 直接给 level 和 levelExp{current,next}
|
|
15
|
+
tarkov.dev 只给总经验,等级要拿 79 条经验表自己累加
|
|
16
|
+
|
|
17
|
+
立绘 eftforge 自带 character.full(Kitbash! 画的全身图)
|
|
18
|
+
tarkov.dev 要靠 imagemagic 现算,实测常年 503
|
|
19
|
+
|
|
20
|
+
时间 eftforge: stats.pmc.time(秒),比 tarkov.dev 的
|
|
21
|
+
totalInGameTime 更新(同一账号实测 171h vs 152h)
|
|
22
|
+
|
|
23
|
+
注意 `updated`:eftforge 的 `looked_up` 是"它什么时候查的",不是档案本身
|
|
24
|
+
的更新时间,拿来当新鲜度会误导用户,所以适配后故意留空、让卡片不显示那一条。
|
|
25
|
+
"""
|
|
26
|
+
|
|
27
|
+
from __future__ import annotations
|
|
28
|
+
|
|
29
|
+
from typing import Any, Dict, List, Optional, Tuple
|
|
30
|
+
|
|
31
|
+
# tarkov.dev 的 json 目录名 -> eftforge 的 mode 参数
|
|
32
|
+
MODES: Dict[str, str] = {
|
|
33
|
+
"regular": "pvp",
|
|
34
|
+
"pve": "pve",
|
|
35
|
+
"pvp-season": "season",
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def _int(value: Any, default: int = 0) -> int:
|
|
40
|
+
try:
|
|
41
|
+
return int(value)
|
|
42
|
+
except (TypeError, ValueError):
|
|
43
|
+
return default
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def _clean_name(value: Any) -> Optional[str]:
|
|
47
|
+
"""eftforge 的中文名里带换行("逃离塔科夫 \\n为了全人类"),压成一行。"""
|
|
48
|
+
if not isinstance(value, str):
|
|
49
|
+
return None
|
|
50
|
+
text = " ".join(value.split())
|
|
51
|
+
return text or None
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def _side(raw: Any) -> Dict[str, Any]:
|
|
55
|
+
"""把一侧(pmc/scav)的统计转成 tarkov.dev 的 overAllCounters 结构。"""
|
|
56
|
+
side = raw if isinstance(raw, dict) else {}
|
|
57
|
+
counters: List[Dict[str, Any]] = []
|
|
58
|
+
for entry in side.get("counters") or []:
|
|
59
|
+
if not isinstance(entry, (list, tuple)) or len(entry) != 2:
|
|
60
|
+
continue
|
|
61
|
+
key, value = entry
|
|
62
|
+
if not isinstance(key, (list, tuple)):
|
|
63
|
+
continue
|
|
64
|
+
counters.append({"Key": list(key), "Value": _int(value)})
|
|
65
|
+
return {
|
|
66
|
+
"overAllCounters": {"Items": counters},
|
|
67
|
+
# tarkov.dev 里叫 totalInGameTime,单位秒
|
|
68
|
+
"totalInGameTime": _int(side.get("time")),
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def character_path(raw: Dict[str, Any]) -> Optional[str]:
|
|
73
|
+
"""立绘地址(相对路径)。优先半身像 headshot,没有再退回全身 full。
|
|
74
|
+
|
|
75
|
+
headshot 是 320×320 的胸像(透明底),比 788×1238 的全身图更适合
|
|
76
|
+
卡片左栏那块接近正方形的区域,也不用为了适配大图缩得太小。
|
|
77
|
+
"""
|
|
78
|
+
character = raw.get("character") or {}
|
|
79
|
+
# 只用胸像:全身图塞进卡片左栏会被缩得很小,不如不放
|
|
80
|
+
path = character.get("headshot")
|
|
81
|
+
return path if isinstance(path, str) and path else None
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def level_of(raw: Dict[str, Any]) -> Dict[str, Any]:
|
|
85
|
+
"""给 fmt.render_player / build_card 用的等级结构。"""
|
|
86
|
+
level = raw.get("level")
|
|
87
|
+
return {"level": _int(level, 0) if level is not None else "?"}
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def progress_of(raw: Dict[str, Any]) -> Tuple[int, int]:
|
|
91
|
+
"""(本级已获得经验, 本级所需经验)。
|
|
92
|
+
|
|
93
|
+
eftforge 的 levelExp 给的是 {current: 本级起点总经验, next: 下一级总经验},
|
|
94
|
+
所以本级进度 = 总经验 - current,本级长度 = next - current。
|
|
95
|
+
"""
|
|
96
|
+
level_exp = raw.get("levelExp") or {}
|
|
97
|
+
current = _int(level_exp.get("current"))
|
|
98
|
+
nxt = _int(level_exp.get("next"))
|
|
99
|
+
experience = _int(raw.get("experience"))
|
|
100
|
+
if nxt <= current:
|
|
101
|
+
return 0, 0
|
|
102
|
+
return max(0, experience - current), nxt - current
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
def to_profile(raw: Dict[str, Any]) -> Tuple[Dict[str, Any], Dict[str, str]]:
|
|
106
|
+
"""eftforge 原始响应 -> (tarkov.dev 结构的 profile, 成就 id->名字)。
|
|
107
|
+
|
|
108
|
+
第二个返回值替代 tarkov.dev 的 tasks_en 名字表——eftforge 的成就
|
|
109
|
+
自带中英文名,省掉 2MB 的下载。
|
|
110
|
+
"""
|
|
111
|
+
stats = raw.get("stats") or {}
|
|
112
|
+
achievements: Dict[str, int] = {}
|
|
113
|
+
achievement_names: Dict[str, str] = {}
|
|
114
|
+
for item in ((raw.get("achievements") or {}).get("done")) or []:
|
|
115
|
+
if not isinstance(item, dict):
|
|
116
|
+
continue
|
|
117
|
+
aid = item.get("id")
|
|
118
|
+
if not aid:
|
|
119
|
+
continue
|
|
120
|
+
achievements[aid] = _int(item.get("at"))
|
|
121
|
+
name = _clean_name((item.get("ch") or {}).get("name")) or _clean_name(
|
|
122
|
+
(item.get("en") or {}).get("name")
|
|
123
|
+
)
|
|
124
|
+
if name:
|
|
125
|
+
achievement_names[aid] = name
|
|
126
|
+
|
|
127
|
+
skills: List[Dict[str, Any]] = []
|
|
128
|
+
for skill in ((raw.get("skills") or {}).get("common")) or []:
|
|
129
|
+
if not isinstance(skill, dict):
|
|
130
|
+
continue
|
|
131
|
+
skills.append(
|
|
132
|
+
{
|
|
133
|
+
"Id": skill.get("id"),
|
|
134
|
+
"LastAccess": _int(skill.get("lastAccess")),
|
|
135
|
+
"Progress": skill.get("progress"),
|
|
136
|
+
}
|
|
137
|
+
)
|
|
138
|
+
|
|
139
|
+
ending = raw.get("ending") or {}
|
|
140
|
+
reached = [
|
|
141
|
+
r.get("id")
|
|
142
|
+
for r in (raw.get("endingsReached") or [])
|
|
143
|
+
if isinstance(r, dict) and r.get("id")
|
|
144
|
+
]
|
|
145
|
+
current_ending = ending.get("id") if isinstance(ending, dict) else None
|
|
146
|
+
resolved = None
|
|
147
|
+
if isinstance(ending, dict):
|
|
148
|
+
resolved = _clean_name(ending.get("ch")) or _clean_name(ending.get("en"))
|
|
149
|
+
|
|
150
|
+
slots = raw.get("slots") or []
|
|
151
|
+
profile: Dict[str, Any] = {
|
|
152
|
+
"aid": _int(raw.get("accountId")),
|
|
153
|
+
"info": {
|
|
154
|
+
"nickname": raw.get("nickname") or "",
|
|
155
|
+
"side": raw.get("side") or "",
|
|
156
|
+
"experience": _int(raw.get("experience")),
|
|
157
|
+
"prestigeLevel": _int(raw.get("prestigeLevel")),
|
|
158
|
+
"memberCategory": raw.get("memberCategory"),
|
|
159
|
+
"selectedMemberCategory": raw.get("selectedMemberCategory"),
|
|
160
|
+
},
|
|
161
|
+
"pmcStats": {"eft": _side(stats.get("pmc"))},
|
|
162
|
+
"scavStats": {"eft": _side(stats.get("scav"))},
|
|
163
|
+
"achievements": achievements,
|
|
164
|
+
"skills": {"Common": skills},
|
|
165
|
+
# 只为让文字版能显示「装备 N 件」,明细在 slots 里
|
|
166
|
+
"equipment": {"Items": [{}] * len(slots)},
|
|
167
|
+
"ending": {
|
|
168
|
+
"current": current_ending,
|
|
169
|
+
# 系统名比 id 可靠:id→系统名的对照表拿不到,系统名能直接对上
|
|
170
|
+
"systemName": (ending or {}).get("systemName") if isinstance(ending, dict) else None,
|
|
171
|
+
"achieved": reached,
|
|
172
|
+
"resolved": resolved,
|
|
173
|
+
},
|
|
174
|
+
# 明确标注来源,方便日志和后续区分
|
|
175
|
+
"_source": "eftforge",
|
|
176
|
+
}
|
|
177
|
+
return profile, achievement_names
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"""结局(Ending)id / systemName -> 显示名。
|
|
2
|
+
|
|
3
|
+
档案里的结局有两个身份标识:
|
|
4
|
+
· id 24 位 Mongo id(tarkov.dev 和 eftforge 都会给)
|
|
5
|
+
· systemName 英文系统名(目前只有 eftforge 给)
|
|
6
|
+
|
|
7
|
+
游戏本体里一共四个结局(从 EscapeFromTarkov_Data 资源包里确认,
|
|
8
|
+
四个名字连续存放,正好对应官方的四种收尾):
|
|
9
|
+
|
|
10
|
+
EscapedFromTarkovForHumanity 救世主
|
|
11
|
+
EscapedFromTarkovAndSurvived 幸存者
|
|
12
|
+
EscapedFromTarkovToFallInTheDarkness 陨落之人
|
|
13
|
+
YouDidntEscapeFromYourself 旧债沉疴
|
|
14
|
+
|
|
15
|
+
tarkov.dev 只给 id、也不公开 id→系统名的对照表,所以 id 表只能覆盖实测
|
|
16
|
+
见过的那两个;systemName 表覆盖全部四个,eftforge 走的就是这条路。
|
|
17
|
+
补新结局时:优先补 systemName 表(一次到位),id 表按实测到的手填。
|
|
18
|
+
"""
|
|
19
|
+
|
|
20
|
+
from __future__ import annotations
|
|
21
|
+
|
|
22
|
+
from typing import Any, Dict, Optional
|
|
23
|
+
|
|
24
|
+
# id -> 简短中文名(tarkov.dev 数据源用)
|
|
25
|
+
ENDINGS: Dict[str, str] = {
|
|
26
|
+
# EscapedFromTarkovForHumanity
|
|
27
|
+
"68a6e8f1a7455e5e23099ad8": "救世主",
|
|
28
|
+
# YouDidntEscapeFromYourself
|
|
29
|
+
"68a6028ef4c23ebbbc49da4b": "旧债沉疴",
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
# systemName -> 简短中文名(eftforge 数据源用,四个全覆盖)
|
|
33
|
+
ENDING_SYSTEM_NAMES: Dict[str, str] = {
|
|
34
|
+
"EscapedFromTarkovForHumanity": "救世主",
|
|
35
|
+
"EscapedFromTarkovAndSurvived": "幸存者",
|
|
36
|
+
"EscapedFromTarkovToFallInTheDarkness": "陨落之人",
|
|
37
|
+
"YouDidntEscapeFromYourself": "旧债沉疴",
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def ending_name(
|
|
42
|
+
ending_id: Optional[str], system_name: Optional[str] = None
|
|
43
|
+
) -> Optional[str]:
|
|
44
|
+
"""按 systemName 优先、id 兜底查名字,查不到给「未知结局(前 8 位)」。"""
|
|
45
|
+
if system_name:
|
|
46
|
+
known = ENDING_SYSTEM_NAMES.get(str(system_name).strip())
|
|
47
|
+
if known:
|
|
48
|
+
return known
|
|
49
|
+
key = str(ending_id or "").strip()
|
|
50
|
+
if key:
|
|
51
|
+
known = ENDINGS.get(key)
|
|
52
|
+
if known:
|
|
53
|
+
return known
|
|
54
|
+
return f"未知结局({key[:8]}…)"
|
|
55
|
+
if system_name:
|
|
56
|
+
return str(system_name)
|
|
57
|
+
return None
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def ending_label(profile: Dict[str, Any]) -> Optional[str]:
|
|
61
|
+
"""从档案里取「当前结局」。没打通剧情线返回 None。
|
|
62
|
+
|
|
63
|
+
结构是 {"current": id|null, "achieved": [id, ...]},
|
|
64
|
+
eftforge 适配后还会多带 systemName 和 resolved(数据源给的名字)。
|
|
65
|
+
current 为空但 achieved 非空时取最后一个已达成的(防御性处理)。
|
|
66
|
+
"""
|
|
67
|
+
ending = profile.get("ending")
|
|
68
|
+
if not isinstance(ending, dict):
|
|
69
|
+
return None
|
|
70
|
+
|
|
71
|
+
system_name = ending.get("systemName")
|
|
72
|
+
current = ending.get("current") or ending.get("display")
|
|
73
|
+
if current or system_name:
|
|
74
|
+
named = ending_name(current, system_name)
|
|
75
|
+
if named:
|
|
76
|
+
return named
|
|
77
|
+
|
|
78
|
+
achieved = ending.get("achieved") or []
|
|
79
|
+
if isinstance(achieved, list) and achieved:
|
|
80
|
+
return ending_name(achieved[-1])
|
|
81
|
+
|
|
82
|
+
# 数据源直接给了名字(现在只有 eftforge 会带 resolved)
|
|
83
|
+
resolved = ending.get("resolved")
|
|
84
|
+
if isinstance(resolved, str) and resolved.strip():
|
|
85
|
+
return " ".join(resolved.split())
|
|
86
|
+
return None
|
|
@@ -0,0 +1,339 @@
|
|
|
1
|
+
"""把 tarkov.dev 的数据渲染成适合聊天的文本。
|
|
2
|
+
|
|
3
|
+
全是纯函数,不依赖 NoneBot,方便单独测试。
|
|
4
|
+
输出刻意避开 Discord 专有语法(markdown 链接、<t:...:R> 时间戳、embed 字段),
|
|
5
|
+
换成 QQ 里能正常显示的纯文本。
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
import time
|
|
11
|
+
from datetime import datetime
|
|
12
|
+
from typing import Any, Dict, List, Optional
|
|
13
|
+
|
|
14
|
+
from .api import STATUS_LABELS
|
|
15
|
+
from .endings import ending_label
|
|
16
|
+
|
|
17
|
+
WIDTH = 34
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def _bar(ratio: float, width: int = 12) -> str:
|
|
21
|
+
"""简单的进度条。"""
|
|
22
|
+
ratio = max(0.0, min(1.0, ratio))
|
|
23
|
+
filled = int(round(ratio * width))
|
|
24
|
+
return "█" * filled + "░" * (width - filled)
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def _fmt_ago(ts_seconds: float, *, now: Optional[float] = None) -> str:
|
|
28
|
+
"""把时间戳描述成「x 分钟前」这种相对时间(替代 Discord 的 <t:...:R>)。"""
|
|
29
|
+
now = now if now is not None else time.time()
|
|
30
|
+
delta = now - ts_seconds
|
|
31
|
+
if delta < 0:
|
|
32
|
+
return "刚刚"
|
|
33
|
+
if delta < 60:
|
|
34
|
+
return f"{int(delta)} 秒前"
|
|
35
|
+
if delta < 3600:
|
|
36
|
+
return f"{int(delta // 60)} 分钟前"
|
|
37
|
+
if delta < 86400:
|
|
38
|
+
return f"{delta / 3600:.1f} 小时前"
|
|
39
|
+
return f"{delta / 86400:.1f} 天前"
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def _fmt_ts(ts_seconds: float) -> str:
|
|
43
|
+
return datetime.fromtimestamp(ts_seconds).strftime("%Y-%m-%d %H:%M")
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
# ------------------------------------------------------------------ status
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def render_status(data: Dict[str, Any], *, now: Optional[float] = None) -> str:
|
|
50
|
+
"""渲染 /eftstatus。对应 commands/status.mjs。"""
|
|
51
|
+
statuses = data.get("currentStatuses") or []
|
|
52
|
+
general = data.get("generalStatus") or {}
|
|
53
|
+
|
|
54
|
+
lines: List[str] = ["🎮 逃离塔科夫 服务器状态", ""]
|
|
55
|
+
|
|
56
|
+
if general:
|
|
57
|
+
code = int(general.get("status", 0))
|
|
58
|
+
label = STATUS_LABELS[code] if 0 <= code < len(STATUS_LABELS) else f"未知({code})"
|
|
59
|
+
lines.append(f"🌐 整体:{label}")
|
|
60
|
+
msg = (general.get("message") or "").strip()
|
|
61
|
+
if msg:
|
|
62
|
+
lines.append(f" {msg}")
|
|
63
|
+
lines.append("")
|
|
64
|
+
|
|
65
|
+
# currentStatuses 里最后一条通常是 Global,与 generalStatus 重复,去掉
|
|
66
|
+
items = [s for s in statuses if s.get("name") != "Global"]
|
|
67
|
+
if items:
|
|
68
|
+
lines.append("📡 各项服务:")
|
|
69
|
+
for item in items:
|
|
70
|
+
code = int(item.get("status", 0))
|
|
71
|
+
label = STATUS_LABELS[code] if 0 <= code < len(STATUS_LABELS) else f"未知({code})"
|
|
72
|
+
lines.append(f" {label} {item.get('name', '?')}")
|
|
73
|
+
lines.append("")
|
|
74
|
+
|
|
75
|
+
for message in data.get("messages") or []:
|
|
76
|
+
content = (message or {}).get("content")
|
|
77
|
+
if content:
|
|
78
|
+
lines.append(f"📢 {content}")
|
|
79
|
+
lines.append("")
|
|
80
|
+
|
|
81
|
+
lines.append("🔗 status.escapefromtarkov.com")
|
|
82
|
+
return "\n".join(lines).rstrip()
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
# ------------------------------------------------------------------ player
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def _side_stats(raw: Dict[str, Any]) -> Dict[str, Any]:
|
|
89
|
+
"""把 profile 里 overAllCounters 那坨 Items 抽成好用的字段。
|
|
90
|
+
|
|
91
|
+
对应 player.mjs:179-190。用「Key 里包含关键词」来匹配,
|
|
92
|
+
因为原始 key 形如 "Eft/Total/Sessions"。
|
|
93
|
+
"""
|
|
94
|
+
counters = ((raw or {}).get("overAllCounters") or {}).get("Items") or []
|
|
95
|
+
|
|
96
|
+
def pick(keyword: str) -> int:
|
|
97
|
+
for entry in counters:
|
|
98
|
+
if keyword in (entry.get("Key") or ""):
|
|
99
|
+
return int(entry.get("Value") or 0)
|
|
100
|
+
return 0
|
|
101
|
+
|
|
102
|
+
raids = pick("Sessions")
|
|
103
|
+
survived = pick("Survived")
|
|
104
|
+
died = pick("Killed")
|
|
105
|
+
kills = pick("Kills")
|
|
106
|
+
return {
|
|
107
|
+
"raids": raids,
|
|
108
|
+
"survived": survived,
|
|
109
|
+
"died": died,
|
|
110
|
+
"kills": kills,
|
|
111
|
+
"surv_rate": survived / raids if raids else 0.0,
|
|
112
|
+
"death_rate": died / raids if raids else 0.0,
|
|
113
|
+
"kd": (kills / died) if died else None, # None 表示无穷大
|
|
114
|
+
"streak": pick("LongestWinStreak"),
|
|
115
|
+
"hours": round((raw or {}).get("totalInGameTime", 0) / 3600, 1),
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
def _fmt_side(label: str, icon: str, s: Dict[str, Any]) -> List[str]:
|
|
120
|
+
kd = "N/A" if s["kd"] is None else f"{s['kd']:.2f}"
|
|
121
|
+
return [
|
|
122
|
+
f"{icon} {label}",
|
|
123
|
+
f" 场次 {s['raids']} 存活 {s['surv_rate']:.1%} ({s['survived']}/{s['raids']})"
|
|
124
|
+
f" 死亡 {s['death_rate']:.1%} ({s['died']}/{s['raids']})",
|
|
125
|
+
f" K/D {kd} ({s['kills']}杀/{s['died']}死) 最长连活 {s['streak']}",
|
|
126
|
+
]
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
def render_player(
|
|
130
|
+
profile: Dict[str, Any],
|
|
131
|
+
*,
|
|
132
|
+
mode_label: str,
|
|
133
|
+
folder: str,
|
|
134
|
+
experience_level: Dict[str, Any],
|
|
135
|
+
progress: tuple[int, int],
|
|
136
|
+
achievements: Dict[str, str],
|
|
137
|
+
max_achievements: int = 10,
|
|
138
|
+
now: Optional[float] = None,
|
|
139
|
+
) -> str:
|
|
140
|
+
"""渲染玩家资料。对应 commands/player.mjs 的 embed 组装部分。"""
|
|
141
|
+
info = profile.get("info") or {}
|
|
142
|
+
nickname = (info.get("nickname") or "").strip()
|
|
143
|
+
if not nickname:
|
|
144
|
+
# 索引里实测有 32 个空昵称账号,做个兜底
|
|
145
|
+
nickname = f"(无名账号 {profile.get('aid')})"
|
|
146
|
+
|
|
147
|
+
level_no = experience_level.get("level", "?")
|
|
148
|
+
gained, need = progress
|
|
149
|
+
ratio = (gained / need) if need else 0.0
|
|
150
|
+
|
|
151
|
+
lines: List[str] = [
|
|
152
|
+
f"📋 {nickname}",
|
|
153
|
+
f"模式:{mode_label} 等级 {level_no} {info.get('side', '?')}"
|
|
154
|
+
+ (f" 转生 {info['prestigeLevel']}" if info.get("prestigeLevel") else ""),
|
|
155
|
+
f"EXP {info.get('experience', 0):,}",
|
|
156
|
+
]
|
|
157
|
+
if need:
|
|
158
|
+
lines.append(f" {_bar(ratio)} {gained:,}/{need:,} ({ratio:.1%})")
|
|
159
|
+
lines.append("")
|
|
160
|
+
|
|
161
|
+
lines += _fmt_side("PMC", "🔫", _side_stats((profile.get("pmcStats") or {}).get("eft") or {}))
|
|
162
|
+
lines.append("")
|
|
163
|
+
lines += _fmt_side("Scav", "🎒", _side_stats((profile.get("scavStats") or {}).get("eft") or {}))
|
|
164
|
+
lines.append("")
|
|
165
|
+
|
|
166
|
+
# 游戏时长是账号级的,PMC/Scav 显示相同,所以只展示一次
|
|
167
|
+
hours = _side_stats((profile.get("pmcStats") or {}).get("eft") or {})["hours"]
|
|
168
|
+
if hours:
|
|
169
|
+
lines.append(f"⏱ 游戏时长 {hours} 小时")
|
|
170
|
+
|
|
171
|
+
# 成就
|
|
172
|
+
done = [
|
|
173
|
+
(achievements.get(aid, aid), ts)
|
|
174
|
+
for aid, ts in (profile.get("achievements") or {}).items()
|
|
175
|
+
]
|
|
176
|
+
if done:
|
|
177
|
+
lines.append(f"🏅 成就 {len(done)} 个")
|
|
178
|
+
for name, ts in sorted(done, key=lambda x: x[1])[:max_achievements]:
|
|
179
|
+
lines.append(f" · {name} ({datetime.fromtimestamp(ts):%Y-%m-%d})")
|
|
180
|
+
if len(done) > max_achievements:
|
|
181
|
+
lines.append(f" … 还有 {len(done) - max_achievements} 个")
|
|
182
|
+
else:
|
|
183
|
+
lines.append("🏅 成就 0 个")
|
|
184
|
+
|
|
185
|
+
lines.append("")
|
|
186
|
+
|
|
187
|
+
# 结局:只有打通剧情线的号才有
|
|
188
|
+
ending = ending_label(profile)
|
|
189
|
+
if ending:
|
|
190
|
+
lines.append(f"🎬 结局 {ending}")
|
|
191
|
+
|
|
192
|
+
# 最后活跃
|
|
193
|
+
last_active = 0
|
|
194
|
+
for skill in (profile.get("skills") or {}).get("Common") or []:
|
|
195
|
+
last_active = max(last_active, int(skill.get("LastAccess") or 0))
|
|
196
|
+
if last_active:
|
|
197
|
+
lines.append(f"🕐 最后活跃 {_fmt_ts(last_active)}")
|
|
198
|
+
|
|
199
|
+
updated = profile.get("updated")
|
|
200
|
+
if updated:
|
|
201
|
+
lines.append(f"🔄 数据更新 {_fmt_ago(updated / 1000, now=now)}")
|
|
202
|
+
|
|
203
|
+
equipment = (profile.get("equipment") or {}).get("Items") or []
|
|
204
|
+
if equipment:
|
|
205
|
+
lines.append(f"🎽 装备 {len(equipment)} 件")
|
|
206
|
+
|
|
207
|
+
aid = profile.get("aid")
|
|
208
|
+
lines.append(f"🔗 tarkov.dev/players/{folder}/{aid}")
|
|
209
|
+
return "\n".join(lines).rstrip()
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
def render_not_found(aid: int, mode_label: str) -> str:
|
|
213
|
+
return (
|
|
214
|
+
f"❌ 没有找到账号 {aid} 在 {mode_label} 模式下的资料\n\n"
|
|
215
|
+
"可能的原因:\n"
|
|
216
|
+
" · 角色 ID 写错了(ID 是一串纯数字)\n"
|
|
217
|
+
" · 该账号没在这个模式下玩过\n"
|
|
218
|
+
" · 资料需要在 tarkov.dev/players 上被查看过才会收录,"
|
|
219
|
+
"首次查看后最长可能要 24 小时\n\n"
|
|
220
|
+
f"🔗 tarkov.dev/players/{mode_label}"
|
|
221
|
+
)
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
def render_index_reload_start(targets_desc: str) -> str:
|
|
225
|
+
return (
|
|
226
|
+
f"⏳ 开始更新昵称索引:{targets_desc}\n"
|
|
227
|
+
" regular 有 67MB,可能要十几秒,稍等…"
|
|
228
|
+
)
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
def render_index_reload_result(rows: list, *, skipped: list = None) -> str:
|
|
232
|
+
"""rows: [(模式标签, 是否成功, 耗时秒, 旧大小MB, 新大小MB, 条目数)]"""
|
|
233
|
+
skipped = skipped or []
|
|
234
|
+
ok = sum(1 for r in rows if r[1])
|
|
235
|
+
lines = [f"✅ 昵称索引更新完成(成功 {ok}/{len(rows)})", ""]
|
|
236
|
+
for label, success, secs, before, after, count in rows:
|
|
237
|
+
mark = "✅" if success else "❌ 失败(保留旧库)"
|
|
238
|
+
size = f"{before:.1f} → {after:.1f} MB" if before != after else f"{after:.1f} MB"
|
|
239
|
+
lines.append(f" {mark} {label} {secs:.1f}s {size} {count} 条")
|
|
240
|
+
if skipped:
|
|
241
|
+
lines.append("")
|
|
242
|
+
lines.append(f" 跳过(尚未使用过):{'、'.join(skipped)}")
|
|
243
|
+
lines.append("")
|
|
244
|
+
lines.append(" 提示:不带参数只刷新已存在的索引;指定模式可强制新建。")
|
|
245
|
+
return "\n".join(lines)
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
def render_usage() -> str:
|
|
249
|
+
return (
|
|
250
|
+
"📖 /player 用法\n\n"
|
|
251
|
+
" /player <模式> <角色ID 或 昵称>\n\n"
|
|
252
|
+
"模式:\n"
|
|
253
|
+
" pvp → PvP 正式服 (regular)\n"
|
|
254
|
+
" pvps → PvP 赛季 (pvp-season)\n"
|
|
255
|
+
" pve → PvE\n\n"
|
|
256
|
+
"示例:\n"
|
|
257
|
+
" /player pve 14064081\n"
|
|
258
|
+
" /player pve xL1gHTx\n"
|
|
259
|
+
" /player pvp Buhaus\n\n"
|
|
260
|
+
"角色 ID 是纯数字,可在 tarkov.dev/players 查到。\n"
|
|
261
|
+
"用昵称搜索时若命中多个账号,会列出候选让你选。"
|
|
262
|
+
)
|
|
263
|
+
|
|
264
|
+
|
|
265
|
+
# ------------------------------------------------------------ 昵称搜索
|
|
266
|
+
|
|
267
|
+
|
|
268
|
+
def render_index_building() -> str:
|
|
269
|
+
return "⏳ 首次使用昵称搜索,需要下载玩家索引(约 67MB),可能要等十几秒…"
|
|
270
|
+
|
|
271
|
+
|
|
272
|
+
def render_index_refreshing_wait() -> str:
|
|
273
|
+
return "🔍 本地索引有点旧,正在更新后重试…"
|
|
274
|
+
|
|
275
|
+
|
|
276
|
+
def render_index_refreshing_slow() -> str:
|
|
277
|
+
return (
|
|
278
|
+
"⏳ 本地索引正在更新,还没下完\n\n"
|
|
279
|
+
"更新会在后台继续,过一会儿再发一次就行。"
|
|
280
|
+
)
|
|
281
|
+
|
|
282
|
+
|
|
283
|
+
def render_index_failed(name: str) -> str:
|
|
284
|
+
return (
|
|
285
|
+
f"❌ 玩家索引下载失败,暂时没法按昵称搜索「{name}」\n\n"
|
|
286
|
+
"可以直接用角色 ID 查询:\n"
|
|
287
|
+
" /player <模式> <角色ID>"
|
|
288
|
+
)
|
|
289
|
+
|
|
290
|
+
|
|
291
|
+
def render_no_match(name: str, mode_label: str) -> str:
|
|
292
|
+
return (
|
|
293
|
+
f"🔍 在 {mode_label} 模式里没找到昵称含「{name}」的账号\n\n"
|
|
294
|
+
"可能的原因:\n"
|
|
295
|
+
" · 昵称拼错了(大小写不敏感,但要拼对)\n"
|
|
296
|
+
" · 该账号没在这个模式下玩过\n"
|
|
297
|
+
" · **刚被扫描出来的新账号**:档案是扫到就写,但昵称索引上游"
|
|
298
|
+
"每天只重建一次,所以最长要等一天才能按名字查到\n"
|
|
299
|
+
" · 资料需要在 tarkov.dev/players 上被查看过才会收录\n\n"
|
|
300
|
+
"💡 如果知道角色 ID,直接用 ID 查询不受索引影响:\n"
|
|
301
|
+
" /player <模式> <角色ID>"
|
|
302
|
+
)
|
|
303
|
+
|
|
304
|
+
|
|
305
|
+
def render_candidates(
|
|
306
|
+
name: str,
|
|
307
|
+
rows: list,
|
|
308
|
+
mode_label: str,
|
|
309
|
+
*,
|
|
310
|
+
kind: str = "",
|
|
311
|
+
ask: bool = True,
|
|
312
|
+
) -> str:
|
|
313
|
+
"""列出候选账号。
|
|
314
|
+
|
|
315
|
+
rows 是 [(aid, name), ...]。`ask=True` 时提示可以回复序号。
|
|
316
|
+
"""
|
|
317
|
+
n = len(rows)
|
|
318
|
+
title = f"🔍 「{name}」在 {mode_label} 模式下找到 {n} 个账号"
|
|
319
|
+
if kind == "exact":
|
|
320
|
+
title += "(昵称完全相同)"
|
|
321
|
+
elif kind == "prefix":
|
|
322
|
+
title += "(昵称以它开头)"
|
|
323
|
+
else:
|
|
324
|
+
title += "(昵称包含它)"
|
|
325
|
+
|
|
326
|
+
lines = [title, ""]
|
|
327
|
+
for i, (aid, nick) in enumerate(rows, 1):
|
|
328
|
+
lines.append(f" {i}. {nick} (ID {aid})")
|
|
329
|
+
lines.append("")
|
|
330
|
+
if ask:
|
|
331
|
+
lines.append(f"回复序号 1-{n} 直接查看,或直接用 ID 查询:")
|
|
332
|
+
else:
|
|
333
|
+
lines.append("直接用 ID 查询:")
|
|
334
|
+
lines.append(f" /player <模式> {rows[0][0]}")
|
|
335
|
+
return "\n".join(lines)
|
|
336
|
+
|
|
337
|
+
|
|
338
|
+
def render_bad_choice(n: int) -> str:
|
|
339
|
+
return f"❌ 请回复 1-{n} 之间的序号"
|