Miao-Yunzai/plugins/genshin/apps/role.js

117 lines
3.4 KiB
JavaScript
Raw Normal View History

2023-03-04 14:30:13 +08:00
import plugin from '../../../lib/plugins/plugin.js'
import fs from 'node:fs'
import gsCfg from '../model/gsCfg.js'
import RoleIndex from '../model/roleIndex.js'
import Abyss from '../model/abyss.js'
import Weapon from '../model/weapon.js'
2023-03-04 14:30:13 +08:00
export class role extends plugin {
2023-12-27 18:15:06 +08:00
constructor() {
2023-03-04 14:30:13 +08:00
super({
name: '角色查询',
dsc: '原神角色信息查询',
event: 'message',
priority: 200,
rule: [{
reg: '^(#*角色3|#*角色卡片|角色)$',
fnc: 'roleCard'
}, {
reg: '^#[上期|往期|本期]*(深渊|深境|深境螺旋)[上期|往期|本期]*[ |0-9]*$',
fnc: 'abyss'
}, {
reg: '^#*[上期|往期|本期]*(深渊|深境|深境螺旋)[上期|往期|本期]*[第]*(9|10|11|12|九|十|十一|十二)层[ |0-9]*$',
fnc: 'abyssFloor'
}, {
reg: '^#[五星|四星|5星|4星]*武器[ |0-9]*$',
fnc: 'weapon'
}, {
reg: '^#(宝箱|成就|尘歌壶|家园|探索|探险|声望|探险度|探索度)[ |0-9]*$',
fnc: 'roleExplore'
}]
2023-03-04 14:30:13 +08:00
})
2023-12-27 18:15:06 +08:00
Object.defineProperty(this, "button", { get() {
this.prefix = this.e?.isSr ? "*" : "#"
return segment.button([
{ text: "角色", callback: `${this.prefix}角色` },
{ text: "探索", callback: `${this.prefix}探索` },
{ text: "武器", callback: `${this.prefix}武器` },
{ text: "深渊", callback: `${this.prefix}深渊` },
])
}})
2023-03-04 14:30:13 +08:00
}
/** 初始化配置文件 */
2023-12-27 18:15:06 +08:00
async init() {
2023-03-04 14:30:13 +08:00
let pubCk = './plugins/genshin/config/mys.pubCk.yaml'
if (!fs.existsSync(pubCk)) {
fs.copyFileSync('./plugins/genshin/defSet/mys/pubCk.yaml', pubCk)
}
let set = './plugins/genshin/config/mys.set.yaml'
if (!fs.existsSync(set)) {
fs.copyFileSync('./plugins/genshin/defSet/mys/set.yaml', set)
}
}
/** 接受到消息都会先执行一次 */
2023-12-27 18:15:06 +08:00
accept() {
2023-03-04 14:30:13 +08:00
if (!this.e.msg) return
if (!/^#(.*)$/.test(this.e.msg)) return
let role = gsCfg.getRole(this.e.msg)
if (role) {
/** 设置命令 */
this.e.msg = '#角色详情'
if (role.uid) this.e.msg += role.uid
/** 角色id */
this.e.roleId = role.roleId
/** 角色名称 */
this.e.roleName = role.alias
return true
}
}
/** 深渊 */
2023-12-27 18:15:06 +08:00
async abyss() {
2023-03-04 14:30:13 +08:00
let data = await new Abyss(this.e).getAbyss()
console.log('abyss', data)
2023-03-04 14:30:13 +08:00
if (!data) return
this.reply([await this.renderImg('genshin', 'html/abyss/abyss', data, { retType: "base64" }), this.button])
2023-03-04 14:30:13 +08:00
}
/** 深渊十二层 */
2023-12-27 18:15:06 +08:00
async abyssFloor() {
2023-03-04 14:30:13 +08:00
let data = await new Abyss(this.e).getAbyssFloor()
if (!data) return
this.reply([await this.renderImg('genshin', 'html/abyss/abyss-floor', data, { retType: "base64" }), this.button])
2023-03-04 14:30:13 +08:00
}
/** 武器 */
2023-12-27 18:15:06 +08:00
async weapon() {
2023-03-04 14:30:13 +08:00
let data = await Weapon.get(this.e)
if (!data) return
this.reply([await this.renderImg('genshin', 'html/avatar/weapon', data, { retType: "base64" }), this.button])
2023-03-04 14:30:13 +08:00
}
/** 角色卡片 */
2023-12-27 18:15:06 +08:00
async roleCard() {
2023-03-04 14:30:13 +08:00
let data = await new RoleIndex(this.e).roleCard()
if (!data) return
this.reply([await this.renderImg('genshin', 'html/player/role-card', data, { retType: "base64" }), this.button])
2023-03-04 14:30:13 +08:00
}
/** 探险 */
2023-12-27 18:15:06 +08:00
async roleExplore() {
2023-03-04 14:30:13 +08:00
let data = await new RoleIndex(this.e).roleExplore()
if (!data) return
this.reply([await this.renderImg('genshin', 'html/player/role-explore', data, { retType: "base64" }), this.button])
2023-03-04 14:30:13 +08:00
}
}