mirror of
https://github.com/yoimiya-kokomi/miao-plugin.git
synced 2024-11-16 04:35:42 +00:00
#深渊组队
适配V3
This commit is contained in:
parent
14fa6739b9
commit
6acfb6417a
@ -1,50 +0,0 @@
|
||||
import * as Miao from '../apps/index.js'
|
||||
import { checkAuth, getMysApi } from './mys.js'
|
||||
import { plugin } from './index.js'
|
||||
|
||||
export class miao extends plugin {
|
||||
constructor () {
|
||||
let rule = {
|
||||
reg: '.+',
|
||||
fnc: 'dispatch'
|
||||
}
|
||||
super({
|
||||
name: 'miao-plugin',
|
||||
desc: '喵喵插件',
|
||||
event: 'message',
|
||||
priority: 50,
|
||||
rule: [rule]
|
||||
})
|
||||
Object.defineProperty(rule, 'log', {
|
||||
get: () => !!this.isDispatch
|
||||
})
|
||||
}
|
||||
|
||||
accept () {
|
||||
this.e.original_msg = this.e.original_msg || this.e.msg
|
||||
}
|
||||
|
||||
async dispatch (e) {
|
||||
let msg = e.original_msg || ''
|
||||
if (!msg) {
|
||||
return false
|
||||
}
|
||||
e.checkAuth = async function (cfg) {
|
||||
return await checkAuth(e, cfg)
|
||||
}
|
||||
e.getMysApi = async function (cfg) {
|
||||
return await getMysApi(e, cfg)
|
||||
}
|
||||
for (let fn in Miao.rule) {
|
||||
let cfg = Miao.rule[fn]
|
||||
if (Miao[fn] && new RegExp(cfg.reg).test(msg)) {
|
||||
let ret = await Miao[fn](e, {})
|
||||
if (ret === true) {
|
||||
this.isDispatch = true
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
}
|
@ -4,18 +4,18 @@ import admin from './admin.js'
|
||||
import stat from './stat.js'
|
||||
import wiki from './wiki.js'
|
||||
|
||||
export const characterApp = character.v2()
|
||||
export const adminApp = admin.v2()
|
||||
export const helpApp = help.v2()
|
||||
export const statApp = stat.v2()
|
||||
export const wikiApp = wiki.v2()
|
||||
export const characterApp = character.v2App()
|
||||
export const adminApp = admin.v2App()
|
||||
export const helpApp = help.v2App()
|
||||
export const statApp = stat.v2App()
|
||||
export const wikiApp = wiki.v2App()
|
||||
|
||||
let apps = { character, admin, help, stat, wiki }
|
||||
let rule = {} // v2
|
||||
let rules = {} // v3
|
||||
for (let key in apps) {
|
||||
rule[`${key}App`] = apps[key].rule()
|
||||
rules[`${key}`] = apps[key].app()
|
||||
rule[`${key}App`] = apps[key].v2Rule()
|
||||
rules[`${key}`] = apps[key].v3App()
|
||||
}
|
||||
|
||||
export { rule, rules as apps }
|
||||
|
33
apps/stat.js
33
apps/stat.js
@ -228,9 +228,6 @@ async function getTalentData (e, isUpdate = false) {
|
||||
}
|
||||
|
||||
async function abyssTeam (e) {
|
||||
if (Common.todoV3(e)) {
|
||||
return true
|
||||
}
|
||||
let MysApi = await e.getMysApi({
|
||||
auth: 'cookie', // 所有用户均可查询
|
||||
targetType: 'self', // 被查询用户可以是任意用户
|
||||
@ -247,19 +244,31 @@ async function abyssTeam (e) {
|
||||
return true
|
||||
}
|
||||
abyssData = abyssData.data
|
||||
let talentData = await getTalentData(e)
|
||||
if (!talentData || talentData.length === 0) {
|
||||
e.reply('暂时未能获得角色的练度信息,请使用【#练度统计】命令尝试手工获取...')
|
||||
return true
|
||||
let uid = e.selfUser.uid
|
||||
let resDetail
|
||||
try {
|
||||
if (!await Avatars.hasTalentCache(uid)) {
|
||||
e.reply('正在获取用户信息,请稍候...')
|
||||
}
|
||||
resDetail = await MysApi.getCharacter()
|
||||
if (!resDetail || !resDetail.avatars || resDetail.avatars.length <= 3) {
|
||||
e.reply('角色信息获取失败')
|
||||
return true
|
||||
}
|
||||
} catch (err) {
|
||||
// console.log(err);
|
||||
}
|
||||
|
||||
let avatars = new Avatars(uid, resDetail.avatars)
|
||||
let avatarIds = avatars.getIds()
|
||||
let avatarData = await avatars.getTalentData(avatarIds, MysApi)
|
||||
let avatarRet = {}
|
||||
let data = {}
|
||||
|
||||
let noAvatar = {}
|
||||
|
||||
lodash.forEach(talentData, (avatar) => {
|
||||
avatarRet[avatar.id] = Math.min(avatar.level, avatar.weapon_level) * 100 + Math.max(avatar.a_original, avatar.e_original, avatar.q_original) * 1000
|
||||
lodash.forEach(avatarData, (avatar) => {
|
||||
let t = avatar.talent
|
||||
avatarRet[avatar.id] = Math.min(avatar.level, avatar.weapon?.level || 1) * 100 + Math.max(t.a?.original, t.e?.original, t.q?.original) * 1000
|
||||
})
|
||||
|
||||
let getTeamCfg = (str) => {
|
||||
@ -394,12 +403,12 @@ async function abyssTeam (e) {
|
||||
|
||||
let avatarMap = {}
|
||||
|
||||
lodash.forEach(talentData, (ds) => {
|
||||
lodash.forEach(avatarData, (ds) => {
|
||||
let char = Character.get(ds.id)
|
||||
avatarMap[ds.id] = {
|
||||
id: ds.id,
|
||||
name: ds.name,
|
||||
star: ds.rarity,
|
||||
star: ds.star,
|
||||
level: ds.level,
|
||||
cons: ds.cons,
|
||||
face: char.face
|
||||
|
@ -16,7 +16,8 @@ class App {
|
||||
}
|
||||
}
|
||||
|
||||
app () {
|
||||
// 获取v3执行方法
|
||||
v3App () {
|
||||
let cfg = this.cfg || {}
|
||||
let rules = []
|
||||
|
||||
@ -67,7 +68,7 @@ class App {
|
||||
}
|
||||
|
||||
// 获取v2版rule
|
||||
rule () {
|
||||
v2Rule () {
|
||||
let cfg = this.cfg
|
||||
return {
|
||||
reg: 'noCheck',
|
||||
@ -78,7 +79,7 @@ class App {
|
||||
}
|
||||
|
||||
// v2执行方法
|
||||
v2 (e) {
|
||||
v2App (e) {
|
||||
let apps = this.apps
|
||||
return async function (e) {
|
||||
let msg = e.original_msg || e.msg || ''
|
||||
|
@ -1,51 +1,7 @@
|
||||
import Cfg from './Cfg.js'
|
||||
import { Data, Version } from './index.js'
|
||||
import { puppeteer } from '../adapter/index.js'
|
||||
import fs from 'fs'
|
||||
import { Version } from './index.js'
|
||||
|
||||
const plugin = 'miao-plugin'
|
||||
const _path = process.cwd()
|
||||
|
||||
export const render = async function (path, params, cfg) {
|
||||
let [app, tpl] = path.split('/')
|
||||
let { e } = cfg
|
||||
let layoutPath = process.cwd() + '/plugins/miao-plugin/resources/common/layout/'
|
||||
let resPath = `../../../../../plugins/${plugin}/resources/`
|
||||
Data.createDir(`data/html/${plugin}/${app}/${tpl}`, 'root')
|
||||
let data = {
|
||||
...params,
|
||||
_plugin: plugin,
|
||||
saveId: params.saveId || params.save_id || tpl,
|
||||
tplFile: `./plugins/${plugin}/resources/${app}/${tpl}.html`,
|
||||
pluResPath: resPath,
|
||||
_res_path: resPath,
|
||||
_layout_path: layoutPath,
|
||||
_tpl_path: process.cwd() + '/plugins/miao-plugin/resources/common/tpl/',
|
||||
defaultLayout: layoutPath + 'default.html',
|
||||
elemLayout: layoutPath + 'elem.html',
|
||||
sys: {
|
||||
scale: Cfg.scale(cfg.scale || 1),
|
||||
copyright: `Created By Yunzai-Bot<span class="version">${Version.yunzai}</span> & Miao-Plugin<span class="version">${Version.version}</span>`
|
||||
}
|
||||
}
|
||||
if (global.debugView === 'web-debug') {
|
||||
// debug下保存当前页面的渲染数据,方便模板编写与调试
|
||||
// 由于只用于调试,开发者只关注自己当时开发的文件即可,暂不考虑app及plugin的命名冲突
|
||||
let saveDir = _path + '/data/ViewData/'
|
||||
if (!fs.existsSync(saveDir)) {
|
||||
fs.mkdirSync(saveDir)
|
||||
}
|
||||
let file = saveDir + tpl + '.json'
|
||||
data._app = app
|
||||
fs.writeFileSync(file, JSON.stringify(data))
|
||||
}
|
||||
let base64 = await puppeteer.screenshot(`miao-plugin/${app}/${tpl}`, data)
|
||||
let ret = true
|
||||
if (base64) {
|
||||
ret = await e.reply(base64)
|
||||
}
|
||||
return cfg.retMsgId ? ret : true
|
||||
}
|
||||
import render from './common-lib/render.js'
|
||||
|
||||
export const todoV3 = function (e) {
|
||||
if (Version.isV3) {
|
||||
|
48
components/common-lib/render.js
Normal file
48
components/common-lib/render.js
Normal file
@ -0,0 +1,48 @@
|
||||
import { Data, Version } from '../index.js'
|
||||
import Cfg from '../Cfg.js'
|
||||
import fs from 'fs'
|
||||
import { puppeteer } from '../../adapter/index.js'
|
||||
|
||||
const plugin = 'miao-plugin'
|
||||
const _path = process.cwd()
|
||||
|
||||
export default async function (path, params, cfg) {
|
||||
let [app, tpl] = path.split('/')
|
||||
let { e } = cfg
|
||||
let layoutPath = process.cwd() + '/plugins/miao-plugin/resources/common/layout/'
|
||||
let resPath = `../../../../../plugins/${plugin}/resources/`
|
||||
Data.createDir(`data/html/${plugin}/${app}/${tpl}`, 'root')
|
||||
let data = {
|
||||
...params,
|
||||
_plugin: plugin,
|
||||
saveId: params.saveId || params.save_id || tpl,
|
||||
tplFile: `./plugins/${plugin}/resources/${app}/${tpl}.html`,
|
||||
pluResPath: resPath,
|
||||
_res_path: resPath,
|
||||
_layout_path: layoutPath,
|
||||
_tpl_path: process.cwd() + '/plugins/miao-plugin/resources/common/tpl/',
|
||||
defaultLayout: layoutPath + 'default.html',
|
||||
elemLayout: layoutPath + 'elem.html',
|
||||
sys: {
|
||||
scale: Cfg.scale(cfg.scale || 1),
|
||||
copyright: `Created By Yunzai-Bot<span class="version">${Version.yunzai}</span> & Miao-Plugin<span class="version">${Version.version}</span>`
|
||||
}
|
||||
}
|
||||
if (global.debugView === 'web-debug') {
|
||||
// debug下保存当前页面的渲染数据,方便模板编写与调试
|
||||
// 由于只用于调试,开发者只关注自己当时开发的文件即可,暂不考虑app及plugin的命名冲突
|
||||
let saveDir = _path + '/data/ViewData/'
|
||||
if (!fs.existsSync(saveDir)) {
|
||||
fs.mkdirSync(saveDir)
|
||||
}
|
||||
let file = saveDir + tpl + '.json'
|
||||
data._app = app
|
||||
fs.writeFileSync(file, JSON.stringify(data))
|
||||
}
|
||||
let base64 = await puppeteer.screenshot(`miao-plugin/${app}/${tpl}`, data)
|
||||
let ret = true
|
||||
if (base64) {
|
||||
ret = await e.reply(base64)
|
||||
}
|
||||
return cfg.retMsgId ? ret : true
|
||||
}
|
Loading…
Reference in New Issue
Block a user