import fs from 'node:fs' import _ from 'lodash' import { Common } from '#miao' export default class base { constructor (e = {}) { this.e = e this.userId = e?.user_id this.model = 'genshin' this._path = process.cwd().replace(/\\/g, '/') } get prefix () { return `Yz:genshin:${this.model}:` } // 统一封装渲染 async renderImg (tpl, data, cfg = {}) { return Common.render('genshin', `html/${tpl}`, data, { ...cfg, e: this.e }) } /** * 截图默认数据 * @param saveId html保存id * @param tplFile 模板html路径 * @param pluResPath 插件资源路径 */ get screenData () { if (this.e?.isSr) { let headImg = _.sample(fs.readdirSync(`${this._path}/plugins/genshin/resources/StarRail/img/worldcard`).filter(file => file.endsWith('.png'))) return { saveId: this.userId, cwd: this._path, tplFile: `./plugins/genshin/resources/StarRail/html/${this.model}/${this.model}.html`, /** 绝对路径 */ pluResPath: `${this._path}/plugins/genshin/resources/StarRail/`, headStyle: ``, srtempFile: 'StarRail/' } } let headImg = _.sample(fs.readdirSync(`${this._path}/plugins/genshin/resources/img/namecard`).filter(file => file.endsWith('.png'))) return { saveId: this.userId, cwd: this._path, tplFile: `./plugins/genshin/resources/html/${this.model}/${this.model}.html`, /** 绝对路径 */ pluResPath: `${this._path}/plugins/genshin/resources/`, headStyle: ``, srtempFile: '' } } }