@enderhorror/koishi-plugin-steam-friend-status 0.3.1 → 0.3.3
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/data/css/steamFriendList.css +138 -133
- package/data/html/gameChange.html +6 -4
- package/data/html/steamProfile.html +1 -0
- package/data/res/game_change_background.png +0 -0
- package/lib/index.js +21 -10
- package/package.json +1 -1
- package/readme.md +3 -1
- package/src/image.ts +14 -4
- package/src/steam.ts +10 -7
|
@@ -1,133 +1,138 @@
|
|
|
1
|
-
* {
|
|
2
|
-
margin: 0px;
|
|
3
|
-
padding: 0px;
|
|
4
|
-
box-sizing: border-box;
|
|
5
|
-
}
|
|
6
|
-
ul {
|
|
7
|
-
list-style: none;
|
|
8
|
-
}
|
|
9
|
-
.bg {
|
|
10
|
-
width:
|
|
11
|
-
}
|
|
12
|
-
.header {
|
|
13
|
-
display: flex;
|
|
14
|
-
border-radius: 7px 7px 0px 0px;
|
|
15
|
-
height: 75px;
|
|
16
|
-
padding-top: 15px;
|
|
17
|
-
padding-left: 7px;
|
|
18
|
-
padding-bottom: 10px;
|
|
19
|
-
background-color: #1c232c;
|
|
20
|
-
}
|
|
21
|
-
.header .headshot {
|
|
22
|
-
display: block;
|
|
23
|
-
width: 50px;
|
|
24
|
-
height: 50px;
|
|
25
|
-
}
|
|
26
|
-
.header .bot {
|
|
27
|
-
display: flex;
|
|
28
|
-
}
|
|
29
|
-
.header .bot .text {
|
|
30
|
-
display: flex;
|
|
31
|
-
flex-direction: column;
|
|
32
|
-
justify-content: center;
|
|
33
|
-
}
|
|
34
|
-
.friendline {
|
|
35
|
-
height: 30px;
|
|
36
|
-
background-color: #434952;
|
|
37
|
-
}
|
|
38
|
-
.friendline .text {
|
|
39
|
-
padding-left: 15px;
|
|
40
|
-
font-size: 12px;
|
|
41
|
-
line-height: 30px;
|
|
42
|
-
color: #b7ccd5;
|
|
43
|
-
}
|
|
44
|
-
.friendlist {
|
|
45
|
-
background-color: #1f2126;
|
|
46
|
-
padding-bottom: 15px;
|
|
47
|
-
border-radius: 0px 0px 6px 6px;
|
|
48
|
-
}
|
|
49
|
-
.group {
|
|
50
|
-
border-bottom: 1px solid #176383;
|
|
51
|
-
}
|
|
52
|
-
.group .title {
|
|
53
|
-
padding: 6px 0px 0px 13px;
|
|
54
|
-
font-size: 12px;
|
|
55
|
-
color: #c5d6d4;
|
|
56
|
-
line-height: 28px;
|
|
57
|
-
}
|
|
58
|
-
.group:last-child {
|
|
59
|
-
border-bottom: none;
|
|
60
|
-
}
|
|
61
|
-
.friend {
|
|
62
|
-
/* 允许容器高度根据内容自适应,以容纳换行的昵称 */
|
|
63
|
-
height: auto;
|
|
64
|
-
padding: 7px 0px 7px 13px;
|
|
65
|
-
display: flex;
|
|
66
|
-
/* 垂直顶部对齐,确保头像在视觉上保持一致 */
|
|
67
|
-
align-items: flex-start;
|
|
68
|
-
}
|
|
69
|
-
.friend .headshot-online {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
padding-left: 10px;
|
|
106
|
-
font-size:
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
1
|
+
* {
|
|
2
|
+
margin: 0px;
|
|
3
|
+
padding: 0px;
|
|
4
|
+
box-sizing: border-box;
|
|
5
|
+
}
|
|
6
|
+
ul {
|
|
7
|
+
list-style: none;
|
|
8
|
+
}
|
|
9
|
+
.bg {
|
|
10
|
+
width: 360px;
|
|
11
|
+
}
|
|
12
|
+
.header {
|
|
13
|
+
display: flex;
|
|
14
|
+
border-radius: 7px 7px 0px 0px;
|
|
15
|
+
height: 75px;
|
|
16
|
+
padding-top: 15px;
|
|
17
|
+
padding-left: 7px;
|
|
18
|
+
padding-bottom: 10px;
|
|
19
|
+
background-color: #1c232c;
|
|
20
|
+
}
|
|
21
|
+
.header .headshot {
|
|
22
|
+
display: block;
|
|
23
|
+
width: 50px;
|
|
24
|
+
height: 50px;
|
|
25
|
+
}
|
|
26
|
+
.header .bot {
|
|
27
|
+
display: flex;
|
|
28
|
+
}
|
|
29
|
+
.header .bot .text {
|
|
30
|
+
display: flex;
|
|
31
|
+
flex-direction: column;
|
|
32
|
+
justify-content: center;
|
|
33
|
+
}
|
|
34
|
+
.friendline {
|
|
35
|
+
height: 30px;
|
|
36
|
+
background-color: #434952;
|
|
37
|
+
}
|
|
38
|
+
.friendline .text {
|
|
39
|
+
padding-left: 15px;
|
|
40
|
+
font-size: 12px;
|
|
41
|
+
line-height: 30px;
|
|
42
|
+
color: #b7ccd5;
|
|
43
|
+
}
|
|
44
|
+
.friendlist {
|
|
45
|
+
background-color: #1f2126;
|
|
46
|
+
padding-bottom: 15px;
|
|
47
|
+
border-radius: 0px 0px 6px 6px;
|
|
48
|
+
}
|
|
49
|
+
.group {
|
|
50
|
+
border-bottom: 1px solid #176383;
|
|
51
|
+
}
|
|
52
|
+
.group .title {
|
|
53
|
+
padding: 6px 0px 0px 13px;
|
|
54
|
+
font-size: 12px;
|
|
55
|
+
color: #c5d6d4;
|
|
56
|
+
line-height: 28px;
|
|
57
|
+
}
|
|
58
|
+
.group:last-child {
|
|
59
|
+
border-bottom: none;
|
|
60
|
+
}
|
|
61
|
+
.friend {
|
|
62
|
+
/* 允许容器高度根据内容自适应,以容纳换行的昵称 */
|
|
63
|
+
height: auto;
|
|
64
|
+
padding: 7px 0px 7px 13px;
|
|
65
|
+
display: flex;
|
|
66
|
+
/* 垂直顶部对齐,确保头像在视觉上保持一致 */
|
|
67
|
+
align-items: flex-start;
|
|
68
|
+
}
|
|
69
|
+
.friend .headshot-online {
|
|
70
|
+
flex-shrink: 0;
|
|
71
|
+
display: block;
|
|
72
|
+
width: 32px;
|
|
73
|
+
height: 32px;
|
|
74
|
+
}
|
|
75
|
+
.friend .headshot-offline {
|
|
76
|
+
flex-shrink: 0;
|
|
77
|
+
display: block;
|
|
78
|
+
width: 32px;
|
|
79
|
+
height: 32px;
|
|
80
|
+
filter: grayscale(60%);
|
|
81
|
+
}
|
|
82
|
+
.friend .name-and-status {
|
|
83
|
+
padding-left: 8px;
|
|
84
|
+
display: flex;
|
|
85
|
+
flex-direction: column;
|
|
86
|
+
justify-content: center;
|
|
87
|
+
/* 允许该 flex 项收缩,以适应父容器的宽度 */
|
|
88
|
+
flex: 1;
|
|
89
|
+
min-width: 0;
|
|
90
|
+
}
|
|
91
|
+
.status-offline {
|
|
92
|
+
padding-left: 10px;
|
|
93
|
+
font-size: 10px;
|
|
94
|
+
color: #6e6e6e;
|
|
95
|
+
}
|
|
96
|
+
.status-online {
|
|
97
|
+
padding-left: 10px;
|
|
98
|
+
font-size: 10px;
|
|
99
|
+
color: #4c91ac;
|
|
100
|
+
}
|
|
101
|
+
.status-gaming {
|
|
102
|
+
white-space: normal;
|
|
103
|
+
overflow-wrap: anywhere;
|
|
104
|
+
line-height: 15px;
|
|
105
|
+
padding-left: 10px;
|
|
106
|
+
font-size: 10px;
|
|
107
|
+
color: #91c257;
|
|
108
|
+
}
|
|
109
|
+
.name-offline {
|
|
110
|
+
padding-left: 10px;
|
|
111
|
+
font-size: 13px;
|
|
112
|
+
line-height: 16px;
|
|
113
|
+
color: #969797;
|
|
114
|
+
/* 允许文本自动换行 */
|
|
115
|
+
white-space: normal;
|
|
116
|
+
/* 强制在长单词或 URL 内部换行,防止布局崩溃 */
|
|
117
|
+
word-break: break-word;
|
|
118
|
+
}
|
|
119
|
+
.name-online {
|
|
120
|
+
padding-left: 10px;
|
|
121
|
+
font-size: 13px;
|
|
122
|
+
line-height: 16px;
|
|
123
|
+
color: #6dcff6;
|
|
124
|
+
/* 允许文本自动换行 */
|
|
125
|
+
white-space: normal;
|
|
126
|
+
/* 强制在长单词或 URL 内部换行,防止布局崩溃 */
|
|
127
|
+
word-break: break-word;
|
|
128
|
+
}
|
|
129
|
+
.name-gaming {
|
|
130
|
+
padding-left: 10px;
|
|
131
|
+
font-size: 13px;
|
|
132
|
+
line-height: 16px;
|
|
133
|
+
color: #e2fec1;
|
|
134
|
+
/* 允许文本自动换行 */
|
|
135
|
+
white-space: normal;
|
|
136
|
+
/* 强制在长单词或 URL 内部换行,防止布局崩溃 */
|
|
137
|
+
word-break: break-word;
|
|
138
|
+
}
|
|
@@ -19,13 +19,14 @@
|
|
|
19
19
|
background-image: url("{{background}}");
|
|
20
20
|
background-size: cover;
|
|
21
21
|
border-radius: 4px;
|
|
22
|
-
width:
|
|
22
|
+
width: 380px;
|
|
23
23
|
box-sizing: border-box;
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
.avatar-container {
|
|
27
27
|
position: relative;
|
|
28
28
|
margin-right: 10px;
|
|
29
|
+
flex-shrink: 0;
|
|
29
30
|
}
|
|
30
31
|
|
|
31
32
|
.avatar {
|
|
@@ -58,9 +59,10 @@
|
|
|
58
59
|
justify-content: center;
|
|
59
60
|
color: #c1c6cf;
|
|
60
61
|
font-size: 14px;
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
62
|
+
min-width: 0;
|
|
63
|
+
flex: 1;
|
|
64
|
+
white-space: normal;
|
|
65
|
+
overflow-wrap: anywhere;
|
|
64
66
|
}
|
|
65
67
|
|
|
66
68
|
.username {
|
|
Binary file
|
package/lib/index.js
CHANGED
|
@@ -360,13 +360,15 @@ async function getSteamProfile(ctx, steamId) {
|
|
|
360
360
|
ctx.config.SteamApiKey,
|
|
361
361
|
steamId
|
|
362
362
|
);
|
|
363
|
-
profile.recentGames =
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
363
|
+
profile.recentGames = [];
|
|
364
|
+
for (let i = 0; i < recentlyPlayed.games.length; i += 4) {
|
|
365
|
+
const batch = recentlyPlayed.games.slice(i, i + 4);
|
|
366
|
+
profile.recentGames.push(...await Promise.all(batch.map(async (game) => ({
|
|
367
|
+
name: await getLocalizedGameName(ctx, game.appid ? String(game.appid) : void 0, game.name),
|
|
368
|
+
hours: `${(game.playtime_forever / 60).toFixed(1)} \u5C0F\u65F6`,
|
|
369
|
+
img: `https://cdn.akamai.steamstatic.com/steam/apps/${game.appid}/header.jpg`
|
|
370
|
+
}))));
|
|
371
|
+
}
|
|
370
372
|
return profile;
|
|
371
373
|
} catch (error) {
|
|
372
374
|
getPluginLogger().error(
|
|
@@ -850,7 +852,15 @@ async function getFriendStatusImg(ctx, userData, botid, channelid, channelname)
|
|
|
850
852
|
const { config } = ctx;
|
|
851
853
|
const resourcePath = path3.join(ctx.baseDir, "data", "steam-friend-status");
|
|
852
854
|
const templatePath = path3.resolve(__dirname, "..", "data", "html", "steamFriendList.html");
|
|
853
|
-
const
|
|
855
|
+
const originalGamingUsers = userData.response.players.filter((p) => p.gameextrainfo);
|
|
856
|
+
const gamingUsers = [];
|
|
857
|
+
for (let i = 0; i < originalGamingUsers.length; i += 4) {
|
|
858
|
+
const batch = originalGamingUsers.slice(i, i + 4);
|
|
859
|
+
gamingUsers.push(...await Promise.all(batch.map(async (player) => ({
|
|
860
|
+
...player,
|
|
861
|
+
gameextrainfo: await getLocalizedGameName(ctx, player.gameid ? String(player.gameid) : void 0, player.gameextrainfo)
|
|
862
|
+
}))));
|
|
863
|
+
}
|
|
854
864
|
const onlineUsers = userData.response.players.filter((p) => p.personastate !== 0 && !p.gameextrainfo).sort((a, b) => a.personastate - b.personastate);
|
|
855
865
|
const offlineUsers = config.showOfflineFriends ? userData.response.players.filter((p) => p.personastate === 0) : [];
|
|
856
866
|
const url = URL2.pathToFileURL(templatePath).href;
|
|
@@ -895,7 +905,7 @@ async function getFriendStatusImg(ctx, userData, botid, channelid, channelname)
|
|
|
895
905
|
const displayedGroups = (gamingUsers.length > 0 ? 1 : 0) + (onlineUsers.length > 0 ? 1 : 0) + (config.showOfflineFriends && offlineUsers.length > 0 ? 1 : 0);
|
|
896
906
|
const totalHeight = 75 + 30 + 15 + displayedGroups * 28 + displayedUsers * 46;
|
|
897
907
|
await page.setViewport({
|
|
898
|
-
width:
|
|
908
|
+
width: 360,
|
|
899
909
|
height: totalHeight,
|
|
900
910
|
deviceScaleFactor: 2
|
|
901
911
|
});
|
|
@@ -1189,7 +1199,7 @@ async function getGameChangeImg(ctx, playerInfo, changeInfo) {
|
|
|
1189
1199
|
"..",
|
|
1190
1200
|
"data",
|
|
1191
1201
|
"res",
|
|
1192
|
-
"
|
|
1202
|
+
"game_change_background.png"
|
|
1193
1203
|
);
|
|
1194
1204
|
const backgroundBase64 = fs3.readFileSync(backgroundPath, "base64");
|
|
1195
1205
|
htmlContent = htmlContent.replace(
|
|
@@ -1198,6 +1208,7 @@ async function getGameChangeImg(ctx, playerInfo, changeInfo) {
|
|
|
1198
1208
|
).replace("{{avatar}}", avatarBase64).replace("{{statusClass}}", statusClass).replace("{{username}}", changeInfo.userName).replace("{{statusText}}", statusText).replace("{{gameName}}", gameName);
|
|
1199
1209
|
const page = await ctx.puppeteer.page();
|
|
1200
1210
|
try {
|
|
1211
|
+
await page.setViewport({ width: 380, height: 200 });
|
|
1201
1212
|
await page.setContent(htmlContent);
|
|
1202
1213
|
const clip = await page.evaluate(() => {
|
|
1203
1214
|
const element = document.querySelector(".card");
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -4,7 +4,9 @@
|
|
|
4
4
|
|
|
5
5
|
## 本版本的主要改动
|
|
6
6
|
|
|
7
|
-
-
|
|
7
|
+
- **长游戏名称布局**:加宽好友列表和活动播报卡片,长游戏名自动换行,减少截断;个人资料游戏名支持长单词换行。
|
|
8
|
+
|
|
9
|
+
- **游戏活动播报名称本地化**:通过正在游玩的 Steam App ID 查询 Steam 商店简体中文名称,并用于开始、切换和停止游戏的文字及图片播报,`看看steam` 好友列表图片,以及 Steam 个人资料卡片中的最近游戏列表。
|
|
8
10
|
- **兼容回退**:查询失败、游戏没有可用 App ID 或没有商店页面时,使用 Steam 返回的原始名称,不阻断播报。Steam 商店未提供中文名的游戏仍可能显示英文。
|
|
9
11
|
- **缓存查询结果**:名称缓存于内存;成功结果缓存 24 小时,失败结果缓存 5 分钟,插件重启后清空。相同游戏的并发查询会合并。
|
|
10
12
|
- **保留原始状态判断**:继续使用 Steam 原始游戏名称判断状态变化,并记录游戏 ID,以便停止或切换时查询旧游戏的名称。升级前已经在游戏中的用户需至少成功轮询一次来补录 ID;如果补录前就停止游戏,该次播报可能仍显示原名。
|
package/src/image.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { Context, h } from "koishi";
|
|
|
3
3
|
import { GameChangeInfo, SteamUserInfo } from "./types";
|
|
4
4
|
import { fetchArrayBuffer } from "./fetch";
|
|
5
5
|
import { downloadAvatar } from "./database";
|
|
6
|
-
import { getSteamUserInfoByDatabase } from "./steam";
|
|
6
|
+
import { getLocalizedGameName, getSteamUserInfoByDatabase } from "./steam";
|
|
7
7
|
import { getPluginLogger } from "./logger";
|
|
8
8
|
import * as fs from "node:fs";
|
|
9
9
|
import * as path from "node:path";
|
|
@@ -215,7 +215,16 @@ export async function getFriendStatusImg(
|
|
|
215
215
|
const resourcePath = path.join(ctx.baseDir, 'data', 'steam-friend-status');
|
|
216
216
|
const templatePath = path.resolve(__dirname, '..', 'data', 'html', 'steamFriendList.html');
|
|
217
217
|
|
|
218
|
-
const
|
|
218
|
+
const originalGamingUsers = userData.response.players.filter((p) => p.gameextrainfo);
|
|
219
|
+
// 仅复制展示数据,保留 API 原始对象供状态判断使用;限制并发避免商店请求过载。
|
|
220
|
+
const gamingUsers: typeof originalGamingUsers = [];
|
|
221
|
+
for (let i = 0; i < originalGamingUsers.length; i += 4) {
|
|
222
|
+
const batch = originalGamingUsers.slice(i, i + 4);
|
|
223
|
+
gamingUsers.push(...await Promise.all(batch.map(async (player) => ({
|
|
224
|
+
...player,
|
|
225
|
+
gameextrainfo: await getLocalizedGameName(ctx, player.gameid ? String(player.gameid) : undefined, player.gameextrainfo),
|
|
226
|
+
}))));
|
|
227
|
+
}
|
|
219
228
|
const onlineUsers = userData.response.players
|
|
220
229
|
.filter((p) => p.personastate !== 0 && !p.gameextrainfo)
|
|
221
230
|
.sort((a, b) => a.personastate - b.personastate);
|
|
@@ -277,7 +286,7 @@ export async function getFriendStatusImg(
|
|
|
277
286
|
(config.showOfflineFriends && offlineUsers.length > 0 ? 1 : 0);
|
|
278
287
|
const totalHeight = 75 + 30 + 15 + displayedGroups * 28 + displayedUsers * 46;
|
|
279
288
|
await page.setViewport({
|
|
280
|
-
width:
|
|
289
|
+
width: 360,
|
|
281
290
|
height: totalHeight,
|
|
282
291
|
deviceScaleFactor: 2,
|
|
283
292
|
});
|
|
@@ -644,7 +653,7 @@ export async function getGameChangeImg(
|
|
|
644
653
|
"..",
|
|
645
654
|
"data",
|
|
646
655
|
"res",
|
|
647
|
-
"
|
|
656
|
+
"game_change_background.png",
|
|
648
657
|
);
|
|
649
658
|
const backgroundBase64 = fs.readFileSync(backgroundPath, "base64");
|
|
650
659
|
htmlContent = htmlContent
|
|
@@ -661,6 +670,7 @@ export async function getGameChangeImg(
|
|
|
661
670
|
// 4. 使用 Puppeteer 截图
|
|
662
671
|
const page = await ctx.puppeteer.page();
|
|
663
672
|
try {
|
|
673
|
+
await page.setViewport({ width: 380, height: 200 });
|
|
664
674
|
await page.setContent(htmlContent);
|
|
665
675
|
|
|
666
676
|
const clip = await page.evaluate(() => {
|
package/src/steam.ts
CHANGED
|
@@ -187,13 +187,16 @@ export async function getSteamProfile(
|
|
|
187
187
|
ctx.config.SteamApiKey,
|
|
188
188
|
steamId,
|
|
189
189
|
);
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
190
|
+
// 只本地化展示值,限制并发并复用活动播报的名称缓存。
|
|
191
|
+
profile.recentGames = [];
|
|
192
|
+
for (let i = 0; i < recentlyPlayed.games.length; i += 4) {
|
|
193
|
+
const batch = recentlyPlayed.games.slice(i, i + 4);
|
|
194
|
+
profile.recentGames.push(...await Promise.all(batch.map(async (game) => ({
|
|
195
|
+
name: await getLocalizedGameName(ctx, game.appid ? String(game.appid) : undefined, game.name),
|
|
196
|
+
hours: `${(game.playtime_forever / 60).toFixed(1)} 小时`,
|
|
197
|
+
img: `https://cdn.akamai.steamstatic.com/steam/apps/${game.appid}/header.jpg`,
|
|
198
|
+
}))));
|
|
199
|
+
}
|
|
197
200
|
|
|
198
201
|
return profile;
|
|
199
202
|
} catch (error) {
|