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 9d15f14 commit b7000a8
Show file tree
Hide file tree
Showing 7 changed files with 168 additions and 24 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,12 @@ pnpm install --filter=steam-plugin
- [x] 群友状态播报
- [x] steam帮助
- [x] steam设置
- [ ] steam搜索
- [x] steam搜索
- [ ] steam成就统计
- [ ] 群友上下线通知
- [ ] steam喜加一
- [ ] 开启/关闭推送
- [x] steam特惠

## 联系方式

Expand Down
73 changes: 73 additions & 0 deletions apps/discounts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import { App, Render } from '#components'
import { api } from '#models'
import moment from 'moment'

const app = {
id: 'discounts',
name: '优惠'
}

export const rule = {
discounts: {
reg: /^#?steam(优惠|特惠|热销|新品|即将推出)$/,
fnc: async e => {
e.reply('在查了....在查了')
const res = await api.featuredcategories()
const items = [
{
title: '优惠',
key: 'specials'
},
{
title: '即将推出',
key: 'coming_soon'
},
{
title: '热销',
key: 'top_sellers'
},
{
title: '新品',
key: 'new_releases'
}
]
const data = []
for (const item of items) {
const key = {
title: item.title,
type: 'wishlist',
games: []
}
for (const i of res[item.key].items) {
key.games.push({
appid: i.id,
name: i.name,
date_added: i.discount_expiration ? moment.unix(i.discount_expiration).format('YYYY-MM-DD HH:mm:ss') : '',
header_image: i.header_image,
header_image_type: i.header_image.match(/store_item_assets\/steam\/(.+?)\//)?.[1] || 'apps',
price_overview: i.discounted
? {
initial_formatted: ${i.original_price / 100}`,
discount_percent: i.discount_percent,
final_formatted: ${i.final_price / 100}`
}
: {
initial_formatted: i.original_price ? ${i.original_price / 100}` : '',
discount_percent: 0
}
})
}
data.push(key)
}
const img = await Render.simpleRender('inventory/index', { data })
if (img) {
await e.reply(img)
} else {
await e.reply('制作图片出错辣! 再试一次吧')
}
return true
}
}
}

export const discounts = new App(app, rule).create()
20 changes: 9 additions & 11 deletions apps/inventory.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ export const rule = {
title: '',
games: [],
type: 'inventory',
playtime_forever: 0,
playtime_2weeks: 0
desc: ''
}
if (e.msg.includes('近')) {
const games = await api.IPlayerService.GetRecentlyPlayedGames(steamId)
Expand Down Expand Up @@ -83,20 +82,19 @@ export const rule = {
screenshotOptions.title = `${nickname} 库存共有 ${games.length} 个游戏`
}
if (screenshotOptions.type !== 'wishlist') {
let playtimeForever = 0
let playtime2weeks = 0
screenshotOptions.games.map(i => {
i.time_info = `${getTime(i.playtime_forever)} ${i.playtime_2weeks ? `/ ${getTime(i.playtime_2weeks)}` : ''}`
screenshotOptions.playtime_forever += i.playtime_forever
i.playtime_2weeks && (screenshotOptions.playtime_2weeks += i.playtime_2weeks)
playtimeForever += i.playtime_forever
i.playtime_2weeks && (playtime2weeks += i.playtime_2weeks)
return i
})
screenshotOptions.playtime_forever = getTime(
screenshotOptions.playtime_forever
)
screenshotOptions.playtime_2weeks = getTime(
screenshotOptions.playtime_2weeks
)
screenshotOptions.desc = `总游戏时长:${getTime(playtimeForever)} / 最近两周游戏时长:${getTime(playtime2weeks)}`
}
const img = await Render.simpleRender('inventory/index', screenshotOptions)
const img = await Render.simpleRender('inventory/index', {
data: [screenshotOptions]
})
if (img) {
await e.reply(img)
} else {
Expand Down
2 changes: 1 addition & 1 deletion apps/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export const rule = {
games,
type: 'wishlist'
}
const img = await Render.simpleRender('inventory/index', screenshotOptions)
const img = await Render.simpleRender('inventory/index', { data: [screenshotOptions] })
if (img) {
await e.reply(img)
} else {
Expand Down
61 changes: 61 additions & 0 deletions models/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,64 @@ export async function search (name) {
return res.data.replace?.(/\n/g, '')
})
}

/**
* @typedef {Object} items
* @property {number} id appid
* @property {number} type 未知
* @property {string} name 游戏名
* @property {boolean} discounted 是否正在打折
* @property {number} discount_percent 折扣率
* @property {number} original_price 原价(需要 / 100)
* @property {number} final_price 现价(需要 / 100)
* @property {string} currency 货币单位
* @property {string} large_capsule_image 大图
* @property {string} small_capsule_image 小图
* @property {boolean} windows_available windows是否可用
* @property {boolean} mac_available mac是否可用
* @property {boolean} linux_available linux是否可用
* @property {boolean} streamingvideo_available 未知
* @property {number} discount_expiration 打折结束时间
* @property {string} header_image header图
* @property {string} controller_support 未知
*/

/**
* 获取优惠信息
* @returns {Promise<{
* specials: {
* id: string,
* name: string,
* items: items[]
* },
* coming_soon: {
* id: string,
* name: string,
* items: items[]
* },
* top_sellers: {
* id: string,
* name: string,
* items: items[]
* },
* new_releases: {
* id: string,
* name: string,
* items: items[]
* }
* }>}
*/
export async function featuredcategories () {
const start = Date.now()
logger.info('开始获取优惠信息')
return utils.request.get('api/featuredcategories', {
baseURL: 'https://store.steampowered.com',
params: {
l: 'schinese',
cc: 'CN'
}
}).then(res => {
logger.info(`获取优惠信息成功,耗时${Date.now() - start}ms`)
return res.data
})
}
5 changes: 5 additions & 0 deletions models/help/help.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ export const helpList = [
icon: 31,
title: '#steam搜索',
desc: '查看steam游戏'
},
{
icon: 32,
title: '#steam特惠',
desc: '查看steam热销游戏'
}
]
}
Expand Down
28 changes: 17 additions & 11 deletions resources/inventory/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
display: flex;
justify-content: space-around;
flex-wrap: wrap;
width: 890px;
}

.games>div {
Expand Down Expand Up @@ -56,6 +57,7 @@

.wishlist-info {
width: 220px;
margin-right: 10px;
}

.inventory-info {
Expand Down Expand Up @@ -105,37 +107,40 @@

<body>
<div id="container">
{{each data item}}
<div class="header">
<h2>{{title}}</h2>
<h2>{{item.title}}</h2>
<h4>
{{if type !== 'wishlist'}}
总游戏时长:{{playtime_forever}} /
最近两周游戏时长:{{playtime_2weeks}}
{{/if}}
{{item.desc}}
</h4>
</div>
<div class="games">
{{each games i}}
<div class="{{type}}">
{{each item.games i}}
<div class="{{item.type}}">
<div class="header-img">
<img src="https://steamcdn-a.akamaihd.net/steam/apps/{{i.appid}}/header.jpg">
{{if i.header_image}}
<img src="{{i.header_image}}">
{{else}}
<img
src="https://steamcdn-a.akamaihd.net/steam/{{i.header_image_type || 'apps'}}/{{i.appid}}/header.jpg">
{{/if}}
</div>
<div class="game-info overflow {{type}}-info">
<div class="game-info overflow {{item.type}}-info">
<div class="game-title">
{{i.name || ''}}
</div>
<div class="game-appid">
{{i.appid}}
</div>
<div class="game-time">
{{if type === 'wishlist'}}
{{if item.type === 'wishlist'}}
{{i.date_added || ''}}
{{else}}
{{i.time_info || ''}}
{{/if}}
</div>
</div>
{{if type === 'wishlist'}}
{{if item.type === 'wishlist'}}
<div class="overflow">
<div class="{{i.price_overview.discount_percent ? 'through' : ''}}">
{{i.price_overview.initial_formatted || i.price_overview.final_formatted || ''}}
Expand All @@ -151,6 +156,7 @@ <h4>
</div>
{{/each}}
</div>
{{/each}}
</div>
</body>

Expand Down

0 comments on commit b7000a8

Please sign in to comment.