koishi-plugin-steam-info-check 1.0.9 → 1.1.0
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.
- package/dist/index.d.ts +1 -0
- package/dist/index.js +109 -40
- package/dist/locales/zh-CN.d.ts +25 -0
- package/dist/locales/zh-CN.js +25 -0
- package/nonebot-plugin-steam-info-main/.github/actions/setup-python/action.yml +21 -0
- package/nonebot-plugin-steam-info-main/.github/workflows/release.yml +37 -0
- package/nonebot-plugin-steam-info-main/LICENSE +21 -0
- package/nonebot-plugin-steam-info-main/README.md +117 -0
- package/nonebot-plugin-steam-info-main/fonts/MiSans-Bold.ttf +0 -0
- package/nonebot-plugin-steam-info-main/fonts/MiSans-Light.ttf +0 -0
- package/nonebot-plugin-steam-info-main/fonts/MiSans-Regular.ttf +0 -0
- package/nonebot-plugin-steam-info-main/nonebot_plugin_steam_info/__init__.py +487 -0
- package/nonebot-plugin-steam-info-main/nonebot_plugin_steam_info/config.py +19 -0
- package/nonebot-plugin-steam-info-main/nonebot_plugin_steam_info/data_source.py +264 -0
- package/nonebot-plugin-steam-info-main/nonebot_plugin_steam_info/draw.py +921 -0
- package/nonebot-plugin-steam-info-main/nonebot_plugin_steam_info/models.py +82 -0
- package/nonebot-plugin-steam-info-main/nonebot_plugin_steam_info/res/bg_dots.png +0 -0
- package/nonebot-plugin-steam-info-main/nonebot_plugin_steam_info/res/busy.png +0 -0
- package/nonebot-plugin-steam-info-main/nonebot_plugin_steam_info/res/default_achievement_image.png +0 -0
- package/nonebot-plugin-steam-info-main/nonebot_plugin_steam_info/res/default_header_image.jpg +0 -0
- package/nonebot-plugin-steam-info-main/nonebot_plugin_steam_info/res/friends_search.png +0 -0
- package/nonebot-plugin-steam-info-main/nonebot_plugin_steam_info/res/gaming.png +0 -0
- package/nonebot-plugin-steam-info-main/nonebot_plugin_steam_info/res/parent_status.png +0 -0
- package/nonebot-plugin-steam-info-main/nonebot_plugin_steam_info/res/unknown_avatar.jpg +0 -0
- package/nonebot-plugin-steam-info-main/nonebot_plugin_steam_info/res/zzz_gaming.png +0 -0
- package/nonebot-plugin-steam-info-main/nonebot_plugin_steam_info/res/zzz_online.png +0 -0
- package/nonebot-plugin-steam-info-main/nonebot_plugin_steam_info/steam.py +259 -0
- package/nonebot-plugin-steam-info-main/nonebot_plugin_steam_info/utils.py +112 -0
- package/nonebot-plugin-steam-info-main/pdm.lock +966 -0
- package/nonebot-plugin-steam-info-main/preview.png +0 -0
- package/nonebot-plugin-steam-info-main/preview_1.png +0 -0
- package/nonebot-plugin-steam-info-main/preview_2.png +0 -0
- package/nonebot-plugin-steam-info-main/pyproject.toml +29 -0
- package/package.json +1 -1
- package/src/index.ts +83 -42
- package/src/locales/zh-CN.ts +25 -0
- package/src/locales/zh-CN.yml +2 -1
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
import json
|
|
2
|
+
import time
|
|
3
|
+
from PIL import Image
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
from typing import Any, List, Dict, Optional, Tuple
|
|
6
|
+
|
|
7
|
+
from .models import Player, ProcessedPlayer
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class BindData:
|
|
11
|
+
def __init__(self, save_path: Path) -> None:
|
|
12
|
+
self.content: Dict[str, List[Dict[str, str]]] = {}
|
|
13
|
+
self._save_path = save_path
|
|
14
|
+
|
|
15
|
+
if save_path.exists():
|
|
16
|
+
self.content = json.loads(Path(save_path).read_text("utf-8"))
|
|
17
|
+
else:
|
|
18
|
+
self.save()
|
|
19
|
+
|
|
20
|
+
def save(self) -> None:
|
|
21
|
+
with open(self._save_path, "w", encoding="utf-8") as f:
|
|
22
|
+
json.dump(self.content, f, indent=4)
|
|
23
|
+
|
|
24
|
+
def add(self, parent_id: str, content: Dict[str, str]) -> None:
|
|
25
|
+
if parent_id not in self.content:
|
|
26
|
+
self.content[parent_id] = [content]
|
|
27
|
+
else:
|
|
28
|
+
self.content[parent_id].append(content)
|
|
29
|
+
|
|
30
|
+
def remove(self, parent_id: str, user_id: str) -> None:
|
|
31
|
+
if parent_id not in self.content:
|
|
32
|
+
return
|
|
33
|
+
for data in self.content[parent_id]:
|
|
34
|
+
if data["user_id"] == user_id:
|
|
35
|
+
self.content[parent_id].remove(data)
|
|
36
|
+
break
|
|
37
|
+
|
|
38
|
+
def update(self, parent_id: str, content: Dict[str, str]) -> None:
|
|
39
|
+
self.content[parent_id] = content
|
|
40
|
+
|
|
41
|
+
def get(self, parent_id: str, user_id: str) -> Optional[Dict[str, str]]:
|
|
42
|
+
if parent_id not in self.content:
|
|
43
|
+
return None
|
|
44
|
+
for data in self.content[parent_id]:
|
|
45
|
+
if data["user_id"] == user_id:
|
|
46
|
+
if not data.get("nickname"):
|
|
47
|
+
data["nickname"] = None
|
|
48
|
+
return data
|
|
49
|
+
return None
|
|
50
|
+
|
|
51
|
+
def get_by_steam_id(
|
|
52
|
+
self, parent_id: str, steam_id: str
|
|
53
|
+
) -> Optional[Dict[str, str]]:
|
|
54
|
+
if parent_id not in self.content:
|
|
55
|
+
return None
|
|
56
|
+
for data in self.content[parent_id]:
|
|
57
|
+
if data["steam_id"] == steam_id:
|
|
58
|
+
if not data.get("nickname"):
|
|
59
|
+
data["nickname"] = None
|
|
60
|
+
return data
|
|
61
|
+
return None
|
|
62
|
+
|
|
63
|
+
def get_all(self, parent_id: str) -> List[str]:
|
|
64
|
+
if parent_id not in self.content:
|
|
65
|
+
return []
|
|
66
|
+
|
|
67
|
+
result = []
|
|
68
|
+
|
|
69
|
+
for data in self.content[parent_id]:
|
|
70
|
+
if not data["steam_id"] in result:
|
|
71
|
+
result.append(data["steam_id"])
|
|
72
|
+
|
|
73
|
+
return result
|
|
74
|
+
|
|
75
|
+
def get_all_steam_id(self) -> List[str]:
|
|
76
|
+
result = []
|
|
77
|
+
for parent_id in self.content:
|
|
78
|
+
for data in self.content[parent_id]:
|
|
79
|
+
if not data["steam_id"] in result:
|
|
80
|
+
result.append(data["steam_id"])
|
|
81
|
+
return result
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
class SteamInfoData:
|
|
85
|
+
def __init__(self, save_path: Path) -> None:
|
|
86
|
+
self.content: List[ProcessedPlayer] = []
|
|
87
|
+
self._save_path = save_path
|
|
88
|
+
|
|
89
|
+
if save_path.exists():
|
|
90
|
+
self.content = json.loads(save_path.read_text("utf-8"))
|
|
91
|
+
if isinstance(self.content, dict):
|
|
92
|
+
self.content = []
|
|
93
|
+
self.save()
|
|
94
|
+
else:
|
|
95
|
+
self.save()
|
|
96
|
+
|
|
97
|
+
def save(self) -> None:
|
|
98
|
+
with open(self._save_path, "w", encoding="utf-8") as f:
|
|
99
|
+
json.dump(self.content, f, indent=4)
|
|
100
|
+
|
|
101
|
+
def update(self, player: ProcessedPlayer) -> None:
|
|
102
|
+
self.content.append(player)
|
|
103
|
+
|
|
104
|
+
def update_by_players(self, players: List[Player]):
|
|
105
|
+
# 将 Player 转换为 ProcessedPlayer
|
|
106
|
+
processed_players = []
|
|
107
|
+
for player in players:
|
|
108
|
+
old_player = self.get_player(player["steamid"])
|
|
109
|
+
|
|
110
|
+
if old_player is None:
|
|
111
|
+
if player.get("gameextrainfo") is not None:
|
|
112
|
+
player["game_start_time"] = int(time.time())
|
|
113
|
+
else:
|
|
114
|
+
player["game_start_time"] = None
|
|
115
|
+
processed_players.append(player)
|
|
116
|
+
else:
|
|
117
|
+
if (
|
|
118
|
+
player.get("gameextrainfo") is not None
|
|
119
|
+
and old_player.get("gameextrainfo") is None
|
|
120
|
+
):
|
|
121
|
+
# 开始游戏
|
|
122
|
+
player["game_start_time"] = int(time.time())
|
|
123
|
+
elif (
|
|
124
|
+
player.get("gameextrainfo") is None
|
|
125
|
+
and old_player.get("gameextrainfo") is not None
|
|
126
|
+
):
|
|
127
|
+
# 结束游戏
|
|
128
|
+
player["game_start_time"] = None
|
|
129
|
+
elif (
|
|
130
|
+
player.get("gameextrainfo") is not None
|
|
131
|
+
and old_player.get("gameextrainfo") is not None
|
|
132
|
+
):
|
|
133
|
+
if player.get("gameextrainfo") != old_player.get("gameextrainfo"):
|
|
134
|
+
# 切换游戏
|
|
135
|
+
player["game_start_time"] = int(time.time())
|
|
136
|
+
else:
|
|
137
|
+
# 继续游戏
|
|
138
|
+
player["game_start_time"] = old_player["game_start_time"]
|
|
139
|
+
else:
|
|
140
|
+
player["game_start_time"] = None
|
|
141
|
+
processed_players.append(player)
|
|
142
|
+
|
|
143
|
+
self.content = processed_players
|
|
144
|
+
|
|
145
|
+
def get_player(self, steam_id: str) -> Optional[Player]:
|
|
146
|
+
for player in self.content:
|
|
147
|
+
if player["steamid"] == steam_id:
|
|
148
|
+
return player
|
|
149
|
+
return None
|
|
150
|
+
|
|
151
|
+
def get_players(self, steam_ids: List[str]) -> List[Player]:
|
|
152
|
+
result = []
|
|
153
|
+
for player in self.content:
|
|
154
|
+
if player["steamid"] in steam_ids:
|
|
155
|
+
result.append(player)
|
|
156
|
+
return result
|
|
157
|
+
|
|
158
|
+
def compare(
|
|
159
|
+
self, old_players: List[Player], new_players: List[Player]
|
|
160
|
+
) -> List[Dict[str, Any]]:
|
|
161
|
+
result = []
|
|
162
|
+
|
|
163
|
+
for player in new_players:
|
|
164
|
+
for old_player in old_players:
|
|
165
|
+
if player["steamid"] == old_player["steamid"]:
|
|
166
|
+
if player.get("gameextrainfo") != old_player.get("gameextrainfo"):
|
|
167
|
+
if (
|
|
168
|
+
player.get("gameextrainfo") is not None
|
|
169
|
+
and old_player.get("gameextrainfo") is not None
|
|
170
|
+
):
|
|
171
|
+
result.append(
|
|
172
|
+
{
|
|
173
|
+
"type": "change",
|
|
174
|
+
"player": player,
|
|
175
|
+
"old_player": old_player,
|
|
176
|
+
}
|
|
177
|
+
)
|
|
178
|
+
elif old_player.get("gameextrainfo") is not None:
|
|
179
|
+
result.append(
|
|
180
|
+
{
|
|
181
|
+
"type": "stop",
|
|
182
|
+
"player": player,
|
|
183
|
+
"old_player": old_player,
|
|
184
|
+
}
|
|
185
|
+
)
|
|
186
|
+
elif player.get("gameextrainfo") is not None :
|
|
187
|
+
result.append(
|
|
188
|
+
{
|
|
189
|
+
"type": "start",
|
|
190
|
+
"player": player,
|
|
191
|
+
"old_player": old_player,
|
|
192
|
+
}
|
|
193
|
+
)
|
|
194
|
+
else:
|
|
195
|
+
result.append(
|
|
196
|
+
{
|
|
197
|
+
"type": "error",
|
|
198
|
+
"player": player,
|
|
199
|
+
"old_player": old_player,
|
|
200
|
+
}
|
|
201
|
+
)
|
|
202
|
+
return result
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
class ParentData:
|
|
206
|
+
def __init__(self, save_path: Path) -> None:
|
|
207
|
+
self.content: Dict[str, str] = {} # parent_id: name
|
|
208
|
+
self._save_path = save_path
|
|
209
|
+
|
|
210
|
+
if not save_path.exists():
|
|
211
|
+
save_path.parent.mkdir(parents=True, exist_ok=True)
|
|
212
|
+
self.save()
|
|
213
|
+
else:
|
|
214
|
+
self.content = json.loads(save_path.read_text("utf-8"))
|
|
215
|
+
|
|
216
|
+
def save(self) -> None:
|
|
217
|
+
with open(self._save_path, "w", encoding="utf-8") as f:
|
|
218
|
+
json.dump(self.content, f, indent=4)
|
|
219
|
+
|
|
220
|
+
def update(self, parent_id: str, avatar: Image.Image, name: str) -> None:
|
|
221
|
+
self.content[parent_id] = name
|
|
222
|
+
self.save()
|
|
223
|
+
# 保存图片
|
|
224
|
+
avatar_path = self._save_path.parent / f"{parent_id}.png"
|
|
225
|
+
avatar.save(avatar_path)
|
|
226
|
+
|
|
227
|
+
def get(self, parent_id: str) -> Tuple[Image.Image, str]:
|
|
228
|
+
if parent_id not in self.content:
|
|
229
|
+
return (
|
|
230
|
+
Image.open(Path(__file__).parent / "res/unknown_avatar.jpg"),
|
|
231
|
+
parent_id,
|
|
232
|
+
)
|
|
233
|
+
avatar_path = self._save_path.parent / f"{parent_id}.png"
|
|
234
|
+
return Image.open(avatar_path), self.content[parent_id]
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
class DisableParentData:
|
|
238
|
+
"""储存禁用 Steam 通知的 parent"""
|
|
239
|
+
|
|
240
|
+
def __init__(self, save_path: Path) -> None:
|
|
241
|
+
self.content: List[str] = []
|
|
242
|
+
self._save_path = save_path
|
|
243
|
+
|
|
244
|
+
if save_path.exists():
|
|
245
|
+
self.content = json.loads(save_path.read_text("utf-8"))
|
|
246
|
+
else:
|
|
247
|
+
self.save()
|
|
248
|
+
|
|
249
|
+
def save(self) -> None:
|
|
250
|
+
with open(self._save_path, "w", encoding="utf-8") as f:
|
|
251
|
+
json.dump(self.content, f, indent=4)
|
|
252
|
+
|
|
253
|
+
def add(self, parent_id: str) -> None:
|
|
254
|
+
if parent_id not in self.content:
|
|
255
|
+
self.content.append(parent_id)
|
|
256
|
+
self.save()
|
|
257
|
+
|
|
258
|
+
def remove(self, parent_id: str) -> None:
|
|
259
|
+
if parent_id in self.content:
|
|
260
|
+
self.content.remove(parent_id)
|
|
261
|
+
self.save()
|
|
262
|
+
|
|
263
|
+
def is_disabled(self, parent_id: str) -> bool:
|
|
264
|
+
return parent_id in self.content
|