From 4c4b4c0ff1f10e251a2a89f9cd217b146b8179a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E5=8F=B6?= <1936472877@qq.com> Date: Fri, 21 Feb 2025 23:35:05 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20steam=E6=B6=88=E8=B4=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/expend.js | 39 +++++++++++++++++++++++++++++++++++++++ models/api/store.js | 32 +++++++++++++++++++++++++++++--- models/help/help.js | 4 ++++ 3 files changed, 72 insertions(+), 3 deletions(-) create mode 100644 apps/expend.js diff --git a/apps/expend.js b/apps/expend.js new file mode 100644 index 0000000..9d3c9ef --- /dev/null +++ b/apps/expend.js @@ -0,0 +1,39 @@ +import { App } from '#components' +import { api } from '#models' +import _ from 'lodash' + +const appInfo = { + id: 'expend', + name: '支出' +} + +const rule = { + total: { + reg: App.getReg('总?(支出|消费|花费)'), + cfg: { + accessToken: true, + tip: true + }, + fnc: async (e, { cookie }) => { + const html = await api.store.AjaxLoadMoreHistory(cookie) + if (!html) { + return '获取失败或消费为空' + } + let currency + const data = html.replace(/[\n\t]/g, '').split('').filter(i => !/(退款|wht_refunded|钱包<)/.test(i)).map(i => { + const reg = /([\s\S]+?)<\/td>/ + const regRet = reg.exec(i) + if (regRet) { + const res = regRet[1].split(' ') + currency = res[0] + return parseFloat(res[1]) || 0 + } + return 0 + }) + const total = _.sum(data) + return `在steam消费了${currency} ${total.toFixed(2)}\n数据来源: 由 客服 -> 购买消费 -> 查看完整的购买记录 计算而来 仅供参考` + } + } +} + +export const app = new App(appInfo, rule).create() diff --git a/models/api/store.js b/models/api/store.js index e1fe68d..65730f6 100644 --- a/models/api/store.js +++ b/models/api/store.js @@ -1,5 +1,6 @@ import { utils } from '#models' import { Config } from '#components' +import moment from 'moment' export function getBaseURL () { const url = 'https://store.steampowered.com' @@ -269,9 +270,10 @@ export async function addtowishlist (cookie, appid) { */ export async function removefromwishlist (cookie, appid) { const sessionid = cookie.split(';').find(i => i.includes('sessionid')).split('=')[1] - const data = new URLSearchParams() - data.append('appid', appid) - data.append('sessionid', sessionid) + const data = new URLSearchParams([ + ['sessionid', sessionid], + ['appid', appid] + ]) return utils.request.post('api/removefromwishlist', { baseURL: getBaseURL(), headers: { @@ -300,3 +302,27 @@ export async function ajaxgetpartnerevent (clanAccountid, announcementGid) { } }).then(res => res.event || {}) } + +/** + * 消费历史记录 + * @param {string} cookie + * @returns {Promise} + */ +export async function AjaxLoadMoreHistory (cookie) { + const sessionid = cookie.split(';').find(i => i.includes('sessionid')).split('=')[1] + const data = new URLSearchParams([ + ['sessionid', sessionid], + ['cursor[wallet_txnid]', 0], + ['cursor[timestamp_newest]', moment().unix()], + ['cursor[balance]', 0], + ['cursor[currency]', 23] + ]) + return utils.request.post('account/AjaxLoadMoreHistory/', { + baseURL: getBaseURL(), + headers: { + Cookie: cookie, + 'Content-Type': 'application/x-www-form-urlencoded' + }, + data + }).then(res => res.html || '') +} diff --git a/models/help/help.js b/models/help/help.js index d654ff6..bcf4431 100644 --- a/models/help/help.js +++ b/models/help/help.js @@ -85,6 +85,10 @@ export const helpList = [ title: '#steam删除ak', desc: '删除access_token' }, + { + title: '#steam消费', + desc: '查看在steam总消费多少' + }, { title: '#steam家庭库存', desc: '查看家庭库存'