@enderhorror/koishi-plugin-steam-friend-status 0.3.2 → 0.3.4

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.
@@ -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: 227px;
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
- display: block;
71
- width: 32px;
72
- height: 32px;
73
- }
74
- .friend .headshot-offline {
75
- display: block;
76
- width: 32px;
77
- height: 32px;
78
- filter: grayscale(60%);
79
- }
80
- .friend .name-and-status {
81
- padding-left: 8px;
82
- display: flex;
83
- flex-direction: column;
84
- justify-content: center;
85
- /* 允许该 flex 项收缩,以适应父容器的宽度 */
86
- flex: 1;
87
- min-width: 0;
88
- }
89
- .status-offline {
90
- padding-left: 10px;
91
- font-size: 10px;
92
- color: #6e6e6e;
93
- }
94
- .status-online {
95
- padding-left: 10px;
96
- font-size: 10px;
97
- color: #4c91ac;
98
- }
99
- .status-gaming {
100
- padding-left: 10px;
101
- font-size: 10px;
102
- color: #91c257;
103
- }
104
- .name-offline {
105
- padding-left: 10px;
106
- font-size: 13px;
107
- line-height: 16px;
108
- color: #969797;
109
- /* 允许文本自动换行 */
110
- white-space: normal;
111
- /* 强制在长单词或 URL 内部换行,防止布局崩溃 */
112
- word-break: break-word;
113
- }
114
- .name-online {
115
- padding-left: 10px;
116
- font-size: 13px;
117
- line-height: 16px;
118
- color: #6dcff6;
119
- /* 允许文本自动换行 */
120
- white-space: normal;
121
- /* 强制在长单词或 URL 内部换行,防止布局崩溃 */
122
- word-break: break-word;
123
- }
124
- .name-gaming {
125
- padding-left: 10px;
126
- font-size: 13px;
127
- line-height: 16px;
128
- color: #e2fec1;
129
- /* 允许文本自动换行 */
130
- white-space: normal;
131
- /* 强制在长单词或 URL 内部换行,防止布局崩溃 */
132
- word-break: break-word;
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: 300px;
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
- white-space: nowrap;
62
- overflow: hidden;
63
- text-overflow: ellipsis;
62
+ min-width: 0;
63
+ flex: 1;
64
+ white-space: normal;
65
+ overflow-wrap: anywhere;
64
66
  }
65
67
 
66
68
  .username {
@@ -108,6 +108,7 @@
108
108
  }
109
109
 
