Skip to content

Commit

Permalink
feat: steam消费
Browse files Browse the repository at this point in the history
  • Loading branch information
XasYer committed Feb 21, 2025
1 parent 50fc95f commit 4c4b4c0
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 3 deletions.
39 changes: 39 additions & 0 deletions apps/expend.js
Original file line number Diff line number Diff line change
@@ -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('</tr>').filter(i => !/(退|wht_refunded|<)/.test(i)).map(i => {
const reg = /<td\s*class="wht_total\s*">([\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()
32 changes: 29 additions & 3 deletions models/api/store.js
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -300,3 +302,27 @@ export async function ajaxgetpartnerevent (clanAccountid, announcementGid) {
}
}).then(res => res.event || {})
}

/**
* 消费历史记录
* @param {string} cookie
* @returns {Promise<string>}
*/
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 || '')
}
4 changes: 4 additions & 0 deletions models/help/help.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ export const helpList = [
title: '#steam删除ak',
desc: '删除access_token'
},
{
title: '#steam消费',
desc: '查看在steam总消费多少'
},
{
title: '#steam家庭库存',
desc: '查看家庭库存'
Expand Down

0 comments on commit 4c4b4c0

Please sign in to comment.