Skip to content

Commit

Permalink
perf: steam状态改为图片
Browse files Browse the repository at this point in the history
  • Loading branch information
XasYer committed Dec 1, 2024
1 parent 36868fe commit 10cfb83
Show file tree
Hide file tree
Showing 5 changed files with 170 additions and 19 deletions.
39 changes: 22 additions & 17 deletions apps/info.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import moment from 'moment'
import { segment } from '#lib'
import { App, Config } from '#components'
import { App, Config, Render } from '#components'
import { db, utils, api } from '#models'

const app = {
Expand All @@ -26,23 +26,28 @@ export const rule = {
return true
}
const info = data.pop()
const avatarBuffer = Config.other.steamAvatar ? await utils.getImgUrlBuffer(info.avatarfull) : ''
const msg = []
avatarBuffer && msg.push(segment.image(avatarBuffer), '\n')
msg.push([
`好友代码: ${utils.getFriendCode(info.steamid)}`,
`steamId: ${info.steamid}`,
`用户名称: ${info.personaname}`,
`当前状态: ${utils.getPersonaState(info.personastate)}`,
`最后下线: ${moment.unix(info.lastlogoff).format('YYYY-MM-DD HH:mm:ss')}`,
`注册时间: ${moment.unix(info.timecreated).format('YYYY-MM-DD HH:mm:ss')}`,
`账号地区: ${getLoccountryCode(info.loccountrycode)}`
].join('\n'))
if (info.gameid) {
const icon = utils.getHeaderImgUrlByAppid(info.gameid)
msg.push('\n', segment.image(icon), `\n正在游玩: ${info.gameextrainfo}`)
const color = info.gameid ? 1 : info.personastate === 0 ? 3 : 2
const bg = await api.IPlayerService.GetProfileItemsEquipped(steamId)
const img = await Render.render('info/index', {
background: utils.getStaticUrl(bg.mini_profile_background.image_large),
frame: utils.getStaticUrl(bg.avatar_frame.image_small),
avatar: Config.other.steamAvatar ? info.avatarfull : utils.getUserAvatar(e.self_id, uid, e.group_id),
name: info.personaname,
status: utils.getPersonaState(info.personastate),
gameId: info.gameid,
gameName: info.gameextrainfo,
friendCode: utils.getFriendCode(info.steamid),
createTime: moment.unix(info.timecreated).format('YYYY-MM-DD HH:mm:ss'),
lastTime: (info.lastlogoff && info.personastate === 0) ? moment.unix(info.lastlogoff).format('YYYY-MM-DD HH:mm:ss') : '',
country: info.loccountrycode ? getLoccountryCode(info.loccountrycode) : '',
color,
scale: 1.4
})
if (img) {
await e.reply(img)
} else {
await e.reply([segment.at(uid), '\n截图失败了, 重试一下吧'])
}
await e.reply(msg)
return true
}
}
Expand Down
4 changes: 2 additions & 2 deletions models/api/IPlayerService.js
Original file line number Diff line number Diff line change
Expand Up @@ -359,9 +359,9 @@ export async function GetProfileItemsEquipped (steamid) {
params: {
steamid
}
}.then(res => {
}).then(res => {
const data = res.data.response || {}
logger.info(`获取${steamid}头像背景信息等成功,耗时${Date.now() - start}ms`)
return data
}))
})
}
11 changes: 11 additions & 0 deletions models/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,17 @@ export function getHeaderImgUrlByAppid (appid) {
return `https://steamcdn-a.akamaihd.net/steam/apps/${appid}/header.jpg`
}

/**
* 获取静态资源url items/xxx
* @param {string} path
*/
export function getStaticUrl (path) {
if (path?.startsWith('items')) {
return `https://cdn.fastly.steamstatic.com/steamcommunity/public/images/${path}`
}
return ''
}

/**
* 获取图片buffer
* @param {string} url
Expand Down
78 changes: 78 additions & 0 deletions resources/info/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}

#container {
width: 593px;
height: 561px;
font-size: 20px;
}

.color-1 {
color: #90ba3c
}

.color-2 {
color: #57cbde;
}

.color-3 {
color: #898989
}

#profile {
width: 563px;
height: 502px;
padding: 20px;
}

#avatar-box {
display: flex;
margin-bottom: 10px;
}

#avatar-frame {
position: absolute;
width: 164px;
height: 164px;
}

#avatar-frame>img {
width: 200px;
height: 200px;
margin: -18px;
}

#name-box {
margin-left: 20px;
display: flex;
flex-direction: column;
justify-content: center;
}

#profile-name {
font-size: 30px;
white-space: nowrap;
}

#profile-status {
margin-top: 10px;
}

#playing-box {
margin-top: 20px;
display: flex;
}

#playing-info {
margin-left: 20px;
display: flex;
flex-direction: column;
justify-content: center;
}

#profile-info {
line-height: 2;
}
57 changes: 57 additions & 0 deletions resources/info/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{{extend defaultLayout}}

{{block 'css'}}
<link rel="stylesheet" type="text/css" href="{{pluResPath}}info/index.css" />
<style>
#container {
background: url({{background}}) no-repeat #363a42;
}
</style>
{{/block}}

{{block 'main'}}

<div id="profile" class="color-{{color}}">
<div id="avatar-box">
{{if frame}}
<div id="avatar-frame">
<img src="{{frame}}">
</div>
{{/if}}
<img src="{{avatar}}" width="164" height="164">
<div id="name-box">
<div id="profile-name">{{name}}</div>
<div id="profile-status">{{status}}</div>
</div>
</div>
{{if gameId}}
<div id="playing-box">
<div>
<img src="https://steamcdn-a.akamaihd.net/steam/apps/{{gameId}}/header.jpg" width="164">
</div>
<div id="playing-info">
<div>游戏中</div>
<div>{{gameName}}</div>
</div>
</div>
{{/if}}
<div id="profile-info">
<div>
好友代码: {{friendCode}}
</div>
<div>
注册时间: {{createTime}}
</div>
{{if lastTime}}
<div>
最后在线: {{lastTime}}
</div>
{{/if}}
{{if country}}
<div>
账号地区: {{country}}
</div>
{{/if}}
</div>
</div>
{{/block}}

0 comments on commit 10cfb83

Please sign in to comment.