UNPKG

steam-family-bot-core

Version:

一个用于新版 Steam 家庭的库存监控 Bot 插件

62 lines 2.84 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.Stats = void 0; const jsx_runtime_1 = require("react/jsx-runtime"); const graph_1 = __importDefault(require("../components/graph")); const lodash_1 = __importDefault(require("lodash")); const node_steam_family_group_api_1 = require("node-steam-family-group-api"); const getPlaytime = (data) => { const appids = data.entries.flatMap((it) => it.appid); const appidsByOwner = data.entriesByOwner.flatMap((it) => it.appid); const allIds = lodash_1.default.uniq(appids.concat(appidsByOwner)); const appPlaytimeDict = lodash_1.default.groupBy(data.entries, 'appid'); const appPlaytimeByOwnerDict = lodash_1.default.groupBy(data.entriesByOwner, 'appid'); return allIds.map((id) => { let res = []; const owners = appPlaytimeByOwnerDict[id]; const players = appPlaytimeDict[id]; if (owners) { res = res.concat(owners.map((owner) => ({ ...owner, isOwner: true }))); } if (players) { res = res.concat(players.map((player) => ({ ...player, isOwner: false }))); } return { appid: id, players: res, }; }); }; const getPlayer = (familyInfo, memberInfos) => { const familyData = familyInfo?.familyGroup; const memberFamilyInfos = lodash_1.default.keyBy(familyData.members, 'steamid'); const members = memberInfos.accounts.map((account) => { const id = account?.publicData?.steamid; const avatar_hash = (0, node_steam_family_group_api_1.shaDigestAvatarToStrAvatarHash)(account?.publicData?.shaDigestAvatar); return { ...account.publicData, avatar_hash, ...memberFamilyInfos[id], }; }); return members; }; const getLibs = (libs) => { return libs.map((it) => ({ ...it, rtTimeAcquired: it.rtTimeAcquired ?? 0, ownerSteamids: it.steamIds.split(','), mappedTags: it.info?.top20Tags?.split(',') ?? [], })); }; function Stats({ familyGames }) { const bg = `https://www.loliapi.com/acg/pe/`; const player = getPlayer(familyGames.familyInfo, familyGames.members); const recentAppDetail = familyGames.recentAppDetail.storeItems; return ((0, jsx_runtime_1.jsx)("div", { className: 'flex min-h-screen w-fit flex-col items-center justify-between bg-red-500', children: (0, jsx_runtime_1.jsx)(graph_1.default, { players: player, libsPlaytime: getPlaytime(familyGames.playtimeSummary), family: familyGames.familyInfo, bg: bg, libs: getLibs(familyGames.games), recentLibs: recentAppDetail }) })); } exports.Stats = Stats; //# sourceMappingURL=stats.js.map