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

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/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 = recentlyPlayed.games.map((game) => ({
364
- name: game.name,
365
- // 将分钟转换为小时
366
- hours: `${(game.playtime_forever / 60).toFixed(1)} \u5C0F\u65F6`,
367
- // 构建游戏横幅图片的URL
368
- img: `https://cdn.akamai.steamstatic.com/steam/apps/${game.appid}/header.jpg`
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 gamingUsers = userData.response.players.filter((p) => p.gameextrainfo);
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;
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.1",
4
+ "version": "0.3.2",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [
package/readme.md CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  ## 本版本的主要改动
6
6
 
7
- - **游戏活动播报名称本地化**:通过正在游玩的 Steam App ID 查询 Steam 商店简体中文名称,并用于开始、切换和停止游戏的文字及图片播报。好友列表与个人资料显示不受此修改影响。
7
+ - **游戏活动播报名称本地化**:通过正在游玩的 Steam App ID 查询 Steam 商店简体中文名称,并用于开始、切换和停止游戏的文字及图片播报,`看看steam` 好友列表图片,以及 Steam 个人资料卡片中的最近游戏列表。
8
8
  - **兼容回退**:查询失败、游戏没有可用 App ID 或没有商店页面时,使用 Steam 返回的原始名称,不阻断播报。Steam 商店未提供中文名的游戏仍可能显示英文。
9
9
  - **缓存查询结果**:名称缓存于内存;成功结果缓存 24 小时,失败结果缓存 5 分钟,插件重启后清空。相同游戏的并发查询会合并。
10
10
  - **保留原始状态判断**:继续使用 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 gamingUsers = userData.response.players.filter((p) => p.gameextrainfo);
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);
package/src/steam.ts CHANGED
@@ -187,13 +187,16 @@ export async function getSteamProfile(
187
187
  ctx.config.SteamApiKey,
188
188
  steamId,
189
189
  );
190
- profile.recentGames = recentlyPlayed.games.map((game) => ({
191
- name: game.name,
192
- // 将分钟转换为小时
193
- hours: `${(game.playtime_forever / 60).toFixed(1)} 小时`,
194
- // 构建游戏横幅图片的URL
195
- img: `https://cdn.akamai.steamstatic.com/steam/apps/${game.appid}/header.jpg`,
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) {