底层架构升级,App拆分维护

This commit is contained in:
yoimiya-kokomi 2022-09-17 04:37:09 +08:00
parent ea0210fe98
commit 17ba8c73b8
11 changed files with 297 additions and 205 deletions

View File

@ -1,11 +1,13 @@
# 1.10.6
# 2.0 Alpha.1
* 内部版本,底层架构升级
* 稳定前不会增加新功能,暂不建议更新
# 1.10.1~1.10.6
* 面板圣遗物评分初步增加流派判定能力
* 实验性,尚未完全稳定,可能会导致一些角色圣遗物评分变化,如遇问题请反馈
* 目前实验暴力芭芭拉、血牛钟离的判定
# 1.10.1~1.10.5
* `#刻晴面板`、`#芭芭拉圣遗物`支持展示角色时装
* 如果角色装备了时装,面板的角色图会展示时装立绘
* 需要重新`#更新面板`以获取时装数据

View File

@ -1,7 +1,7 @@
import fs from 'fs'
import lodash from 'lodash'
import { exec } from 'child_process'
import { Cfg, Common, Data } from '../components/index.js'
import { Cfg, Common, Data, App } from '../components/index.js'
let cfgMap = {
角色: 'char.char',
@ -17,29 +17,32 @@ let cfgMap = {
渲染: 'sys.scale',
帮助: 'sys.help'
}
let sysCfgReg = `^#喵喵设置\\s*(${lodash.keys(cfgMap).join('|')})?\\s*(.*)$`
export const rule = {
updateRes: {
hashMark: true,
reg: '^#喵喵(更新图像|图像更新)$',
describe: '【#管理】更新素材'
},
updateMiaoPlugin: {
hashMark: true,
reg: '^#喵喵(强制)?更新',
describe: '【#管理】喵喵更新'
},
sysCfg: {
hashMark: true,
reg: sysCfgReg,
describe: '【#管理】系统设置'
},
profileCfg: {
hashMark: true,
reg: '^#喵喵面板(?:设置)?.*',
describe: '【#管理】面板设置'
}
}
let app = App.init({
id: 'admin',
name: '喵喵设置',
desc: '喵喵设置'
})
let sysCfgReg = new RegExp(`^#喵喵设置\\s*(${lodash.keys(cfgMap).join('|')})?\\s*(.*)$`)
app.reg('update-res', updateRes, {
rule: /^#喵喵(更新图像|图像更新)$/,
desc: '【#管理】更新素材'
})
app.reg('update', updateMiaoPlugin, {
rule: /^#喵喵(强制)?更新/,
desc: '【#管理】喵喵更新'
})
app.reg('sys-cfg', sysCfg, {
rule: sysCfgReg,
desc: '【#管理】系统设置'
})
app.reg('profile-cfg', profileCfg, {
rule: /^#喵喵面板(?:设置)?.*/,
desc: '面板设置'
})
export default app
const _path = process.cwd()
const resPath = `${_path}/plugins/miao-plugin/resources/`
@ -53,12 +56,12 @@ const checkAuth = async function (e) {
})
}
export async function sysCfg (e) {
async function sysCfg (e) {
if (!await checkAuth(e)) {
return true
}
let cfgReg = new RegExp(sysCfgReg)
let cfgReg = sysCfgReg
let regRet = cfgReg.exec(e.msg)
if (!regRet) {
@ -111,7 +114,7 @@ const getStatus = function (rote, def = true) {
}
}
export async function updateRes (e) {
async function updateRes (e) {
if (!await checkAuth(e)) {
return true
}
@ -152,7 +155,7 @@ export async function updateRes (e) {
let timer
export async function updateMiaoPlugin (e) {
async function updateMiaoPlugin (e) {
if (!await checkAuth(e)) {
return true
}
@ -200,7 +203,7 @@ export async function updateMiaoPlugin (e) {
return true
}
export async function profileCfg (e) {
async function profileCfg (e) {
if (!await checkAuth(e)) {
return true
}

View File

@ -1,28 +1,85 @@
import { Common, Cfg } from '../components/index.js'
import { renderAvatar } from './character/avatar-card.js'
import { getTargetUid, getProfile, profileHelp, getProfileAll, inputProfile } from './character/profile-common.js'
import { profileArtis } from './character/profile-artis.js'
import { renderProfile } from './character/profile-detail.js'
import { Common, Cfg, App } from '../components/index.js'
import { Character } from '../models/index.js'
//
export { getProfileAll, getProfile, profileHelp }
export { enemyLv, getOriginalPicture } from './character/utils.js'
import { renderAvatar } from './character/avatar-card.js'
import { getTargetUid, getProfile, profileHelp, inputProfile } from './character/profile-common.js'
import { profileArtis, profileArtisList } from './character/profile-artis.js'
import { renderProfile } from './character/profile-detail.js'
// 角色图像上传
export { uploadCharacterImg } from './character/character-img-upload.js'
// 圣遗物列表
export { profileArtisList } from './character/profile-artis.js'
// 老婆
export { wife, pokeWife, wifeReg } from './character/avatar-wife.js'
// 面板角色列表
export { profileList } from './character/profile-list.js'
import { uploadCharacterImg } from './character/character-img-upload.js'
// 面板练度统计
export { profileStat } from './character/profile-stat.js'
import { profileStat } from './character/profile-stat.js'
// 面板角色列表
import { profileList } from './character/profile-list.js'
// 老婆
import { wife, pokeWife, wifeReg } from './character/avatar-wife.js'
import { enemyLv, getOriginalPicture } from './character/utils.js'
let app = App.init({
id: 'character',
name: '角色查询',
desc: '角色查询'
})
app.reg('character', character, {
rule: /^(#(.*)|#*(更新|录入)?(.*)(详细|详情|面板|面版|伤害[1-7]?)(更新)?)$/,
name: '角色查询'
})
app.reg('upload-img', uploadCharacterImg, {
rule: /^#*(喵喵)?(上传|添加)(.+)(照片|写真|图片|图像)\s*$/,
name: '上传角色写真'
})
app.reg('artis-list', profileArtisList, {
rule: /^#圣遗物列表\s*(\d{9})?$/,
name: '面板圣遗物列表'
})
app.reg('profile-list', profileList, {
rule: /^#(面板角色|角色面板|面板)(列表)?\s*(\d{9})?$/,
name: '面板角色列表',
desc: '查看当前已获取面板数据的角色列表'
})
app.reg('profile-stat', profileStat, {
rule: /^#面板练度统计$/,
name: '面板练度统计$'
})
app.reg('profile-help', profileHelp, {
rule: /^#角色面板帮助$/,
name: '角色面板帮助'
})
app.reg('wife', wife, {
rule: wifeReg,
describe: '#老公 #老婆 查询'
})
app.reg('pock-wife', pokeWife, {
rule: '#poke#',
describe: '#老公 #老婆 查询'
})
app.reg('original-pic', getOriginalPicture, {
rule: /^#?(获取|给我|我要|求|发|发下|发个|发一下)?原图(吧|呗)?$/,
describe: '【#原图】 回复角色卡片,可获取原图'
})
app.reg('enemy-lv', enemyLv, {
rule: /^#(敌人|怪物)等级\s*\d{1,3}\s*$/,
describe: '【#角色】 设置伤害计算中目标敌人的等级'
})
app.reg('profile-refresh', getProfile, {
rule: /^#(全部面板更新|更新全部面板|获取游戏角色详情|更新面板|面板更新)\s*(\d{9})?$/,
describe: '【#角色】 获取游戏橱窗详情数据'
})
export default app
// 查看当前角色
export async function character (e) {
@ -39,7 +96,7 @@ export async function character (e) {
}
let name = msg.replace(/#|老婆|老公/g, '').trim()
msg = msg.replace('面版', '面板')
let dmgRet = /伤害(\d?)$/.exec(name);
let dmgRet = /伤害(\d?)$/.exec(name)
let dmgIdx = 0
if (/(详情|详细|面板|面版)\s*$/.test(msg) && !/更新|录入|输入/.test(msg)) {
mode = 'profile'
@ -77,7 +134,7 @@ export async function character (e) {
}
if (e.isPrivate) {
if ((e.sub_type === 'friend' && Cfg.get('profile.friend.status') === false) ||
(e.sub_type === 'group' && Cfg.get('profile.stranger.status') === false)) {
(e.sub_type === 'group' && Cfg.get('profile.stranger.status') === false)) {
return
}
} else if (e.isGroup) {

View File

@ -11,14 +11,6 @@ import { Character } from '../../models/index.js'
const resPath = process.cwd() + '/plugins/miao-plugin/resources/'
let regex = /^#?\s*(?:喵喵)?(?:上传|添加)(.+)(?:照片|写真|图片|图像)\s*$/
export const rule = {
uploadCharacterImage: {
hashMark: true,
reg: '^#*喵喵(上传|添加)(.+)写真.*$',
describe: '喵喵上传角色写真'
}
}
export async function uploadCharacterImg (e) {
let promise = await isAllowedToUploadCharacterImage(e)
if (!promise) {
@ -43,10 +35,11 @@ export async function uploadCharacterImg (e) {
}
}
let source
if (e.isGroup) {// 支持at图片添加以及支持后发送
source = (await e.group.getChatHistory(e.source.seq, 1)).pop()
if (e.isGroup) {
// 支持at图片添加以及支持后发送
source = (await e.group.getChatHistory(e.source?.seq, 1)).pop()
} else {
source = (await e.friend.getChatHistory(e.source.time, 1)).pop()
source = (await e.friend.getChatHistory(e.source?.time, 1)).pop()
}
if (source) {
for (let val of source.message) {
@ -55,9 +48,8 @@ export async function uploadCharacterImg (e) {
}
}
}
if (imageMessages.length <= 0) {
e.reply('消息中未找到图片,请将要发送的图片与消息一同发送..')
return true
}

View File

@ -1,16 +1,34 @@
import lodash from 'lodash'
import fs from 'fs'
import { Cfg, Version, Common } from '../components/index.js'
import { Cfg, Version, Common, App } from '../components/index.js'
let app = App.init({
id: 'help',
name: '喵喵帮助',
desc: '喵喵帮助'
})
app.reg('help', help, {
rule: /^#?(喵喵)?(命令|帮助|菜单|help|说明|功能|指令|使用说明)$/,
desc: '【#帮助】 #喵喵帮助'
})
app.reg('version', versionInfo, {
rule: /^#?喵喵版本$/,
desc: '【#帮助】 喵喵版本介绍'
})
export default app
const _path = process.cwd()
const helpPath = `${_path}/plugins/miao-plugin/resources/help`
export async function help (e) {
async function help (e) {
if (!/喵喵/.test(e.msg) && !Cfg.get('sys.help', false)) {
return false
}
let custom = {};
let custom = {}
let help = {}
if (fs.existsSync(`${helpPath}/help-cfg.js`)) {
help = await import(`file://${helpPath}/help-cfg.js?version=${new Date().getTime()}`)
@ -45,7 +63,7 @@ export async function help (e) {
if (!icon) {
help.css = 'display:none'
} else {
let x = (icon - 1) % 10;
let x = (icon - 1) % 10
let y = (icon - x - 1) / 10
help.css = `background-position:-${x * 50}px -${y * 50}px`
}
@ -61,7 +79,7 @@ export async function help (e) {
}, { e, scale: 1.2 })
}
export async function versionInfo (e) {
async function versionInfo (e) {
return await Common.render('help/version-info', {
currentVersion: Version.version,
changelogs: Version.changelogs,

View File

@ -1,125 +1,21 @@
import { wifeReg } from './character.js'
import help from './help.js'
import character from './character.js'
import admin from './admin.js'
import stat from './stat.js'
import wiki from './wiki.js'
import { consStat, abyssPct, abyssTeam, uploadData } from './stat.js'
import { wiki, calendar } from './wiki.js'
import { help, versionInfo } from './help.js'
import lodash from 'lodash'
import { rule as adminRule, updateRes, sysCfg, updateMiaoPlugin, profileCfg } from './admin.js'
export {
character,
getProfile,
wife,
pokeWife,
enemyLv,
profileArtisList,
getProfileAll,
profileHelp,
getOriginalPicture,
uploadCharacterImg,
profileList,
profileStat
} from './character.js'
export {
consStat,
abyssPct,
abyssTeam,
wiki,
updateRes,
updateMiaoPlugin,
sysCfg,
help,
versionInfo,
calendar,
profileCfg,
uploadData
}
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()
let rule = {
character: {
reg: '^(#(.*)|#*(更新|录入)?(.*)(详细|详情|面板|面版|伤害[1-7]?)(更新)?)$',
// reg: "noCheck",
describe: '【#角色】角色详情'
},
uploadCharacterImg: {
reg: '^#*(喵喵)?(上传|添加)(.+)(照片|写真|图片|图像)\\s*$',
describe: '喵喵上传角色写真'
},
profileArtisList: {
reg: '^#圣遗物列表\\s*(\\d{9})?$',
describe: '【#角色】圣遗物列表'
},
profileList: {
reg: '^#(面板角色|角色面板|面板)(列表)?\\s*(\\d{9})?$',
describe: '【#角色】查看当前已获取面板数据的角色列表'
},
profileStat: {
reg: '^#面板练度统计$',
describe: '【#角色】查看当前面板练度统计$'
},
profileHelp: {
reg: '^#角色面板帮助$',
describe: '【#角色】查看当前已获取面板数据的角色列表'
},
wife: {
reg: wifeReg,
describe: '【#角色】#老公 #老婆 查询'
},
pokeWife: {
reg: '#poke#',
describe: '【#角色】戳一戳'
},
getOriginalPicture: {
reg: '^#?(获取|给我|我要|求|发|发下|发个|发一下)?原图(吧|呗)?$',
describe: '【#原图】 回复角色卡片,可获取原图'
},
consStat: {
reg: '^#(喵喵)?角色(持有|持有率|命座|命之座|.命)(分布|统计|持有|持有率)?$',
describe: '【#统计】 #角色持有率 #角色5命统计'
},
abyssPct: {
reg: '^#(喵喵)?深渊(第?.{1,2}层)?(角色)?(出场|使用)(率|统计)*$',
describe: '【#统计】 #深渊出场率 #深渊12层出场率'
},
abyssTeam: {
reg: '#深渊(组队|配队)',
describe: '【#角色】 #深渊组队'
},
wiki: {
reg: '^(#|喵喵)?.*(天赋|技能|命座|命之座|资料|图鉴|照片|写真|图片|图像)$',
describe: '【#资料】 #神里天赋 #夜兰命座'
},
help: {
reg: '^#?(喵喵)?(命令|帮助|菜单|help|说明|功能|指令|使用说明)$',
describe: '【#帮助】 #喵喵帮助'
},
getProfile: {
reg: '^#(全部面板更新|更新全部面板|获取游戏角色详情|更新面板|面板更新)\\s*(\\d{9})?$',
describe: '【#角色】 获取游戏橱窗详情数据'
},
enemyLv: {
reg: '^#(敌人|怪物)等级\\s*\\d{1,3}\\s*$',
describe: '【#角色】 设置伤害计算中目标敌人的等级'
},
versionInfo: {
reg: '^#?喵喵版本$',
describe: '【#帮助】 喵喵版本介绍'
},
calendar: {
reg: '^(#|喵喵)+(日历|日历列表)$',
describe: '【#日历】 活动日历'
},
uploadData: {
reg: '^#*(喵喵|上传|本期)*(深渊|深境|深境螺旋)[ |0-9]*(数据)?$'
},
...adminRule
characterApp: character.rule(),
adminApp: character.rule(),
helpApp: help.rule(),
statApp: stat.rule(),
wikiApp: wiki.rule()
}
lodash.forEach(rule, (r) => {
r.priority = r.priority || 50
r.prehash = true
r.hashMark = true
})
export { rule }

View File

@ -4,11 +4,35 @@
* */
import lodash from 'lodash'
import fs from 'fs'
import { Cfg, Common } from '../components/index.js'
import { Cfg, Common, App } from '../components/index.js'
import { Abyss, Avatars, Character } from '../models/index.js'
import HutaoApi from './stat/HutaoApi.js'
export async function consStat (e) {
let app = App.init({
id: 'stat',
name: '喵喵帮助',
desc: '喵喵帮助'
})
app.reg('cons-stat', consStat, {
rule: /^#(喵喵)?角色(持有|持有率|命座|命之座|.命)(分布|统计|持有|持有率)?$/,
desc: '【#统计】 #角色持有率 #角色5命统计'
})
app.reg('abyss-pct', abyssPct, {
rule: /^#(喵喵)?深渊(第?.{1,2}层)?(角色)?(出场|使用)(率|统计)*$/,
desc: '【#统计】 #深渊出场率 #深渊12层出场率'
})
app.reg('abyss-team', abyssTeam, {
rule: /#深渊(组队|配队)/,
describe: '【#角色】 #深渊组队'
})
app.reg('upload-data', uploadData, {
rule: /^#*(喵喵|上传|本期)*(深渊|深境|深境螺旋)[ |0-9]*(数据)?$/,
desc: '上传深渊'
})
export default app
async function consStat (e) {
if (Cfg.isDisable(e, 'wiki.stat')) {
return
}
@ -91,7 +115,7 @@ export async function consStat (e) {
}, { e, scale: 1.5 })
}
export async function abyssPct (e) {
async function abyssPct (e) {
if (Cfg.isDisable(e, 'wiki.stat')) {
return
}
@ -204,7 +228,7 @@ async function getTalentData (e, isUpdate = false) {
return false
}
export async function abyssTeam (e) {
async function abyssTeam (e) {
if (Common.todoV3(e)) {
return true
}
@ -401,7 +425,7 @@ export async function abyssTeam (e) {
}, { e, scale: 1.5 })
}
export async function uploadData (e) {
async function uploadData (e) {
let isMatch = /^#(喵喵|上传)深渊(数据)?$/.test(e.original_msg || e.msg || '')
if (!Cfg.get('wiki.abyss', false) && !isMatch) {
return false
@ -420,10 +444,9 @@ export async function uploadData (e) {
}
let ret = {}
let uid = e.selfUser.uid
let resDetail, resAbyss, overview
let resDetail, resAbyss
try {
resAbyss = await MysApi.getSpiralAbyss(1)
// overview = await HutaoApi.getOverview()
if (resAbyss.floors.length > 0 && !await Avatars.hasTalentCache(uid)) {
e.reply('正在获取用户信息,请稍候...')
}

View File

@ -1,7 +1,7 @@
import { segment } from 'oicq'
import lodash from 'lodash'
import Calendar from './wiki/calendar.js'
import { Format, Cfg, Common } from '../components/index.js'
import { Format, Cfg, Common, App } from '../components/index.js'
import { Character } from '../models/index.js'
import CharWiki from './wiki/CharWiki.js'
@ -12,7 +12,23 @@ let action = {
}
}
export async function wiki (e) {
let app = App.init({
id: 'wiki',
name: '喵喵帮助',
desc: '喵喵帮助'
})
app.reg('wiki', wiki, {
rule: /^(#|喵喵)?.*(天赋|技能|命座|命之座|资料|图鉴|照片|写真|图片|图像)$/,
desc: '【#资料】 #神里天赋 #夜兰命座'
})
app.reg('calendar', calendar, {
rule: /^(#|喵喵)+(日历|日历列表)$/,
desc: '【#日历】 活动日历'
})
export default app
async function wiki (e) {
if (!e.msg) {
return false
}
@ -129,7 +145,7 @@ const getLineData = function (char) {
return ret
}
export async function calendar (e) {
async function calendar (e) {
let calData = await Calendar.get()
let mode = 'calendar'
if (/(日历列表|活动)$/.test(e.msg)) {

84
components/App.js Normal file
View File

@ -0,0 +1,84 @@
import { plugin } from '../adapter/index.js'
class App {
constructor (cfg) {
this.id = cfg.id
this.cfg = cfg
this.apps = {}
}
reg (key, fn, cfg = {}) {
//TODO: 参数校验
this.apps[key] = {
fn,
...cfg
}
}
getPlugins () {
let cfg = this.cfg || {}
let rule = this.getV3Rule()
let cls = class extends plugin {
constructor () {
super({
name: `喵喵:${cfg.name || cfg.id}`,
desc: cfg.desc || '喵喵插件',
event: 'message',
priority: 50,
rule
})
}
async app (e) {
}
}
cls.test = 1
return cls
}
// 获取v2版rule
rule () {
let cfg = this.cfg
return {
reg: 'noCheck',
describe: cfg.desc || '',
priority: 50,
hashMark: true
}
}
// v2执行方法
v2 (e) {
let apps = this.apps
return async function (e) {
let msg = e.original_msg || e.msg || ''
for (let key in apps) {
let app = apps[key]
let rule = app.rule || app.reg || 'noCheck'
if (app.rule) {
if (typeof (rule) === 'string') {
if (rule === '#poke#') {
continue
} else if (rule === 'noCheck') {
rule = /.*/
}
rule = new RegExp(rule)
}
if (rule.test(msg)) {
let ret = await app.fn(e, {})
if (ret === true) {
return true
}
}
}
}
return false
}
}
}
App.init = function (cfg) {
return new App(cfg)
}
export default App

View File

@ -32,7 +32,7 @@ try {
if (versionCount <= -1) {
return false
}
let versionRet = /^#\s*([0-9\\.~\s]+?)\s*$/.exec(line)
let versionRet = /^#\s*([0-9a-zA-Z\\.~\s]+?)\s*$/.exec(line)
if (versionRet && versionRet[1]) {
let v = versionRet[1].trim()
if (!currentVersion) {

View File

@ -4,5 +4,6 @@ import Common from './Common.js'
import Cfg from './Cfg.js'
import Version from './Version.js'
import Profile from './Profile.js'
import App from './App.js'
export { Data, Cfg, Format, Common, Version, Profile }
export { Data, Cfg, Format, Common, Version, Profile, App }