Skip to content

Commit

Permalink
feat: 帮助 & 设置
Browse files Browse the repository at this point in the history
  • Loading branch information
XasYer committed Nov 20, 2024
1 parent a456ff2 commit aedc7d8
Show file tree
Hide file tree
Showing 27 changed files with 495 additions and 245 deletions.
38 changes: 7 additions & 31 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,10 @@
### Features

* 适配karin ([a80de7e](https://github.com/XasYer/steam-plugin/commit/a80de7e7579c8d9f71e5fb511e21fd305d047185))

## 1.3.0 (2024-11-17)


### Features

* steam愿望单

## 1.2.0 (2024-11-16)


### Features

* steam库存
* steam最近游玩

## 1.1.0 (2024-11-16)


### Features

* steam信息

## 1.0.0 (2024-11-15)


### Features

* steam绑定
* steam解除绑定
* 游玩通知 结束通知
* steam愿望单 ([20e7795](https://github.com/XasYer/steam-plugin/commit/20e7795bd766ebe38b696ec5ea4837d521918171))
* steam库存 ([20e7795](https://github.com/XasYer/steam-plugin/commit/20e7795bd766ebe38b696ec5ea4837d521918171))
* steam最近游玩 ([20e7795](https://github.com/XasYer/steam-plugin/commit/20e7795bd766ebe38b696ec5ea4837d521918171))
* steam信息 ([20e7795](https://github.com/XasYer/steam-plugin/commit/20e7795bd766ebe38b696ec5ea4837d521918171))
* steam绑定 ([20e7795](https://github.com/XasYer/steam-plugin/commit/20e7795bd766ebe38b696ec5ea4837d521918171))
* steam解除绑定 ([20e7795](https://github.com/XasYer/steam-plugin/commit/20e7795bd766ebe38b696ec5ea4837d521918171))
* 游玩通知 结束通知 ([20e7795](https://github.com/XasYer/steam-plugin/commit/20e7795bd766ebe38b696ec5ea4837d521918171))
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ pnpm install --filter=steam-plugin
- [x] steam最近游玩
- [x] steam愿望单
- [x] 群友状态播报
- [ ] 帮助
- [ ] 设置
- [x] 帮助
- [x] 设置
- [ ] steam搜索
- [ ] steam成就统计
- [ ] 群友上下线通知
Expand Down
2 changes: 1 addition & 1 deletion apps/bind.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export const rule = {
}
},
unbind: {
reg: /^#?steam(?:解除?绑定?|unbind)\s*(\d+)$/i,
reg: /^#?steam(?:解除?绑定?|unbind|取消绑定)\s*(\d+)$/i,
fnc: async e => {
const textId = rule.unbind.reg.exec(e.msg)[1]
if (!textId) {
Expand Down
67 changes: 67 additions & 0 deletions apps/help.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import { App, Render, Version } from '#components'
import lodash from 'lodash'
import { help as helpUtil } from '#models'

const app = {
id: 'help',
name: '帮助'
}

export const rule = {
help: {
reg: /^#?steam(插件|plugin)?(帮助|菜单|help)$/i,
fnc: help
}
// version: {
// reg: /^#?steam(插件|plugin)?(版本|version)$/i,
// fnc: version
// }
}

export const helpApp = new App(app, rule).create()

async function help (e) {
const helpGroup = []

lodash.forEach(helpUtil.helpList, (group) => {
if (group.auth && group.auth === 'master' && !e.isMaster) {
return true
}

lodash.forEach(group.list, (help) => {
const icon = help.icon * 1
if (!icon) {
help.css = 'display:none'
} else {
const x = (icon - 1) % 10
const y = (icon - x - 1) / 10
help.css = `background-position:-${x * 50}px -${y * 50}px`
}
})

helpGroup.push(group)
})
const themeData = await helpUtil.helpTheme.getThemeData(helpUtil.helpCfg)
const img = await Render.render('help/index', {
helpCfg: helpUtil.helpCfg,
helpGroup,
...themeData,
scale: 1.2
})
if (img) {
await e.reply(img)
} else {
await e.reply('截图失败辣! 再试一次叭')
}
return true
}

// eslint-disable-next-line no-unused-vars
async function version (e) {
const img = await Render.render('help/version-info', {
currentVersion: Version.version,
changelogs: Version.changelogs,
scale: 1.2
})
return await e.reply(img)
}
72 changes: 72 additions & 0 deletions apps/setting.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import { App, Config, Render } from '#components'
import lodash from 'lodash'
import { setting } from '#models'

const keys = lodash.map(setting.getCfgSchemaMap(), (i) => i.key)

const app = {
id: 'setting',
name: '设置'
}

export const rule = {
setting: {
reg: new RegExp(`^#steam设置\\s*(${keys.join('|')})?\\s*(.*)$`),
fnc: async e => {
const regRet = rule.setting.reg.exec(e.msg)
const cfgSchemaMap = setting.getCfgSchemaMap()
if (!regRet) {
return true
}

if (regRet[1]) {
// 设置模式
let val = regRet[2] || ''

if (regRet[1] == '全部') {
val = !/关闭/.test(val)
for (const i of keys) {
if (typeof cfgSchemaMap[i].def == 'boolean') {
if (cfgSchemaMap[i].key == '全部') {
await redis.set('steam-plugin:set-all', val ? 1 : 0)
} else {
Config.modify(cfgSchemaMap[i].fileName, cfgSchemaMap[i].cfgKey, val)
}
}
}
} else {
const cfgSchema = cfgSchemaMap[regRet[1]]
if (cfgSchema.input) {
val = cfgSchema.input(val)
} else {
if (cfgSchema.type === 'number') {
val = val * 1 || cfgSchema.def
} else if (cfgSchema.type === 'boolean') {
val = !/关闭/.test(val)
} else if (cfgSchema.type === 'string') {
val = val.trim() || cfgSchema.def
}
}
Config.modify(cfgSchema.fileName, cfgSchema.cfgKey, val)
}
}

const schema = setting.cfgSchema
const cfg = Config.getCfg()
cfg.setAll = (await redis.get('steam-plugin:set-all')) == 1

const img = await Render.render('setting/index', {
schema,
cfg
}, { e, scale: 1.4 })
if (img) {
await e.reply(img)
} else {
await e.reply('截图失败辣! 再试一次叭')
}
return true
}
}
}

export const settingPlugin = new App(app, rule).create()
10 changes: 10 additions & 0 deletions components/Config.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class Config {
if (!fs.existsSync(path)) fs.mkdirSync(path)
const pathDef = `${Version.pluginPath}/config/default_config/`
const files = fs.readdirSync(pathDef).filter(file => file.endsWith('.yaml'))
this.files = files
const ignore = []
for (const file of files) {
if (!fs.existsSync(`${path}${file}`)) {
Expand Down Expand Up @@ -123,6 +124,15 @@ class Config {
return this.config[key]
}

/** 获取所有配置 */
getCfg () {
return {
...this.files.map(file => this.getDefOrConfig(file.replace('.yaml', ''))).reduce((obj, item) => {
return { ...obj, ...item }
}, {})
}
}

/** 监听配置文件 */
watch (file, name, type = 'default_config') {
const key = `${type}.${name}`
Expand Down
4 changes: 2 additions & 2 deletions components/Render.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { puppeteer } from '#lib'
import { Version } from '#components'

function scale (pct = 1) {
const scale = Math.min(2, Math.max(0.5, 100 / 100))
const scale = Math.min(2, Math.max(0.5, 150 / 100))
pct = pct * scale
return `style=transform:scale(${pct})`
}
Expand All @@ -20,7 +20,7 @@ const Render = {
defaultLayout: join(layoutPath, 'default.html'),
sys: {
scale: scale(params.scale || 1),
copyright: params.copyright || `Created By <span class="version"> ${Version.BotName} v${Version.BotVersion} </span> & <span class="version"> ${Version.pluginName} v${Version.version} </span>`
copyright: params.copyright || `Created By <span class="version"> ${Version.BotName} v${Version.BotVersion} </span> & <span class="version"> ${Version.pluginName} v${Version.pluginVersion} </span>`
},
...params
}
Expand Down
24 changes: 24 additions & 0 deletions models/help/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
export const style = {
// 主文字颜色
fontColor: '#ceb78b',
// 主文字阴影: 横向距离 垂直距离 阴影大小 阴影颜色
// fontShadow: '0px 0px 1px rgba(6, 21, 31, .9)',
fontShadow: 'none',
// 描述文字颜色
descColor: '#eee',

/* 面板整体底色,会叠加在标题栏及帮助行之下,方便整体帮助有一个基础底色
* 若无需此项可将rgba最后一位置为0即为完全透明
* 注意若综合透明度较低,或颜色与主文字颜色过近或太透明可能导致阅读困难 */
contBgColor: 'rgba(6, 21, 31, .5)',

// 面板底图毛玻璃效果,数字越大越模糊,0-10 ,可为小数
contBgBlur: 3,

// 板块标题栏底色
headerBgColor: 'rgba(6, 21, 31, .4)',
// 帮助奇数行底色
rowBgColor1: 'rgba(6, 21, 31, .2)',
// 帮助偶数行底色
rowBgColor2: 'rgba(6, 21, 31, .35)'
}
46 changes: 46 additions & 0 deletions models/help/help.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
export const helpCfg = {
themeSet: false,
title: 'steam帮助',
subTitle: '',
colCount: 3,
colWidth: 265,
theme: 'all',
bgBlur: true
}
export const helpList = [
{
group: 'steam 信息',
list: [
{
icon: 9,
title: '#steam绑定',
desc: '绑定steamid或好友码'
},
{
icon: 10,
title: '#steam解除绑定',
desc: '解除绑定steamid或好友码'
},
{
icon: 11,
title: '#steam状态',
desc: '查看steam个人状态'
},
{
icon: 12,
title: '#steam库存',
desc: '查看steam库存'
},
{
icon: 13,
title: '#steam最近游玩',
desc: '查看steam最近游玩'
},
{
icon: 14,
title: '#steam愿望单',
desc: '查看steam愿望单'
}
]
}
]
6 changes: 6 additions & 0 deletions models/help/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import helpTheme from './theme.js'
export { helpCfg, helpList } from './help.js'

export {
helpTheme
}
53 changes: 53 additions & 0 deletions models/help/theme.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import lodash from 'lodash'
import { style } from './config.js'

const helpTheme = {
getThemeCfg () {
const resPath = `{{pluResPath}}help/theme/${lodash.random(1, 5)}.png`
return {
main: resPath,
bg: resPath,
style
}
},
async getThemeData (diyStyle) {
const helpConfig = lodash.extend({}, diyStyle)
const colCount = Math.min(5, Math.max(parseInt(helpConfig?.colCount) || 3, 2))
const colWidth = Math.min(500, Math.max(100, parseInt(helpConfig?.colWidth) || 265))
const width = Math.min(2500, Math.max(800, colCount * colWidth + 30))
const theme = helpTheme.getThemeCfg()
const themeStyle = theme.style || {}
const ret = [`
body{background-image:url(${theme.bg});width:${width}px;}
.container{background-image:url(${theme.main});width:${width}px;}
.help-table .td,.help-table .th{width:${100 / colCount}%}
`]
const defFnc = (...args) => {
for (const idx in args) {
if (!lodash.isUndefined(args[idx])) {
return args[idx]
}
}
}
const css = function (sel, css, key, def, fn) {
let val = defFnc(themeStyle[key], diyStyle[key], def)
if (fn) {
val = fn(val)
}
ret.push(`${sel}{${css}:${val}}`)
}
css('.help-title,.help-group', 'color', 'fontColor', '#ceb78b')
css('.help-title,.help-group', 'text-shadow', 'fontShadow', 'none')
css('.help-desc', 'color', 'descColor', '#eee')
css('.cont-box', 'background', 'contBgColor', 'rgba(43, 52, 61, 0.8)')
css('.cont-box', 'backdrop-filter', 'contBgBlur', 3, (n) => diyStyle.bgBlur === false ? 'none' : `blur(${n}px)`)
css('.help-group', 'background', 'headerBgColor', 'rgba(34, 41, 51, .4)')
css('.help-table .tr:nth-child(odd)', 'background', 'rowBgColor1', 'rgba(34, 41, 51, .2)')
css('.help-table .tr:nth-child(even)', 'background', 'rowBgColor2', 'rgba(34, 41, 51, .4)')
return {
style: `<style>${ret.join('\n')}</style>`,
colCount
}
}
}
export default helpTheme
2 changes: 2 additions & 0 deletions models/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ export * as bind from './bind/index.js'
export * as utils from './utils/index.js'
export * as api from './api/index.js'
export * as task from './task/index.js'
export * as help from './help/index.js'
export * as setting from './setting/index.js'
Loading

0 comments on commit aedc7d8

Please sign in to comment.