110
110
  .game-name {
111
+ overflow-wrap: anywhere;
111
112
  font-size: 16px;
112
113
  font-weight: 500;
113
114
  color: #ffffff;
@@ -4,6 +4,11 @@ export interface SteamBroadcastConfig {
4
4
  SteamApiKey: string;
5
5
  useSteamName: boolean;
6
6
  broadcastWithImage: boolean;
7
+ mergeBroadcast?: boolean;
8
+ mergeWindow?: number;
9
+ stabilityPeriod?: number;
10
+ minStopPlayMinutes?: number;
11
+ immediateBroadcast?: boolean;
7
12
  }
8
13
  export declare function pollSteamBroadcast(ctx: Context, config: SteamBroadcastConfig, logger: PluginLogger, shouldStop: () => boolean): Promise<void>;
9
14
  export declare function updatePlayerHeadshots(ctx: Context, config: SteamBroadcastConfig, logger: PluginLogger): Promise<void>;
package/lib/index.d.ts CHANGED
@@ -8,6 +8,11 @@ export interface PluginConfig {
8
8
  interval: number;
9
9
  useSteamName: boolean;
10
10
  broadcastWithImage: boolean;
11
+ mergeBroadcast: boolean;
12
+ mergeWindow: number;
13
+ stabilityPeriod: number;
14
+ minStopPlayMinutes: number;
15
+ immediateBroadcast: boolean;
11
16
  useApifoxProxy: boolean;
12
17
  maxRetries: number;
13
18
  showcardmode: "1" | "2";
package/lib/index.js CHANGED
@@ -484,11 +484,11 @@ async function saveGameSessionsLocked(ctx, data) {
484
484
  releaseLock();
485
485
  }
486
486
  }
487
- async function startGameSession(ctx, userId, gameName) {
487
+ async function startGameSession(ctx, userId, gameName, startTime = Date.now()) {
488
488
  const sessions = await loadGameSessionsLocked(ctx);
489
489
  sessions[userId] = {
490
490
  gameName,
491
- startTime: Date.now()
491
+ startTime
492
492
  };
493
493
  await saveGameSessionsLocked(ctx, sessions);
494
494
  }
@@ -905,7 +905,7 @@ async function getFriendStatusImg(ctx, userData, botid, channelid, channelname)
905
905
  const displayedGroups = (gamingUsers.length > 0 ? 1 : 0) + (onlineUsers.length > 0 ? 1 : 0) + (config.showOfflineFriends && offlineUsers.length > 0 ? 1 : 0);
906
906
  const totalHeight = 75 + 30 + 15 + displayedGroups * 28 + displayedUsers * 46;
907
907
  await page.setViewport({
908
- width: 227,
908
+ width: 360,
909
909
  height: totalHeight,
910
910
  deviceScaleFactor: 2
911
911
  });
@@ -1199,7 +1199,7 @@ async function getGameChangeImg(ctx, playerInfo, changeInfo) {
1199
1199
  "..",
1200
1200
  "data",
1201
1201
  "res",
1202
- "gaming.png"
1202
+ "game_change_background.png"
1203
1203
  );
1204
1204
  const backgroundBase64 = fs3.readFileSync(backgroundPath, "base64");
1205
1205
  htmlContent = htmlContent.replace(
@@ -1208,6 +1208,7 @@ async function getGameChangeImg(ctx, playerInfo, changeInfo) {
1208
1208
  ).replace("{{avatar}}", avatarBase64).replace("{{statusClass}}", statusClass).replace("{{username}}", changeInfo.userName).replace("{{statusText}}", statusText).replace("{{gameName}}", gameName);
1209
1209
  const page = await ctx.puppeteer.page();
1210
1210
  try {
1211
+ await page.setViewport({ width: 380, height: 200 });
1211
1212
  await page.setContent(htmlContent);
1212
1213
  const clip = await page.evaluate(() => {
1213
1214
  const element = document.querySelector(".card");
@@ -1269,6 +1270,10 @@ async function pollSteamBroadcast(ctx, config, logger, shouldStop) {
1269
1270
  logger,
1270
1271
  shouldStop
1271
1272
  );
1273
+ if (config.mergeBroadcast !== false && !config.immediateBroadcast) {
1274
+ await processMergedBroadcast(ctx, config, logger, shouldStop, channels, allUserData, steamUserInfo, changes);
1275
+ return;
1276
+ }
1272
1277
  if (Object.keys(changes).length === 0) {
1273
1278
  logger.debug("\u672C\u8F6E\u6CA1\u6709\u68C0\u6D4B\u5230\u6E38\u620F\u72B6\u6001\u53D8\u5316");
1274
1279
  return;
@@ -1286,6 +1291,13 @@ async function pollSteamBroadcast(ctx, config, logger, shouldStop) {
1286
1291
  );
1287
1292
  continue;
1288
1293
  }
1294
+ if (isShortSession(changeInfo, config)) {
1295
+ if (changeInfo.status === "stop") {
1296
+ await acknowledgeGameChange(ctx, changeInfo, logger);
1297
+ continue;
1298
+ }
1299
+ changeInfo.suppressEnd = true;
1300
+ }
1289
1301
  const playerInfo = steamUserInfo.response.players.find(
1290
1302
  (player) => player.steamid === user.steamId
1291
1303
  );
@@ -1342,6 +1354,106 @@ async function pollSteamBroadcast(ctx, config, logger, shouldStop) {
1342
1354
  }
1343
1355
  }
1344
1356
  }
1357
+ var mergeStates = /* @__PURE__ */ new WeakMap();
1358
+ function getMergeState(ctx) {
1359
+ let state = mergeStates.get(ctx);
1360
+ if (!state) {
1361
+ state = { candidates: /* @__PURE__ */ new Map(), queue: /* @__PURE__ */ new Map() };
1362
+ mergeStates.set(ctx, state);
1363
+ }
1364
+ return state;
1365
+ }
1366
+ function changeSignature(change) {
1367
+ return JSON.stringify([change.oldGame || "", change.newGame || "", change.newGameId || ""]);
1368
+ }
1369
+ async function processMergedBroadcast(ctx, config, logger, shouldStop, channels, users, steamUserInfo, changes) {
1370
+ const state = getMergeState(ctx);
1371
+ const now = Date.now();
1372
+ const stableMs = Math.max(0, config.stabilityPeriod ?? 30) * 1e3;
1373
+ const mergeMs = Math.max(0, config.mergeWindow ?? 180) * 1e3;
1374
+ const observed = new Set(steamUserInfo.response.players.map((p) => p.steamid));
1375
+ const userMap = new Map(users.map((u) => [u.userId, u]));
1376
+ for (const id of /* @__PURE__ */ new Set([...state.candidates.keys(), ...state.queue.keys()])) {
1377
+ const user = userMap.get(id);
1378
+ if (!user || !observed.has(user.steamId) || !changes[id]) {
1379
+ state.candidates.delete(id);
1380
+ if (!user || observed.has(user.steamId) && !changes[id]) state.queue.delete(id);
1381
+ }
1382
+ }
1383
+ for (const change of Object.values(changes)) {
1384
+ const signature = changeSignature(change);
1385
+ const previous = state.candidates.get(change.userId);
1386
+ if (!previous || previous.signature !== signature) {
1387
+ state.candidates.set(change.userId, { signature, since: now, firstChange: { ...change } });
1388
+ state.queue.delete(change.userId);
1389
+ if (stableMs > 0) continue;
1390
+ } else if (now - previous.since < stableMs) continue;
1391
+ const firstChange = state.candidates.get(change.userId).firstChange;
1392
+ if (isShortSession(firstChange, config)) {
1393
+ if (firstChange.status === "stop") {
1394
+ if (await acknowledgeGameChange(ctx, firstChange, logger)) {
1395
+ state.queue.delete(change.userId);
1396
+ state.candidates.delete(change.userId);
1397
+ }
1398
+ continue;
1399
+ }
1400
+ change.suppressEnd = true;
1401
+ }
1402
+ const queued = state.queue.get(change.userId);
1403
+ if (queued?.signature === signature) continue;
1404
+ const user = userMap.get(change.userId);
1405
+ if (!user) continue;
1406
+ change.observedAt = state.candidates.get(change.userId).since;
1407
+ const pendingChannels = new Set(channels.filter((c) => user.effectGroups.includes(c.id)).map((c) => c.id));
1408
+ if (pendingChannels.size) state.queue.set(change.userId, { signature, change, queuedAt: now, pendingChannels });
1409
+ }
1410
+ for (const channel of channels) {
1411
+ if (shouldStop()) return;
1412
+ const entries = [...state.queue.values()].filter((entry) => {
1413
+ const candidate = state.candidates.get(entry.change.userId);
1414
+ return entry.pendingChannels.has(channel.id) && observed.has(userMap.get(entry.change.userId)?.steamId || "") && candidate?.signature === entry.signature && now - candidate.since >= stableMs;
1415
+ });
1416
+ if (!entries.length || now - Math.min(...entries.map((e) => e.queuedAt)) < mergeMs) continue;
1417
+ const bot = ctx.bots[`${channel.platform}:${channel.assignee}`] || Object.values(ctx.bots).find(
1418
+ (item) => item.platform === channel.platform && (item.selfId === channel.assignee || item.user?.id === channel.assignee)
1419
+ );
1420
+ if (!bot) {
1421
+ logger.warn(`\u672A\u627E\u5230\u7FA4\u7EC4 ${channel.id} \u5BF9\u5E94\u7684\u673A\u5668\u4EBA\uFF0C\u4FDD\u7559\u5F85\u53D1\u9001\u64AD\u62A5`);
1422
+ continue;
1423
+ }
1424
+ try {
1425
+ const lines = [];
1426
+ for (const entry of entries) {
1427
+ const change = entry.change;
1428
+ const display = {
1429
+ ...change,
1430
+ oldGame: change.oldGame ? await getLocalizedGameName(ctx, change.oldGameId, change.oldGame) : void 0,
1431
+ newGame: change.newGame ? await getLocalizedGameName(ctx, change.newGameId, change.newGame) : void 0
1432
+ };
1433
+ const nickname = await getUserNickname(ctx, change.userId, channel.id);
1434
+ lines.push(`\u2022 ${buildBroadcastText(nickname || change.userName, display)}`);
1435
+ }
1436
+ if (shouldStop()) return;
1437
+ await bot.sendMessage(channel.id, `\u{1F3AE} Steam \u597D\u53CB\u52A8\u6001
1438
+ ${lines.join("\n")}`);
1439
+ for (const entry of entries) entry.pendingChannels.delete(channel.id);
1440
+ } catch (error) {
1441
+ logger.warn(`\u7FA4\u7EC4 ${channel.id} \u5408\u5E76\u64AD\u62A5\u5931\u8D25\uFF0C\u5C06\u5728\u4E0B\u6B21\u8F6E\u8BE2\u91CD\u8BD5:`, error);
1442
+ }
1443
+ }
1444
+ for (const [id, entry] of state.queue) {
1445
+ const user = userMap.get(id);
1446
+ for (const channelId of entry.pendingChannels) {
1447
+ if (!channels.some((c) => c.id === channelId) || !user?.effectGroups.includes(channelId)) entry.pendingChannels.delete(channelId);
1448
+ }
1449
+ if (!entry.pendingChannels.size) {
1450
+ if (await acknowledgeGameChange(ctx, entry.change, logger)) {
1451
+ state.queue.delete(id);
1452
+ state.candidates.delete(id);
1453
+ }
1454
+ }
1455
+ }
1456
+ }
1345
1457
  async function updatePlayerHeadshots(ctx, config, logger) {
1346
1458
  const allUserData = await ctx.database.select("SteamUser").execute();
1347
1459
  const steamUserInfo = await getSteamUserInfoByDatabase(
@@ -1389,7 +1501,10 @@ async function detectGameChanges(ctx, allUserData, steamUserInfo, useSteamName,
1389
1501
  }
1390
1502
  continue;
1391
1503
  }
1392
- const playTime = await getCurrentPlayTime(ctx, userData.userId);
1504
+ const session = await getGameSession(ctx, userData.userId);
1505
+ const playDurationMs = session && Number.isFinite(session.startTime) ? Math.max(0, Date.now() - session.startTime) : void 0;
1506
+ const minutes = playDurationMs === void 0 ? 0 : Math.floor(playDurationMs / 6e4);
1507
+ const playTime = minutes > 0 ? formatPlayTime(minutes) : void 0;
1393
1508
  const userName = useSteamName ? player.personaname : userData.userName;
1394
1509
  if (newGame && !oldGame) {
1395
1510
  changes[userData.userId] = {
@@ -1408,7 +1523,8 @@ async function detectGameChanges(ctx, allUserData, steamUserInfo, useSteamName,
1408
1523
  oldGameId,
1409
1524
  newGame,
1410
1525
  newGameId,
1411
- playTime
1526
+ playTime,
1527
+ playDurationMs
1412
1528
  };
1413
1529
  } else if (!newGame && oldGame) {
1414
1530
  changes[userData.userId] = {
@@ -1417,20 +1533,19 @@ async function detectGameChanges(ctx, allUserData, steamUserInfo, useSteamName,
1417
1533
  status: "stop",
1418
1534
  oldGame,
1419
1535
  oldGameId,
1420
- playTime
1536
+ playTime,
1537
+ playDurationMs
1421
1538
  };
1422
1539
  }
1423
1540
  }
1424
1541
  return changes;
1425
1542
  }
1426
- async function getCurrentPlayTime(ctx, userId) {
1427
- const session = await getGameSession(ctx, userId);
1428
- if (!session) return void 0;
1429
- const minutes = Math.floor((Date.now() - session.startTime) / 6e4);
1430
- return minutes > 0 ? formatPlayTime(minutes) : void 0;
1543
+ function isShortSession(change, config) {
1544
+ const threshold = Math.max(0, config.minStopPlayMinutes ?? 10) * 6e4;
1545
+ return (change.status === "stop" || change.status === "change") && change.playDurationMs !== void 0 && change.playDurationMs < threshold;
1431
1546
  }
1432
1547
  function buildBroadcastText(displayName, changeInfo) {
1433
- if (changeInfo.status === "start") {
1548
+ if (changeInfo.status === "start" || changeInfo.status === "change" && changeInfo.suppressEnd) {
1434
1549
  return `${displayName} \u5F00\u59CB\u73A9 ${changeInfo.newGame} \u4E86`;
1435
1550
  }
1436
1551
  if (changeInfo.status === "stop") {
@@ -1453,10 +1568,10 @@ async function sendBroadcast(ctx, bot, channelId, textMessage, playerInfo, chang
1453
1568
  async function acknowledgeGameChange(ctx, changeInfo, logger) {
1454
1569
  try {
1455
1570
  if (changeInfo.status === "start") {
1456
- await startGameSession(ctx, changeInfo.userId, changeInfo.newGame || "");
1571
+ await startGameSession(ctx, changeInfo.userId, changeInfo.newGame || "", changeInfo.observedAt);
1457
1572
  } else if (changeInfo.status === "change") {
1458
1573
  await endGameSession(ctx, changeInfo.userId);
1459
- await startGameSession(ctx, changeInfo.userId, changeInfo.newGame || "");
1574
+ await startGameSession(ctx, changeInfo.userId, changeInfo.newGame || "", changeInfo.observedAt);
1460
1575
  } else {
1461
1576
  await endGameSession(ctx, changeInfo.userId);
1462
1577
  }
@@ -1465,11 +1580,13 @@ async function acknowledgeGameChange(ctx, changeInfo, logger) {
1465
1580
  { userId: changeInfo.userId },
1466
1581
  { lastPlayedGame: changeInfo.newGame || "", lastPlayedGameId: changeInfo.newGameId || "" }
1467
1582
  );
1583
+ return true;
1468
1584
  } catch (error) {
1469
1585
  logger.error(
1470
1586
  `\u64AD\u62A5\u5DF2\u53D1\u9001\uFF0C\u4F46\u66F4\u65B0\u7528\u6237 ${changeInfo.userId} \u7684\u6E38\u620F\u72B6\u6001\u5931\u8D25:`,
1471
1587
  error
1472
1588
  );
1589
+ return false;
1473
1590
  }
1474
1591
  }
1475
1592
  async function downloadPlayerAvatar(ctx, player) {
@@ -1550,10 +1667,17 @@ var Config = import_koishi4.Schema.intersect([
1550
1667
  SteamApiKey: import_koishi4.Schema.string().description(
1551
1668
  "Steam API Key\uFF0C\u83B7\u53D6\u65B9\u5F0F\uFF1Ahttps://partner.steamgames.com/doc/webapi_overview/auth"
1552
1669
  ).role("secret").required(),
1553
- interval: import_koishi4.Schema.number().default(60).min(10).description("\u67E5\u8BE2\u95F4\u9694,\u5355\u4F4D\uFF1A\u79D2"),
1670
+ interval: import_koishi4.Schema.number().default(60).min(10).description("\u67E5\u8BE2\u95F4\u9694\uFF0C\u5355\u4F4D\uFF1A\u79D2\uFF1B\u72B6\u6001\u7A33\u5B9A\u671F\u9700\u7ECF\u540E\u7EED\u8F6E\u8BE2\u786E\u8BA4\uFF0C\u5EFA\u8BAE\u4E0D\u5927\u4E8E\u7A33\u5B9A\u671F"),
1554
1671
  useSteamName: import_koishi4.Schema.boolean().default(true).description("\u4F7F\u7528Steam\u6635\u79F0,\u5173\u95ED\u65F6\u4F7F\u7528\u7684QQ\u6635\u79F0"),
1555
1672
  broadcastWithImage: import_koishi4.Schema.boolean().default(true).description("\u64AD\u62A5\u65F6\u9644\u5E26\u56FE\u7247")
1556
1673
  }).description("\u57FA\u7840\u8BBE\u7F6E"),
1674
+ import_koishi4.Schema.object({
1675
+ mergeBroadcast: import_koishi4.Schema.boolean().default(true).description("\u5408\u5E76\u7A97\u53E3\u5185\u7684\u6E38\u620F\u72B6\u6001\u64AD\u62A5"),
1676
+ mergeWindow: import_koishi4.Schema.number().default(180).min(1).step(1).description("\u5408\u5E76\u64AD\u62A5\u7A97\u53E3\uFF0C\u5355\u4F4D\uFF1A\u79D2"),
1677
+ stabilityPeriod: import_koishi4.Schema.number().default(30).min(0).step(1).description("\u72B6\u6001\u7A33\u5B9A\u671F\uFF0C\u5355\u4F4D\uFF1A\u79D2\uFF1B\u9700\u901A\u8FC7\u540E\u7EED\u8F6E\u8BE2\u786E\u8BA4"),
1678
+ minStopPlayMinutes: import_koishi4.Schema.number().default(10).min(0).step(1).description("\u7ED3\u675F\u64AD\u62A5\u6700\u77ED\u6E38\u620F\u65F6\u957F\uFF08\u5206\u949F\uFF09\uFF0C\u8BBE\u4E3A 0 \u5173\u95ED\u8FC7\u6EE4\uFF1B\u65F6\u957F\u672A\u77E5\u65F6\u4ECD\u64AD\u62A5"),
1679
+ immediateBroadcast: import_koishi4.Schema.boolean().default(false).description("\u5373\u65F6\u64AD\u62A5\uFF0C\u8DF3\u8FC7\u5408\u5E76\u7A97\u53E3\u548C\u72B6\u6001\u7A33\u5B9A\u671F")
1680
+ }).description("\u64AD\u62A5\u8BBE\u7F6E"),
1557
1681
  import_koishi4.Schema.object({
1558
1682
  useApifoxProxy: import_koishi4.Schema.boolean().default(true).description(
1559
1683
  "Steam API \u76F4\u8FDE\u5931\u8D25\u65F6\u4F7F\u7528 APIFOX \u516C\u5171\u4EE3\u7406\u515C\u5E95\uFF08\u8BF7\u6C42 URL \u4F1A\u53D1\u9001\u7ED9\u4EE3\u7406\uFF09"
package/lib/types.d.ts CHANGED
@@ -24,6 +24,9 @@ export interface GameChangeInfo {
24
24
  oldGame?: string;
25
25
  newGame?: string;
26
26
  playTime?: string;
27
+ playDurationMs?: number;
28
+ suppressEnd?: boolean;
29
+ observedAt?: number;
27
30
  oldGameId?: string;
28
31
  newGameId?: string;
29
32
  }
package/lib/userdata.d.ts CHANGED
@@ -6,7 +6,7 @@ interface GameSession {
6
6
  /**
7
7
  * 记录用户开始玩游戏
8
8
  */
9
- export declare function startGameSession(ctx: Context, userId: string, gameName: string): Promise<void>;
9
+ export declare function startGameSession(ctx: Context, userId: string, gameName: string, startTime?: number): Promise<void>;
10
10
  /**
11
11
  * 结束游戏会话并返回游玩时长(分钟)
12
12
  */
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@enderhorror/koishi-plugin-steam-friend-status",
3
3
  "description": "查询并播报 Steam 好友状态,支持游戏活动播报名称本地化",
4
- "version": "0.3.2",
4
+ "version": "0.3.4",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [
package/readme.md CHANGED
@@ -2,8 +2,20 @@
2
2
 
3
3
  自动查询并播报 Steam 好友游戏状态的 Koishi 插件。本版本基于 [koishi-plugin-steam-friend-status-fork@0.3.1](https://www.npmjs.com/package/koishi-plugin-steam-friend-status-fork/v/0.3.1) 修改。
4
4
 
5
+ ## 更新日志
6
+
7
+ ### 0.3.4
8
+
9
+ - 默认开启群组游戏动态合并播报,合并窗口默认为 180 秒;不同群组独立发送,失败群组在后续轮询重试。
10
+ - 新增状态稳定期,默认 30 秒;需后续轮询确认,降低短时间状态波动产生的播报。
11
+ - 新增结束播报时长阈值,默认少于 10 分钟不播报结束;切换游戏时若前一游戏未达到阈值,仅播报新游戏开始。时长未知时仍播报,阈值设为 0 可关闭过滤。
12
+ - 新增即时播报选项及相关配置;合并播报以文字汇总,不附单人图片。
13
+ - 新安装默认轮询间隔为 60 秒;已有配置保持不变。实际检测与播报时间受轮询间隔影响,待发送队列存于内存。
14
+
5
15
  ## 本版本的主要改动
6
16
 
17
+ - **长游戏名称布局**:加宽好友列表和活动播报卡片,长游戏名自动换行,减少截断;个人资料游戏名支持长单词换行。
18
+
7
19
  - **游戏活动播报名称本地化**:通过正在游玩的 Steam App ID 查询 Steam 商店简体中文名称,并用于开始、切换和停止游戏的文字及图片播报,`看看steam` 好友列表图片,以及 Steam 个人资料卡片中的最近游戏列表。
8
20
  - **兼容回退**:查询失败、游戏没有可用 App ID 或没有商店页面时,使用 Steam 返回的原始名称,不阻断播报。Steam 商店未提供中文名的游戏仍可能显示英文。
9
21
  - **缓存查询结果**:名称缓存于内存;成功结果缓存 24 小时,失败结果缓存 5 分钟,插件重启后清空。相同游戏的并发查询会合并。
@@ -44,9 +56,20 @@ npm install @enderhorror/koishi-plugin-steam-friend-status
44
56
  | 配置项 | 默认值 | 说明 |
45
57
  | ------------------ | ------ | ---------------------------------------------------------------------------------------------------------------------------------- |
46
58
  | SteamApiKey | 无 | 用户查询信息的apikey,可以从 -> [这里](https://partner.steamgames.com/doc/webapi_overview/auth) 获取 |
47
- | interval | 300 | 单位(秒),自动查询信息的时间间隔 |
59
+ | interval | 60 | 单位(秒),自动查询信息的时间间隔,最小 10 秒 |
48
60
  | useSteamName | true | 播报时使用玩家昵称,false为QQ昵称,true为steam昵称 <span style="color:red">red/satori适配器暂时无法获取到用户昵称,建议打开</span> |
49
61
  | broadcastWithImage | true | 播报时附带好友列表图片,关闭可以减少因长图片导致的刷屏 |
62
+ | mergeBroadcast | true | 开启合并播报 |
63
+ | mergeWindow | 180 | 合并播报窗口,单位:秒,最小 1 秒 |
64
+ | stabilityPeriod | 30 | 状态稳定期,单位:秒,最小 0 秒 |
65
+ | minStopPlayMinutes | 10 | 少于该时长(分钟)不播报结束;0 表示关闭过滤,时长未知仍播报 |
66
+ | immediateBroadcast | false | 开启后即时播报,跳过合并窗口和状态稳定期 |
67
+
68
+ 状态变化通过轮询发现和确认;稳定期不是精确定时,实际确认可能延迟至下一次轮询。默认查询间隔为 60 秒,若希望更及时地确认默认 30 秒稳定期,可将 `interval` 调整至 30 秒或更短(最小 10 秒);更频繁的轮询会增加 Steam API 请求量。已有 `interval` 配置不会自动改变。
69
+
70
+ 游戏切换时,如果上一个游戏未满阈值,只播报新游戏开始;结束状态仍会更新。时长以插件首次检测到开始和结束的时间估算,而非 Steam 官方精确游戏时长;轮询间隔可能影响估算,旧会话可能受升级前播报延迟影响。
71
+
72
+ > 合并播报以文字汇总发送,不附单人图片。候选状态和待发送队列保存在内存中,插件重启会清空队列;未成功确认的状态将在后续轮询重新检测。发送失败的群组会在下一次轮询时重试;不同群组独立发送。
50
73
 
51
74
  ## 其他说明
52
75
 
package/src/broadcast.ts CHANGED
@@ -16,6 +16,11 @@ export interface SteamBroadcastConfig {
16
16
  SteamApiKey: string;
17
17
  useSteamName: boolean;
18
18
  broadcastWithImage: boolean;
19
+ mergeBroadcast?: boolean;
20
+ immediateBroadcast?: boolean;
21
+ mergeWindow?: number;
22
+ stabilityPeriod?: number;
23
+ minStopPlayMinutes?: number;
19
24
  }
20
25
 
21
26
  type SteamPlayer = SteamUserInfo["response"]["players"][number];
@@ -67,6 +72,10 @@ export async function pollSteamBroadcast(
67
72
  logger,
68
73
  shouldStop,
69
74
  );
75
+ if (config.mergeBroadcast !== false && !config.immediateBroadcast) {
76
+ await processMergedBroadcast(ctx, config, logger, shouldStop, channels, allUserData, steamUserInfo, changes);
77
+ return;
78
+ }
70
79
  if (Object.keys(changes).length === 0) {
71
80
  logger.debug("本轮没有检测到游戏状态变化");
72
81
  return;
@@ -88,6 +97,13 @@ export async function pollSteamBroadcast(
88
97
  continue;
89
98
  }
90
99
 
100
+ if (isShortSession(changeInfo, config)) {
101
+ if (changeInfo.status === "stop") {
102
+ await acknowledgeGameChange(ctx, changeInfo, logger);
103
+ continue;
104
+ }
105
+ changeInfo.suppressEnd = true;
106
+ }
91
107
  const playerInfo = steamUserInfo.response.players.find(
92
108
  (player) => player.steamid === user.steamId,
93
109
  );
@@ -157,6 +173,111 @@ export async function pollSteamBroadcast(
157
173
  }
158
174
  }
159
175
 
176
+ // 运行期队列:候选状态需两次成功轮询确认,群组发送成功后不重复投递。
177
+ type Candidate = { signature: string; since: number; firstChange: GameChangeInfo };
178
+ type QueuedChange = { signature: string; change: GameChangeInfo; queuedAt: number; pendingChannels: Set<string> };
179
+ type MergeState = { candidates: Map<string, Candidate>; queue: Map<string, QueuedChange> };
180
+ const mergeStates = new WeakMap<Context, MergeState>();
181
+ function getMergeState(ctx: Context): MergeState {
182
+ let state = mergeStates.get(ctx);
183
+ if (!state) { state = { candidates: new Map(), queue: new Map() }; mergeStates.set(ctx, state); }
184
+ return state;
185
+ }
186
+ function changeSignature(change: GameChangeInfo): string {
187
+ return JSON.stringify([change.oldGame || "", change.newGame || "", change.newGameId || ""]);
188
+ }
189
+ async function processMergedBroadcast(
190
+ ctx: Context, config: SteamBroadcastConfig, logger: PluginLogger, shouldStop: () => boolean,
191
+ channels: any[], users: SteamUser[], steamUserInfo: SteamUserInfo, changes: Record<string, GameChangeInfo>,
192
+ ): Promise<void> {
193
+ const state = getMergeState(ctx);
194
+ const now = Date.now();
195
+ const stableMs = Math.max(0, config.stabilityPeriod ?? 30) * 1000;
196
+ const mergeMs = Math.max(0, config.mergeWindow ?? 180) * 1000;
197
+ const observed = new Set(steamUserInfo.response.players.map((p) => p.steamid));
198
+ const userMap = new Map(users.map((u) => [u.userId, u]));
199
+ // 消失、解绑或恢复原状时取消过期状态;未返回玩家时不认定稳定。
200
+ for (const id of new Set([...state.candidates.keys(), ...state.queue.keys()])) {
201
+ const user = userMap.get(id);
202
+ if (!user || !observed.has(user.steamId) || !changes[id]) {
203
+ state.candidates.delete(id);
204
+ if (!user || (observed.has(user.steamId) && !changes[id])) state.queue.delete(id);
205
+ }
206
+ }
207
+ for (const change of Object.values(changes)) {
208
+ const signature = changeSignature(change);
209
+ const previous = state.candidates.get(change.userId);
210
+ if (!previous || previous.signature !== signature) {
211
+ state.candidates.set(change.userId, { signature, since: now, firstChange: { ...change } });
212
+ state.queue.delete(change.userId);
213
+ if (stableMs > 0) continue;
214
+ } else if (now - previous.since < stableMs) continue;
215
+ const firstChange = state.candidates.get(change.userId)!.firstChange;
216
+ if (isShortSession(firstChange, config)) {
217
+ if (firstChange.status === "stop") {
218
+ if (await acknowledgeGameChange(ctx, firstChange, logger)) {
219
+ state.queue.delete(change.userId);
220
+ state.candidates.delete(change.userId);
221
+ }
222
+ continue;
223
+ }
224
+ change.suppressEnd = true;
225
+ }
226
+ const queued = state.queue.get(change.userId);
227
+ if (queued?.signature === signature) continue;
228
+ const user = userMap.get(change.userId);
229
+ if (!user) continue;
230
+ change.observedAt = state.candidates.get(change.userId)!.since;
231
+ const pendingChannels = new Set(channels.filter((c) => user.effectGroups.includes(c.id)).map((c) => c.id as string));
232
+ if (pendingChannels.size) state.queue.set(change.userId, { signature, change, queuedAt: now, pendingChannels });
233
+ }
234
+ // 每个群从其首条稳定动态入队开始计时,到期后一次汇总。
235
+ for (const channel of channels) {
236
+ if (shouldStop()) return;
237
+ const entries = [...state.queue.values()].filter((entry) => {
238
+ const candidate = state.candidates.get(entry.change.userId);
239
+ return entry.pendingChannels.has(channel.id)
240
+ && observed.has(userMap.get(entry.change.userId)?.steamId || "")
241
+ && candidate?.signature === entry.signature
242
+ && now - candidate.since >= stableMs;
243
+ });
244
+ if (!entries.length || now - Math.min(...entries.map((e) => e.queuedAt)) < mergeMs) continue;
245
+ const bot = ctx.bots[`${channel.platform}:${channel.assignee}`] || Object.values(ctx.bots).find(
246
+ (item) => item.platform === channel.platform && (item.selfId === channel.assignee || item.user?.id === channel.assignee),
247
+ );
248
+ if (!bot) { logger.warn(`未找到群组 ${channel.id} 对应的机器人,保留待发送播报`); continue; }
249
+ try {
250
+ const lines: string[] = [];
251
+ for (const entry of entries) {
252
+ const change = entry.change;
253
+ const display: GameChangeInfo = {
254
+ ...change,
255
+ oldGame: change.oldGame ? await getLocalizedGameName(ctx, change.oldGameId, change.oldGame) : undefined,
256
+ newGame: change.newGame ? await getLocalizedGameName(ctx, change.newGameId, change.newGame) : undefined,
257
+ };
258
+ const nickname = await getUserNickname(ctx, change.userId, channel.id);
259
+ lines.push(`• ${buildBroadcastText(nickname || change.userName, display)}`);
260
+ }
261
+ if (shouldStop()) return;
262
+ await bot.sendMessage(channel.id, `🎮 Steam 好友动态\n${lines.join("\n")}`);
263
+ for (const entry of entries) entry.pendingChannels.delete(channel.id);
264
+ } catch (error) { logger.warn(`群组 ${channel.id} 合并播报失败,将在下次轮询重试:`, error); }
265
+ }
266
+ for (const [id, entry] of state.queue) {
267
+ const user = userMap.get(id);
268
+ // 群组已关闭或解绑时不再继续投递。
269
+ for (const channelId of entry.pendingChannels) {
270
+ if (!channels.some((c) => c.id === channelId) || !user?.effectGroups.includes(channelId)) entry.pendingChannels.delete(channelId);
271
+ }
272
+ if (!entry.pendingChannels.size) {
273
+ if (await acknowledgeGameChange(ctx, entry.change, logger)) {
274
+ state.queue.delete(id);
275
+ state.candidates.delete(id);
276
+ }
277
+ }
278
+ }
279
+ }
280
+
160
281
  // 更新所有已绑定用户的头像
161
282
  export async function updatePlayerHeadshots(
162
283
  ctx: Context,
@@ -224,7 +345,10 @@ async function detectGameChanges(
224
345
  continue;
225
346
  }
226
347
 
227
- const playTime = await getCurrentPlayTime(ctx, userData.userId);
348
+ const session = await getGameSession(ctx, userData.userId);
349
+ const playDurationMs = session && Number.isFinite(session.startTime) ? Math.max(0, Date.now() - session.startTime) : undefined;
350
+ const minutes = playDurationMs === undefined ? 0 : Math.floor(playDurationMs / 60000);
351
+ const playTime = minutes > 0 ? formatPlayTime(minutes) : undefined;
228
352
  const userName = useSteamName ? player.personaname : userData.userName;
229
353
 
230
354
  if (newGame && !oldGame) {
@@ -245,6 +369,7 @@ async function detectGameChanges(
245
369
  newGame,
246
370
  newGameId,
247
371
  playTime,
372
+ playDurationMs,
248
373
  };
249
374
  } else if (!newGame && oldGame) {
250
375
  changes[userData.userId] = {
@@ -254,6 +379,7 @@ async function detectGameChanges(
254
379
  oldGame,
255
380
  oldGameId,
256
381
  playTime,
382
+ playDurationMs,
257
383
  };
258
384
  }
259
385
  }
@@ -261,22 +387,17 @@ async function detectGameChanges(
261
387
  return changes;
262
388
  }
263
389
 
264
- async function getCurrentPlayTime(
265
- ctx: Context,
266
- userId: string,
267
- ): Promise<string | undefined> {
268
- const session = await getGameSession(ctx, userId);
269
- if (!session) return undefined;
270
-
271
- const minutes = Math.floor((Date.now() - session.startTime) / 60000);
272
- return minutes > 0 ? formatPlayTime(minutes) : undefined;
390
+ function isShortSession(change: GameChangeInfo, config: SteamBroadcastConfig): boolean {
391
+ const threshold = Math.max(0, config.minStopPlayMinutes ?? 10) * 60_000;
392
+ return (change.status === "stop" || change.status === "change")
393
+ && change.playDurationMs !== undefined && change.playDurationMs < threshold;
273
394
  }
274
395
 
275
396
  function buildBroadcastText(
276
397
  displayName: string,
277
398
  changeInfo: GameChangeInfo,
278
399
  ): string {
279
- if (changeInfo.status === "start") {
400
+ if (changeInfo.status === "start" || (changeInfo.status === "change" && changeInfo.suppressEnd)) {
280
401
  return `${displayName} 开始玩 ${changeInfo.newGame} 了`;
281
402
  }
282
403
 
@@ -320,13 +441,13 @@ async function acknowledgeGameChange(
320
441
  ctx: Context,
321
442
  changeInfo: GameChangeInfo,
322
443
  logger: PluginLogger,
323
- ): Promise<void> {
444
+ ): Promise<boolean> {
324
445
  try {
325
446
  if (changeInfo.status === "start") {
326
- await startGameSession(ctx, changeInfo.userId, changeInfo.newGame || "");
447
+ await startGameSession(ctx, changeInfo.userId, changeInfo.newGame || "", changeInfo.observedAt);
327
448
  } else if (changeInfo.status === "change") {
328
449
  await endGameSession(ctx, changeInfo.userId);
329
- await startGameSession(ctx, changeInfo.userId, changeInfo.newGame || "");
450
+ await startGameSession(ctx, changeInfo.userId, changeInfo.newGame || "", changeInfo.observedAt);
330
451
  } else {
331
452
  await endGameSession(ctx, changeInfo.userId);
332
453
  }
@@ -336,11 +457,13 @@ async function acknowledgeGameChange(
336
457
  { userId: changeInfo.userId },
337
458
  { lastPlayedGame: changeInfo.newGame || "", lastPlayedGameId: changeInfo.newGameId || "" },
338
459
  );
460
+ return true;
339
461
  } catch (error) {
340
462
  logger.error(
341
463
  `播报已发送,但更新用户 ${changeInfo.userId} 的游戏状态失败:`,
342
464
  error,
343
465
  );
466
+ return false;
344
467
  }
345
468
  }
346
469
 
package/src/image.ts CHANGED
@@ -286,7 +286,7 @@ export async function getFriendStatusImg(
286
286
  (config.showOfflineFriends && offlineUsers.length > 0 ? 1 : 0);
287
287
  const totalHeight = 75 + 30 + 15 + displayedGroups * 28 + displayedUsers * 46;
288
288
  await page.setViewport({
289
- width: 227,
289
+ width: 360,
290
290
  height: totalHeight,
291
291
  deviceScaleFactor: 2,
292
292
  });
@@ -653,7 +653,7 @@ export async function getGameChangeImg(
653
653
  "..",
654
654
  "data",
655
655
  "res",
656
- "gaming.png",
656
+ "game_change_background.png",
657
657
  );
658
658
  const backgroundBase64 = fs.readFileSync(backgroundPath, "base64");
659
659
  htmlContent = htmlContent
@@ -670,6 +670,7 @@ export async function getGameChangeImg(
670
670
  // 4. 使用 Puppeteer 截图
671
671
  const page = await ctx.puppeteer.page();
672
672
  try {
673
+ await page.setViewport({ width: 380, height: 200 });
673
674
  await page.setContent(htmlContent);
674
675
 
675
676
  const clip = await page.evaluate(() => {
package/src/index.ts CHANGED
@@ -70,7 +70,7 @@ export const Config = Schema.intersect([
70
70
  interval: Schema.number()
71
71
  .default(60)
72
72
  .min(10)
73
- .description("查询间隔,单位:秒"),
73
+ .description("查询间隔,单位:秒;状态稳定期需经后续轮询确认,建议不大于稳定期"),
74
74
  useSteamName: Schema.boolean()
75
75
  .default(true)
76
76
  .description("使用Steam昵称,关闭时使用的QQ昵称"),
@@ -79,6 +79,30 @@ export const Config = Schema.intersect([
79
79
  .description("播报时附带图片"),
80
80
  }).description("基础设置"),
81
81
 
82
+ Schema.object({
83
+ mergeBroadcast: Schema.boolean()
84
+ .default(true)
85
+ .description("合并窗口内的游戏状态播报"),
86
+ mergeWindow: Schema.number()
87
+ .default(180)
88
+ .min(1)
89
+ .step(1)
90
+ .description("合并播报窗口,单位:秒"),
91
+ stabilityPeriod: Schema.number()
92
+ .default(30)
93
+ .min(0)
94
+ .step(1)
95
+ .description("状态稳定期,单位:秒;需通过后续轮询确认"),
96
+ minStopPlayMinutes: Schema.number()
97
+ .default(10)
98
+ .min(0)
99
+ .step(1)
100
+ .description("结束播报最短游戏时长(分钟),设为 0 关闭过滤;时长未知时仍播报"),
101
+ immediateBroadcast: Schema.boolean()
102
+ .default(false)
103
+ .description("即时播报,跳过合并窗口和状态稳定期"),
104
+ }).description("播报设置"),
105
+
82
106
  Schema.object({
83
107
  useApifoxProxy: Schema.boolean()
84
108
  .default(true)
@@ -154,6 +178,11 @@ export interface PluginConfig {
154
178
  interval: number;
155
179
  useSteamName: boolean;
156
180
  broadcastWithImage: boolean;
181
+ mergeBroadcast: boolean;
182
+ mergeWindow: number;
183
+ stabilityPeriod: number;
184
+ immediateBroadcast: boolean;
185
+ minStopPlayMinutes: number;
157
186
  useApifoxProxy: boolean;
158
187
  maxRetries: number;
159
188
  showcardmode: "1" | "2";
package/src/types.ts CHANGED
@@ -31,6 +31,9 @@ export interface GameChangeInfo {
31
31
  oldGame?: string;
32
32
  newGame?: string;
33
33
  playTime?: string;
34
+ playDurationMs?: number;
35
+ suppressEnd?: boolean;
36
+ observedAt?: number;
34
37
  oldGameId?: string;
35
38
  newGameId?: string;
36
39
  }
package/src/userdata.ts CHANGED
@@ -98,11 +98,11 @@ async function saveGameSessionsLocked(ctx: Context, data: GameSessionsData): Pro
98
98
  /**
99
99
  * 记录用户开始玩游戏
100
100
  */
101
- export async function startGameSession(ctx: Context, userId: string, gameName: string): Promise<void> {
101
+ export async function startGameSession(ctx: Context, userId: string, gameName: string, startTime: number = Date.now()): Promise<void> {
102
102
  const sessions = await loadGameSessionsLocked(ctx);
103
103
  sessions[userId] = {
104
104
  gameName,
105
- startTime: Date.now(),
105
+ startTime,
106
106
  };
107
107
  await saveGameSessionsLocked(ctx, sessions);
108
108
  }