Miao-Yunzai/plugins/genshin/model/base.js

77 lines
2.1 KiB
JavaScript
Raw Normal View History

import fs from 'node:fs'
import _ from 'lodash'
2024-01-25 00:56:49 +08:00
import cfg from '../../../lib/config/config.js'
import { Common, Version } from '#miao'
import { Character } from '#miao.models'
2023-03-04 14:30:13 +08:00
export default class base {
2024-01-25 00:56:49 +08:00
constructor(e = {}) {
2023-03-04 14:30:13 +08:00
this.e = e
this.userId = e?.user_id
this.model = 'genshin'
this._path = process.cwd().replace(/\\/g, '/')
}
2024-01-25 00:56:49 +08:00
get prefix() {
2023-03-04 14:30:13 +08:00
return `Yz:genshin:${this.model}:`
}
// 统一封装渲染
2024-01-25 00:56:49 +08:00
async renderImg(tpl, data, cfg = {}) {
return Common.render('genshin', `html/${tpl}`, data, {
...cfg,
e: this.e
})
}
2023-03-04 14:30:13 +08:00
/**
* 截图默认数据
* @param saveId html保存id
* @param tplFile 模板html路径
* @param pluResPath 插件资源路径
*/
2024-01-25 00:56:49 +08:00
get screenData() {
const layoutPath = process.cwd() + '/plugins/genshin/resources/html/layout/'
2024-01-25 00:56:49 +08:00
let yunzaiName = cfg.package.name
if (yunzaiName == 'miao-yunzai') {
yunzaiName = 'Miao-Yunzai'
} else if (yunzaiName == 'yunzai') {
yunzaiName = 'Yunzai-Bot'
} else if (yunzaiName == 'trss-yunzai') {
yunzaiName = 'TRSS-Yunzai'
} else {
yunzaiName = _.capitalize(yunzaiName)
}
let data = {
saveId: this.userId,
cwd: this._path,
yzVersion: `v${Version.yunzai}`,
2024-01-25 00:56:49 +08:00
yzName: yunzaiName,
genshinLayout: layoutPath + 'genshin.html',
defaultLayout: layoutPath + 'default.html'
}
if (this.e?.isSr) {
2024-01-18 17:55:23 +08:00
let char = Character.get('真理医生', 'sr')
2023-08-18 10:19:48 +08:00
return {
...data,
2023-08-18 10:19:48 +08:00
tplFile: `./plugins/genshin/resources/StarRail/html/${this.model}/${this.model}.html`,
/** 绝对路径 */
pluResPath: `${this._path}/plugins/genshin/resources/StarRail/`,
srtempFile: 'StarRail/',
headImg: char?.imgs?.banner,
game: 'sr',
2023-08-18 10:19:48 +08:00
}
}
let char = Character.get('闲云', 'gs')
2023-03-04 14:30:13 +08:00
return {
...data,
2023-03-04 14:30:13 +08:00
tplFile: `./plugins/genshin/resources/html/${this.model}/${this.model}.html`,
/** 绝对路径 */
pluResPath: `${this._path}/plugins/genshin/resources/`,
headImg: char?.imgs?.banner,
srtempFile: '',
game: 'gs',
2023-03-04 14:30:13 +08:00
}
}
}