UNPKG

steam-family-bot-core

Version:

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

89 lines 3.19 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); // todo // const builder_1 = require("../cmd/builder"); class TmpLock { tmpFamilyLock = []; hasFamilyId(familyId) { return this.tmpFamilyLock.some((it) => it === familyId); } inFamilyId(familyId) { this.tmpFamilyLock.push(familyId); } outFamilyId(familyId) { this.tmpFamilyLock = this.tmpFamilyLock.filter((it) => it !== familyId); } } const tmpLock = new TmpLock(); exports.default = () => new builder_1.CommandBuilder() .setName('stats') .setDescription('generate stats info for steam family') .addAlias('sbstats') .addOption('r', 'remote:boolean?') .setExecutor(async (c) => { const { render, steamService, logger, session, options } = c; if (!render.isRenderEnable()) { await session.sendQueued(session.text('commands.statistic.no-render')); return; } const tmp = await steamService.db.Account.getSteamAccountBySessionUid(session.uid); if (!tmp) { await session.sendQueued(session.text('commands.statistic.no-binding')); return; } if (!tmp.familyId) { await session.sendQueued(session.text('commands.statistic.no-family')); return; } if (tmpLock.hasFamilyId(tmp.familyId)) { await session.sendQueued(session.text('commands.statistic.repeat-render', { familyId: tmp.familyId, })); return; } else { tmpLock.inFamilyId(tmp.familyId); } const account = await steamService.db.Account.getAuthedSteamAccountByFamilyId(tmp.familyId); // get same const valid = await steamService.validAccount(account); if (!valid) { await session.sendQueued(session.text('commands.statistic.token-invalid')); tmpLock.outFamilyId(tmp.familyId); return; } const onStart = () => { session.sendQueued(session.text('commands.statistic.render-start')); }; const onError = () => { session.sendQueued(session.text('commands.statistic.render-error')); }; if (options.r) { const token = account.steamAccessToken; try { const res = await render.screenshotFamilyStatistic(token, () => { session.sendQueued(session.text('commands.statistic.need-wait-long-time')); }); await session.sendImgBuffer(res); } catch (e) { logger.error(`render error ${e}`); await session.sendQueued(session.text('commands.statistic.render-remote-error')); } } else { session.send(session.text('commands.statistic.fetching-steam-data')); try { const familyGames = await steamService.getLibStatistic(account.steamAccessToken); const buffer = await render.getFamilyStatisticImg(familyGames, onStart, onError); await session.sendImgBuffer(buffer); } catch (e) { logger.error(`render error ${e}`); await session.sendQueued(session.text('commands.statistic.render-error')); } } tmpLock.outFamilyId(tmp.familyId); }); //# sourceMappingURL=statistic.js.map