diff --git a/adapter/v3-entrance.js b/adapter/v3-entrance.js
deleted file mode 100644
index ab04c1fb..00000000
--- a/adapter/v3-entrance.js
+++ /dev/null
@@ -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
- }
-}
diff --git a/apps/index.js b/apps/index.js
index 1a16be07..1fd673ba 100644
--- a/apps/index.js
+++ b/apps/index.js
@@ -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 }
diff --git a/apps/stat.js b/apps/stat.js
index 205ffb7d..a30f5499 100644
--- a/apps/stat.js
+++ b/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
diff --git a/components/App.js b/components/App.js
index e4e8a7f7..27b71560 100644
--- a/components/App.js
+++ b/components/App.js
@@ -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 || ''
diff --git a/components/Common.js b/components/Common.js
index 9180dca5..759d6512 100644
--- a/components/Common.js
+++ b/components/Common.js
@@ -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${Version.yunzai} & Miao-Plugin${Version.version}`
- }
- }
- 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) {
diff --git a/components/common-lib/render.js b/components/common-lib/render.js
new file mode 100644
index 00000000..092df0c8
--- /dev/null
+++ b/components/common-lib/render.js
@@ -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${Version.yunzai} & Miao-Plugin${Version.version}`
+ }
+ }
+ 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
+}