2
0
mirror of https://github.com/ctrlcvs/xiaoyao-cvs-plugin.git synced 2024-12-23 03:20:52 +08:00
xiaoyao-cvs-plugin/adapter/index.js

59 lines
1.4 KiB
JavaScript
Raw Normal View History

2022-07-24 11:46:05 +08:00
import plugin from '../../../lib/plugins/plugin.js'
import * as Atlas from '../apps/index.js'
import { render } from './render.js'
import { checkAuth, getMysApi } from './mys.js'
export class atlas extends plugin {
2022-09-18 22:09:25 +08:00
constructor (e) {
2022-08-03 21:25:29 +08:00
let rule = {
reg: '.+',
fnc: 'dispatch'
}
2022-09-18 22:09:25 +08:00
let event=e?.event || e?.sub_type
2022-07-24 11:46:05 +08:00
super({
name: 'xiaoyao-cvs-plugin',
desc: '图鉴插件',
2022-09-18 22:09:25 +08:00
event: event === 'poke' ? 'notice.*.poke' : 'message',
2022-07-24 11:46:05 +08:00
priority: 50,
2022-09-18 22:09:25 +08:00
rule: [rule],
2022-07-24 11:46:05 +08:00
})
2022-08-03 21:25:29 +08:00
Object.defineProperty(rule, 'log', {
get: () => !!this.isDispatch
// get: () =>true
2022-08-03 21:25:29 +08:00
})
2022-07-24 11:46:05 +08:00
}
2022-08-02 20:20:34 +08:00
accept () {
if(this.event==='notice.*.poke'&&this.e.target_id === Bot.uin){
this.e.user_id=this.e.operator_id;
2022-09-18 22:09:25 +08:00
this.e.msg = '#poke#'
}
2022-08-02 20:20:34 +08:00
this.e.original_msg = this.e.original_msg || this.e.msg
}
2022-07-24 11:46:05 +08:00
async dispatch (e) {
2022-08-02 20:20:34 +08:00
let msg = e.original_msg || ''
if (!msg) {
return false
}
2022-07-24 11:46:05 +08:00
e.checkAuth = async function (cfg) {
return await checkAuth(e, cfg)
}
e.getMysApi = async function (cfg) {
return await getMysApi(e, cfg)
}
2022-10-19 07:05:20 +08:00
msg = msg.replace(/#|/, '#').trim()
2022-07-24 11:46:05 +08:00
for (let fn in Atlas.rule) {
let cfg = Atlas.rule[fn]
if (Atlas[fn] && new RegExp(cfg.reg).test(msg)) {
let ret = await Atlas[fn](e, {
render
})
if (ret === true) {
return true
}
}
}
return false
}
}