2024-06-08 20:52:49 +08:00
|
|
|
import { MessageCallBackType } from './types.js'
|
2024-06-08 21:01:41 +08:00
|
|
|
import { plugin } from './plugin.js'
|
2024-06-08 20:52:49 +08:00
|
|
|
|
|
|
|
// 插件super默认值
|
|
|
|
export const PluginSuperDefine = {
|
|
|
|
name: 'group-app',
|
|
|
|
dsc: 'group-dsc',
|
|
|
|
event: 'message',
|
|
|
|
priority: 9999
|
|
|
|
}
|
|
|
|
|
|
|
|
// 消息
|
|
|
|
export class Messages {
|
|
|
|
count = 0
|
|
|
|
rule: {
|
|
|
|
reg: RegExp
|
|
|
|
fnc: string
|
|
|
|
}[] = []
|
|
|
|
response(reg: RegExp, fnc: MessageCallBackType) {
|
|
|
|
this.count++
|
|
|
|
const propName = `prop_${this.count}`
|
|
|
|
this[propName] = fnc
|
|
|
|
this.rule.push({
|
|
|
|
reg,
|
|
|
|
fnc: propName
|
|
|
|
})
|
|
|
|
}
|
|
|
|
get ok() {
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
|
|
const App = this
|
|
|
|
class Children extends plugin {
|
|
|
|
constructor() {
|
|
|
|
super({
|
|
|
|
...PluginSuperDefine,
|
|
|
|
rule: App.rule
|
|
|
|
})
|
|
|
|
for (const key of App.rule) {
|
|
|
|
if (App[key.fnc] instanceof Function) {
|
|
|
|
this[key.fnc] = App[key.fnc].bind(App)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Children
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 事件
|
|
|
|
*/
|
|
|
|
export class Events {
|
|
|
|
count = 0
|
|
|
|
data: {
|
|
|
|
[key: string]: typeof plugin
|
|
|
|
} = {}
|
|
|
|
use(val: typeof plugin) {
|
|
|
|
this.count++
|
|
|
|
this.data[this.count] = val
|
|
|
|
}
|
|
|
|
get ok() {
|
|
|
|
return this.data
|
|
|
|
}
|
2024-06-08 21:01:41 +08:00
|
|
|
}
|