update: 补充类型声明
This commit is contained in:
parent
3aac394e4b
commit
610a84c6ea
|
@ -152,18 +152,11 @@ class PluginsLoader {
|
||||||
*/
|
*/
|
||||||
#importPlugin = async (file, packageErr?: any) => {
|
#importPlugin = async (file, packageErr?: any) => {
|
||||||
try {
|
try {
|
||||||
// 应该去去印插件的路径。
|
|
||||||
// 才能确定是谁的插件
|
|
||||||
|
|
||||||
const app = await import(`file://${join(process.cwd(), file.path)}`)
|
const app = await import(`file://${join(process.cwd(), file.path)}`)
|
||||||
|
|
||||||
const pluginArray = []
|
const pluginArray = []
|
||||||
|
|
||||||
for (const key in app.apps) {
|
for (const key in app.apps) {
|
||||||
// console.log('key', key)
|
|
||||||
pluginArray.push(this.loadPlugin(file, app.apps[key], key))
|
pluginArray.push(this.loadPlugin(file, app.apps[key], key))
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const i of await Promise.allSettled(pluginArray))
|
for (const i of await Promise.allSettled(pluginArray))
|
||||||
if (i?.status && i.status != 'fulfilled') {
|
if (i?.status && i.status != 'fulfilled') {
|
||||||
logger.error(`加载插件错误:${logger.red(file.name)}`)
|
logger.error(`加载插件错误:${logger.red(file.name)}`)
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
import * as common from '../../utils/common.js'
|
import lodash from 'lodash'
|
||||||
import cfg from '../../config/config.js'
|
import fs from 'node:fs'
|
||||||
import Handler from './handler.js'
|
|
||||||
|
|
||||||
import {
|
import {
|
||||||
gsCfg,
|
gsCfg,
|
||||||
mysApi as MysApi,
|
mysApi as MysApi,
|
||||||
|
@ -9,21 +7,14 @@ import {
|
||||||
NoteUser,
|
NoteUser,
|
||||||
MysUser
|
MysUser
|
||||||
} from '../../mys/index.js'
|
} from '../../mys/index.js'
|
||||||
|
|
||||||
import puppeteer from '../../utils/puppeteer/puppeteer.js'
|
import puppeteer from '../../utils/puppeteer/puppeteer.js'
|
||||||
|
import * as common from '../../utils/common.js'
|
||||||
|
import cfg from '../../config/config.js'
|
||||||
import lodash from 'lodash'
|
import Handler from './handler.js'
|
||||||
import fs from 'node:fs'
|
|
||||||
import { Version } from '../../miao.js'
|
import { Version } from '../../miao.js'
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ********************
|
* @deprecated 已废弃
|
||||||
* 对e进行重构的危险代码
|
|
||||||
* ********************
|
|
||||||
* tudo
|
|
||||||
* 写法混乱,需要重构
|
|
||||||
*/
|
*/
|
||||||
export default class Runtime {
|
export default class Runtime {
|
||||||
e = null
|
e = null
|
||||||
|
@ -121,7 +112,7 @@ export default class Runtime {
|
||||||
*/
|
*/
|
||||||
static async init(e) {
|
static async init(e) {
|
||||||
await MysInfo.initCache()
|
await MysInfo.initCache()
|
||||||
let runtime = new Runtime(e)
|
const runtime = new Runtime(e)
|
||||||
e.runtime = runtime
|
e.runtime = runtime
|
||||||
await runtime.initUser()
|
await runtime.initUser()
|
||||||
return runtime
|
return runtime
|
||||||
|
@ -239,7 +230,7 @@ export default class Runtime {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @deprecated 不符合架构设计,已废弃
|
* @deprecated 不符合架构设计,已废弃
|
||||||
* @param plugin plugin key
|
* @param plugin_name plugin key
|
||||||
* @param path html文件路径,相对于plugin resources目录
|
* @param path html文件路径,相对于plugin resources目录
|
||||||
* @param data 渲染数据
|
* @param data 渲染数据
|
||||||
* @param cfg 渲染配置
|
* @param cfg 渲染配置
|
||||||
|
@ -250,77 +241,91 @@ export default class Runtime {
|
||||||
* @param cfg.beforeRender({data}) 可改写渲染的data数据
|
* @param cfg.beforeRender({data}) 可改写渲染的data数据
|
||||||
* @returns {Promise<boolean>}
|
* @returns {Promise<boolean>}
|
||||||
*/
|
*/
|
||||||
async render (plugin, path, data = {}, cfg = {}) {
|
async render(
|
||||||
// 处理传入的path
|
plugin_name: string,
|
||||||
path = path.replace(/.html$/, '')
|
path: string,
|
||||||
let paths = lodash.filter(path.split('/'), (p) => !!p)
|
data: {
|
||||||
path = paths.join('/')
|
[key: string]: any
|
||||||
// 创建目录
|
saveId?: any,
|
||||||
const mkdir = (check) => {
|
save_id?: any,
|
||||||
let currDir = `${process.cwd()}/temp`
|
_htmlPath?: any,
|
||||||
for (let p of check.split('/')) {
|
} = {}, cfg: {
|
||||||
currDir = `${currDir}/${p}`
|
[key: string]: any
|
||||||
if (!fs.existsSync(currDir)) {
|
retType?: any,
|
||||||
fs.mkdirSync(currDir)
|
recallMsg?: any
|
||||||
}
|
beforeRender?: any
|
||||||
}
|
} = {}
|
||||||
return currDir
|
) {
|
||||||
}
|
// 处理传入的path
|
||||||
mkdir(`html/${plugin}/${path}`)
|
path = path.replace(/.html$/, '')
|
||||||
// 自动计算pluResPath
|
let paths = lodash.filter(path.split('/'), (p) => !!p)
|
||||||
let pluResPath = `../../../${lodash.repeat('../', paths.length)}plugins/${plugin}/resources/`
|
path = paths.join('/')
|
||||||
let miaoResPath = `../../../${lodash.repeat('../', paths.length)}plugins/miao-plugin/resources/`
|
// 创建目录
|
||||||
const layoutPath = process.cwd() + '/plugins/miao-plugin/resources/common/layout/'
|
const mkdir = (check) => {
|
||||||
// 渲染data
|
let currDir = `${process.cwd()}/temp`
|
||||||
data = {
|
for (let p of check.split('/')) {
|
||||||
sys: {
|
currDir = `${currDir}/${p}`
|
||||||
scale: 1
|
if (!fs.existsSync(currDir)) {
|
||||||
},
|
fs.mkdirSync(currDir)
|
||||||
/** miao 相关参数 **/
|
}
|
||||||
copyright: `Created By Miao-Yunzai<span class="version">${Version.yunzai}</span> `,
|
}
|
||||||
_res_path: pluResPath,
|
return currDir
|
||||||
_miao_path: miaoResPath,
|
}
|
||||||
_tpl_path: process.cwd() + '/plugins/miao-plugin/resources/common/tpl/',
|
mkdir(`html/${plugin_name}/${path}`)
|
||||||
defaultLayout: layoutPath + 'default.html',
|
// 自动计算pluResPath
|
||||||
elemLayout: layoutPath + 'elem.html',
|
let pluResPath = `../../../${lodash.repeat('../', paths.length)}plugins/${plugin_name}/resources/`
|
||||||
|
let miaoResPath = `../../../${lodash.repeat('../', paths.length)}plugins/miao-plugin/resources/`
|
||||||
|
const layoutPath = process.cwd() + '/plugins/miao-plugin/resources/common/layout/'
|
||||||
|
// 渲染data
|
||||||
|
data = {
|
||||||
|
sys: {
|
||||||
|
scale: 1
|
||||||
|
},
|
||||||
|
/** miao 相关参数 **/
|
||||||
|
copyright: `Created By Miao-Yunzai<span class="version">${Version.yunzai}</span> `,
|
||||||
|
_res_path: pluResPath,
|
||||||
|
_miao_path: miaoResPath,
|
||||||
|
_tpl_path: process.cwd() + '/plugins/miao-plugin/resources/common/tpl/',
|
||||||
|
defaultLayout: layoutPath + 'default.html',
|
||||||
|
elemLayout: layoutPath + 'elem.html',
|
||||||
|
|
||||||
...data,
|
...data,
|
||||||
|
|
||||||
/** 默认参数 **/
|
/** 默认参数 **/
|
||||||
_plugin: plugin,
|
_plugin: plugin_name,
|
||||||
_htmlPath: path,
|
_htmlPath: path,
|
||||||
pluResPath,
|
pluResPath,
|
||||||
tplFile: `./plugins/${plugin}/resources/${path}.html`,
|
tplFile: `./plugins/${plugin_name}/resources/${path}.html`,
|
||||||
saveId: data.saveId || data.save_id || paths[paths.length - 1],
|
saveId: data.saveId || data.save_id || paths[paths.length - 1],
|
||||||
pageGotoParams: {
|
pageGotoParams: {
|
||||||
waitUntil: 'networkidle2'
|
waitUntil: 'networkidle2'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 处理beforeRender
|
// 处理beforeRender
|
||||||
if (cfg.beforeRender) {
|
if (cfg.beforeRender) {
|
||||||
data = cfg.beforeRender({ data }) || data
|
data = cfg.beforeRender({ data }) || data
|
||||||
}
|
}
|
||||||
// 保存模板数据
|
// 保存模板数据
|
||||||
if (process.argv.includes('dev')) {
|
if (process.argv.includes('dev')) {
|
||||||
// debug下保存当前页面的渲染数据,方便模板编写与调试
|
// debug下保存当前页面的渲染数据,方便模板编写与调试
|
||||||
// 由于只用于调试,开发者只关注自己当时开发的文件即可,暂不考虑app及plugin的命名冲突
|
// 由于只用于调试,开发者只关注自己当时开发的文件即可,暂不考虑app及plugin的命名冲突
|
||||||
let saveDir = mkdir(`ViewData/${plugin}`)
|
let saveDir = mkdir(`ViewData/${plugin_name}`)
|
||||||
let file = `${saveDir}/${data._htmlPath.split('/').join('_')}.json`
|
let file = `${saveDir}/${data._htmlPath.split('/').join('_')}.json`
|
||||||
fs.writeFileSync(file, JSON.stringify(data))
|
fs.writeFileSync(file, JSON.stringify(data))
|
||||||
}
|
}
|
||||||
// 截图
|
// 截图
|
||||||
let base64 = await puppeteer.screenshot(`${plugin}/${path}`, data)
|
let base64 = await puppeteer.screenshot(`${plugin_name}/${path}`, data)
|
||||||
if (cfg.retType === 'base64') {
|
if (cfg.retType === 'base64') {
|
||||||
return base64
|
return base64
|
||||||
}
|
}
|
||||||
let ret = true
|
let ret = true
|
||||||
if (base64) {
|
if (base64) {
|
||||||
if (cfg.recallMsg) {
|
if (cfg.recallMsg) {
|
||||||
ret = await this.e.reply(base64, false, {})
|
ret = await this.e.reply(base64, false, {})
|
||||||
} else {
|
} else {
|
||||||
ret = await this.e.reply(base64)
|
ret = await this.e.reply(base64)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return cfg.retType === 'msgId' ? ret : true
|
return cfg.retType === 'msgId' ? ret : true
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,28 +1,38 @@
|
||||||
import { type GroupMessage } from 'icqq'
|
import { type GroupMessage } from 'icqq'
|
||||||
// import { Client } from 'icqq'
|
import Runtime from './runtime'
|
||||||
// import { PrivateMessage } from 'oicq'
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 消息事件体
|
||||||
|
*/
|
||||||
export interface EventType extends GroupMessage {
|
export interface EventType extends GroupMessage {
|
||||||
/**
|
/**
|
||||||
* 是否是主人
|
* 是否是机器人主人
|
||||||
*/
|
*/
|
||||||
isMaster: boolean
|
isMaster: boolean
|
||||||
/**
|
/**
|
||||||
* 是否是管理员
|
* 是否是机器人管理员
|
||||||
*/
|
*/
|
||||||
// isAdmin: boolean;
|
// isAdmin: boolean;
|
||||||
/**
|
/**
|
||||||
* 是否是群里
|
* 是否是群里
|
||||||
*/
|
*/
|
||||||
isGroup: boolean
|
isGroup: boolean
|
||||||
|
/**
|
||||||
|
* 是否是群管理
|
||||||
|
*/
|
||||||
|
// isGroupAdmin:boolean
|
||||||
/**
|
/**
|
||||||
* 是私聊
|
* 是私聊
|
||||||
*/
|
*/
|
||||||
isPrivate?: any
|
isPrivate: boolean
|
||||||
/**
|
/**
|
||||||
* 是频道
|
* 是频道
|
||||||
*/
|
*/
|
||||||
isGuild?: any
|
isGuild: boolean
|
||||||
|
/**
|
||||||
|
* 用户名
|
||||||
|
*/
|
||||||
|
user_id: number
|
||||||
/**
|
/**
|
||||||
* 用户名
|
* 用户名
|
||||||
*/
|
*/
|
||||||
|
@ -30,7 +40,7 @@ export interface EventType extends GroupMessage {
|
||||||
/**
|
/**
|
||||||
* 用户头像
|
* 用户头像
|
||||||
*/
|
*/
|
||||||
user_avatar: string | null
|
user_avatar: string
|
||||||
/**
|
/**
|
||||||
* 用户消息
|
* 用户消息
|
||||||
*/
|
*/
|
||||||
|
@ -52,9 +62,15 @@ export interface EventType extends GroupMessage {
|
||||||
/**
|
/**
|
||||||
* 群头像
|
* 群头像
|
||||||
*/
|
*/
|
||||||
group_avatar: string | null
|
group_avatar: string
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* @deprecated 已废弃
|
||||||
|
*/
|
||||||
|
runtime: typeof Runtime.prototype
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated 已废弃
|
||||||
*/
|
*/
|
||||||
group: {
|
group: {
|
||||||
is_owner: any;
|
is_owner: any;
|
||||||
|
@ -62,28 +78,30 @@ export interface EventType extends GroupMessage {
|
||||||
getMemberMap: any;
|
getMemberMap: any;
|
||||||
quit: any;
|
quit: any;
|
||||||
mute_left: any
|
mute_left: any
|
||||||
|
|
||||||
pickMember: any
|
pickMember: any
|
||||||
|
|
||||||
|
|
||||||
sendMsg: any
|
sendMsg: any
|
||||||
};
|
};
|
||||||
/**
|
/**
|
||||||
|
* @deprecated 已废弃
|
||||||
*/
|
*/
|
||||||
file: any;
|
file: any;
|
||||||
/**
|
/**
|
||||||
|
* @deprecated 已废弃
|
||||||
*/
|
*/
|
||||||
bot: any;
|
bot: any;
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
* @deprecated 已废弃
|
||||||
*/
|
*/
|
||||||
approve: any;
|
approve: any;
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
* @deprecated 已废弃
|
||||||
*/
|
*/
|
||||||
member: any;
|
member: any;
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
* @deprecated 已废弃
|
||||||
*/
|
*/
|
||||||
logText: any;
|
logText: any;
|
||||||
/**
|
/**
|
||||||
|
@ -96,34 +114,41 @@ export interface EventType extends GroupMessage {
|
||||||
isGs?: boolean
|
isGs?: boolean
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
* @deprecated 已废弃
|
||||||
*/
|
*/
|
||||||
self_id?: any
|
self_id?: any
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
* @deprecated 已废弃
|
||||||
*/
|
*/
|
||||||
game?: any
|
game?: any
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
* @deprecated 已废弃
|
||||||
*/
|
*/
|
||||||
detail_type?: any
|
detail_type?: any
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
* @deprecated 已废弃
|
||||||
*/
|
*/
|
||||||
at?: any
|
at?: any
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
* @deprecated 已废弃
|
||||||
*/
|
*/
|
||||||
atBot: any;
|
atBot: any;
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
* @deprecated 已废弃
|
||||||
*/
|
*/
|
||||||
hasAlias?: any
|
hasAlias?: any
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
* @deprecated 已废弃
|
||||||
*/
|
*/
|
||||||
replyNew?: any
|
replyNew?: any
|
||||||
/**
|
/**
|
||||||
*
|
* @deprecated 已废弃
|
||||||
*/
|
*/
|
||||||
friend?: any
|
friend?: any
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue