Skip to content

Commit

Permalink
feat: steam搜索
Browse files Browse the repository at this point in the history
  • Loading branch information
XasYer committed Nov 20, 2024
1 parent 0a31520 commit 9d15f14
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 3 deletions.
1 change: 0 additions & 1 deletion apps/info.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ export const rule = {
await e.reply([segment.at(uid), '\n还没有绑定steamId哦, 先绑定steamId吧'])
return true
}
e.reply([segment.at(uid), '\n在查了...在查了...'])
// TODO: 先获取https://steamcommunity.com/profiles/${steamId}/
const data = await api.ISteamUser.GetPlayerSummaries(steamId)
if (!data.length) {
Expand Down
51 changes: 51 additions & 0 deletions apps/search.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { api } from '#models'
import { App, Render } from '#components'

const app = {
id: 'search',
name: '搜索'
}

export const rule = {
search: {
reg: /^#?steam(?:搜索|search|查找|find)\s*(.*)$/i,
fnc: async e => {
const name = rule.search.reg.exec(e.msg)[1].trim()
if (!name) {
await e.reply('要搜什么?')
return true
}
const result = await api.search(name)
const games = result.split('</a>').map(i => {
if (!i.includes('appid')) {
return null
}
const appid = i.match(/data-ds-appid="(\d+)"/)?.[1]
const name = i.match(/class="match_name">(.*?)<\/div>/)?.[1]
const price = i.match(/class="match_price">(.*?)<\/div>/)?.[1]
return {
appid,
name,
price_overview: {
discount_percent: 0,
initial_formatted: price
}
}
}).filter(Boolean)
const screenshotOptions = {
title: `${name} 搜索结果`,
games,
type: 'wishlist'
}
const img = await Render.simpleRender('inventory/index', screenshotOptions)
if (img) {
await e.reply(img)
} else {
await e.reply('制作图片出错辣! 再试一次吧')
}
return true
}
}
}

export const search = new App(app, rule).create()
2 changes: 1 addition & 1 deletion apps/setting.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,4 @@ export const rule = {
}
}

export const settingPlugin = new App(app, rule).create()
export const settingApp = new App(app, rule).create()
26 changes: 25 additions & 1 deletion models/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export async function appdetails (appid) {
params: {
appids: appid,
l: 'schinese',
cc: 'cn'
cc: 'CN'
}
}).then(res => {
if (res.data[appid].success) {
Expand All @@ -115,3 +115,27 @@ export async function appdetails (appid) {
}
})
}

/**
* 搜索游戏
* @param {string} name
* @returns {Promise<string>}
*/
export async function search (name) {
const start = Date.now()
logger.info(`开始搜索${name}游戏`)
return utils.request.get('search/suggest', {
baseURL: 'https://store.steampowered.com',
params: {
term: name,
f: 'games',
cc: 'CN',
realm: 1,
l: 'schinese'
},
responseType: 'text'
}).then(res => {
logger.info(`搜索${name}成功,耗时${Date.now() - start}ms`)
return res.data.replace?.(/\n/g, '')
})
}
5 changes: 5 additions & 0 deletions models/help/help.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ export const helpList = [
icon: 14,
title: '#steam愿望单',
desc: '查看steam愿望单'
},
{
icon: 31,
title: '#steam搜索',
desc: '查看steam游戏'
}
]
}
Expand Down

0 comments on commit 9d15f14

Please sign in to comment.