alemonjs 1.0.48 → 1.0.50
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/api.js +8 -12
- package/lib/core/apps.js +52 -2
- package/lib/core/cache.js +122 -0
- package/lib/core/dealmsg.js +25 -21
- package/lib/core/index.js +1 -1
- package/lib/core/plugin.js +181 -12
- package/lib/define/main.js +2 -2
- package/lib/kook/alemon/message/PUBLIC_GUILD_MESSAGES.js +14 -14
- package/lib/kook/index.js +2 -2
- package/lib/kook/sdk/index.js +1 -1
- package/lib/ntqq/alemon/message/C2C_MESSAGE_CREATE.js +5 -5
- package/lib/ntqq/alemon/message/GROUP_AT_MESSAGE_CREATE.js +5 -5
- package/lib/ntqq/index.js +3 -3
- package/lib/ntqq/sdk/index.js +1 -1
- package/lib/ntqq/sdk/intents.js +6 -3
- package/lib/qq/alemon/apidoc.js +6 -6
- package/lib/qq/alemon/message/DIRECT_MESSAGE.js +3 -3
- package/lib/qq/alemon/message/GUILD_MEMBERS.js +4 -4
- package/lib/qq/alemon/message/MESSAGE.js +5 -5
- package/lib/qq/alemon/permissions.js +1 -1
- package/lib/qq/alemon/privatechat.js +3 -3
- package/lib/qq/index.js +2 -2
- package/lib/qq/sdk/index.js +1 -1
- package/lib/qq/sdk/wss.js +2 -2
- package/lib/villa/alemon/message/MESSAGES.js +11 -11
- package/lib/villa/sdk/index.js +1 -1
- package/package.json +2 -2
- package/types/api.d.ts +9 -13
- package/types/core/apps.d.ts +38 -0
- package/types/core/cache.d.ts +85 -0
- package/types/core/index.d.ts +1 -1
- package/types/core/plugin.d.ts +89 -4
- package/types/define/main.d.ts +2 -2
- package/types/kook/sdk/index.d.ts +1 -1
- package/types/ntqq/sdk/index.d.ts +1 -1
- package/types/qq/alemon/apidoc.d.ts +1 -1
- package/types/qq/alemon/message/DIRECT_MESSAGE.d.ts +1 -1
- package/types/qq/alemon/message/GUILD_MEMBERS.d.ts +1 -1
- package/types/qq/alemon/message/MESSAGE.d.ts +1 -1
- package/types/qq/alemon/permissions.d.ts +1 -1
- package/types/qq/alemon/privatechat.d.ts +1 -1
- package/types/qq/index.d.ts +1 -1
- package/types/qq/sdk/index.d.ts +1 -1
- package/types/qq/sdk/wss.d.ts +1 -1
- package/types/villa/sdk/index.d.ts +1 -1
- package/lib/core/message.js +0 -50
- package/types/core/message.d.ts +0 -34
- package/types/qq/alemon/console.d.ts +0 -1
package/lib/api.js
CHANGED
|
@@ -1,24 +1,20 @@
|
|
|
1
|
-
import { ClientAPIByQQ as ClientByNTQQ } from './ntqq/sdk/index.js';
|
|
2
|
-
import { Client as ClientByVILLA } from './villa/sdk/index.js';
|
|
3
|
-
import { KOOKApiClient as ClientByKOOK } from './kook/sdk/index.js';
|
|
4
|
-
import { ClientKOA as ClientByKOA } from './koa/index.js';
|
|
5
1
|
/**
|
|
6
2
|
* qq客户端
|
|
7
3
|
*/
|
|
8
|
-
export const ClientQQ = global.
|
|
4
|
+
export const ClientQQ = global.ClientQQ;
|
|
9
5
|
/**
|
|
10
|
-
*
|
|
6
|
+
* villa客户端
|
|
11
7
|
*/
|
|
12
|
-
export
|
|
8
|
+
export { ClientVILLA } from './villa/sdk/index.js';
|
|
13
9
|
/**
|
|
14
10
|
* ntqq客户端
|
|
15
11
|
*/
|
|
16
|
-
export
|
|
12
|
+
export { ClientNTQQ } from './ntqq/sdk/index.js';
|
|
17
13
|
/**
|
|
18
|
-
*
|
|
14
|
+
* server客户端
|
|
19
15
|
*/
|
|
20
|
-
export
|
|
16
|
+
export { ClientKOA } from './koa/index.js';
|
|
21
17
|
/**
|
|
22
|
-
*
|
|
18
|
+
* kook客户端
|
|
23
19
|
*/
|
|
24
|
-
export
|
|
20
|
+
export { ClientKOOK } from './kook/sdk/index.js';
|
package/lib/core/apps.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { dirname, basename } from 'path';
|
|
2
2
|
import { fileURLToPath } from 'url';
|
|
3
|
-
import {
|
|
3
|
+
import { setAppMessage, setAppArg, setAppCharacter, setAppEvent, setAppPriority } from './cache.js';
|
|
4
4
|
import { setApp } from './app.js';
|
|
5
5
|
/**
|
|
6
6
|
* 得到执行路径
|
|
@@ -40,7 +40,57 @@ export function createApp(AppName) {
|
|
|
40
40
|
* 重名控制器
|
|
41
41
|
*/
|
|
42
42
|
let acount = 0;
|
|
43
|
+
/**
|
|
44
|
+
* 设置默认指令规则
|
|
45
|
+
*/
|
|
46
|
+
setAppCharacter(AppName, '/');
|
|
43
47
|
return {
|
|
48
|
+
/**
|
|
49
|
+
* 设置正则最低优先级
|
|
50
|
+
* 当设置了500,而所有优先级为5000时
|
|
51
|
+
* 则全部默认为500,但有优先级为300的子应用
|
|
52
|
+
* 则仅限当前子应用优先级为300
|
|
53
|
+
* @param val
|
|
54
|
+
* @returns
|
|
55
|
+
*/
|
|
56
|
+
setPriority: (val) => {
|
|
57
|
+
try {
|
|
58
|
+
setAppPriority(AppName, val);
|
|
59
|
+
return true;
|
|
60
|
+
}
|
|
61
|
+
catch (err) {
|
|
62
|
+
console.error('APP setEvent', err);
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
/**
|
|
67
|
+
* 设置正则默认消息
|
|
68
|
+
* @param val
|
|
69
|
+
* @returns
|
|
70
|
+
*/
|
|
71
|
+
setEvent: (val) => {
|
|
72
|
+
try {
|
|
73
|
+
setAppEvent(AppName, val);
|
|
74
|
+
return true;
|
|
75
|
+
}
|
|
76
|
+
catch (err) {
|
|
77
|
+
console.error('APP setEvent', err);
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
/**
|
|
82
|
+
* 设置指令规则
|
|
83
|
+
*/
|
|
84
|
+
setCharacter: (val) => {
|
|
85
|
+
try {
|
|
86
|
+
setAppCharacter(AppName, val);
|
|
87
|
+
return true;
|
|
88
|
+
}
|
|
89
|
+
catch (err) {
|
|
90
|
+
console.error('APP setCharacter', err);
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
93
|
+
},
|
|
44
94
|
/**
|
|
45
95
|
* 设置扩展参
|
|
46
96
|
*/
|
|
@@ -61,7 +111,7 @@ export function createApp(AppName) {
|
|
|
61
111
|
*/
|
|
62
112
|
setMessage: (fnc) => {
|
|
63
113
|
try {
|
|
64
|
-
|
|
114
|
+
setAppMessage(AppName, fnc);
|
|
65
115
|
return true;
|
|
66
116
|
}
|
|
67
117
|
catch (err) {
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
// 消息控制
|
|
2
|
+
const MSG = {};
|
|
3
|
+
/**
|
|
4
|
+
* 得到消息
|
|
5
|
+
* @param key 插件名
|
|
6
|
+
* @returns 重定义回调函数
|
|
7
|
+
*/
|
|
8
|
+
export function getAppMessage(key) {
|
|
9
|
+
return MSG[key];
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* 设置消息
|
|
13
|
+
* @param key 插件名
|
|
14
|
+
* @param fnc 方法
|
|
15
|
+
*/
|
|
16
|
+
export function setAppMessage(key, fnc) {
|
|
17
|
+
MSG[key] = fnc;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* 删除消息
|
|
21
|
+
* @param key 插件名
|
|
22
|
+
*/
|
|
23
|
+
export function delAppMessage(key) {
|
|
24
|
+
delete MSG[key];
|
|
25
|
+
}
|
|
26
|
+
// 扩展控制
|
|
27
|
+
const ARG = {};
|
|
28
|
+
/**
|
|
29
|
+
* 得到扩展参数
|
|
30
|
+
* @param key 插件名
|
|
31
|
+
* @returns
|
|
32
|
+
*/
|
|
33
|
+
export function getAppArg(key) {
|
|
34
|
+
return ARG[key];
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* 设置扩展参数
|
|
38
|
+
* @param key 插件名
|
|
39
|
+
* @param fnc 方法
|
|
40
|
+
*/
|
|
41
|
+
export function setAppArg(key, fnc) {
|
|
42
|
+
ARG[key] = fnc;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* 删除消息
|
|
46
|
+
* @param key 插件名
|
|
47
|
+
*/
|
|
48
|
+
export function delAppArg(key) {
|
|
49
|
+
delete ARG[key];
|
|
50
|
+
}
|
|
51
|
+
const CAT = {};
|
|
52
|
+
/**
|
|
53
|
+
* 得到指令规则
|
|
54
|
+
* @param key 插件名
|
|
55
|
+
* @returns
|
|
56
|
+
*/
|
|
57
|
+
export function getAppCharacter(key) {
|
|
58
|
+
return CAT[key];
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* 设置令规则
|
|
62
|
+
* @param key 插件名
|
|
63
|
+
* @param val 字符
|
|
64
|
+
*/
|
|
65
|
+
export function setAppCharacter(key, val) {
|
|
66
|
+
CAT[key] = val;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* 删除令规则
|
|
70
|
+
* @param key 插件名
|
|
71
|
+
*/
|
|
72
|
+
export function delAppCharacter(key) {
|
|
73
|
+
delete CAT[key];
|
|
74
|
+
}
|
|
75
|
+
const EVENT = {};
|
|
76
|
+
/**
|
|
77
|
+
* 得到正则默认事件
|
|
78
|
+
* @param key 插件名
|
|
79
|
+
* @returns
|
|
80
|
+
*/
|
|
81
|
+
export function getAppEvent(key) {
|
|
82
|
+
return EVENT[key];
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* 设置正则默认事件
|
|
86
|
+
* @param key 插件名
|
|
87
|
+
* @param val 事件名
|
|
88
|
+
*/
|
|
89
|
+
export function setAppEvent(key, val) {
|
|
90
|
+
EVENT[key] = val;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* 删除正则默认事件
|
|
94
|
+
* @param key 插件名
|
|
95
|
+
*/
|
|
96
|
+
export function delAppEvent(key) {
|
|
97
|
+
delete EVENT[key];
|
|
98
|
+
}
|
|
99
|
+
const PRIORITY = {};
|
|
100
|
+
/**
|
|
101
|
+
* 得到插件默认正则
|
|
102
|
+
* @param key 插件名
|
|
103
|
+
* @returns
|
|
104
|
+
*/
|
|
105
|
+
export function getAppPriority(key) {
|
|
106
|
+
return PRIORITY[key];
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* 设置插件默认正则
|
|
110
|
+
* @param key 插件名
|
|
111
|
+
* @param val 事件名
|
|
112
|
+
*/
|
|
113
|
+
export function setAppPriority(key, val) {
|
|
114
|
+
PRIORITY[key] = val;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* 删除插件默认正则
|
|
118
|
+
* @param key 插件名
|
|
119
|
+
*/
|
|
120
|
+
export function delAppPriority(key) {
|
|
121
|
+
delete PRIORITY[key];
|
|
122
|
+
}
|
package/lib/core/dealmsg.js
CHANGED
|
@@ -2,7 +2,7 @@ import { join } from 'path';
|
|
|
2
2
|
import { writeFile } from 'fs/promises';
|
|
3
3
|
import { existsSync, mkdirSync, readdirSync, readFileSync } from 'fs';
|
|
4
4
|
import lodash from 'lodash';
|
|
5
|
-
import { getAppArg,
|
|
5
|
+
import { getAppArg, getAppEvent, getAppCharacter, getAppMessage, getAppPriority } from './cache.js';
|
|
6
6
|
import { getApp, delApp, getAppKey } from './app.js';
|
|
7
7
|
import { EventEnum } from './typings.js';
|
|
8
8
|
import { conversationHandlers, getConversationState } from './dialogue.js';
|
|
@@ -64,16 +64,15 @@ function createPluginHelp() {
|
|
|
64
64
|
}
|
|
65
65
|
/**
|
|
66
66
|
* 应用挂载
|
|
67
|
+
* @param AppName 插件名
|
|
67
68
|
* @param AppsObj 插件集成对象
|
|
68
|
-
* @param appname 插件名
|
|
69
69
|
*/
|
|
70
|
-
async function synthesis(
|
|
70
|
+
async function synthesis(AppName, AppsObj) {
|
|
71
71
|
// 没有记载
|
|
72
|
-
if (!plugins[
|
|
73
|
-
plugins[
|
|
72
|
+
if (!plugins[AppName]) {
|
|
73
|
+
plugins[AppName] = [];
|
|
74
74
|
}
|
|
75
75
|
const shield = getAppProCoinfg('event');
|
|
76
|
-
const defaultCharacter = getAppProCoinfg('defaultCharacter');
|
|
77
76
|
for (const item in AppsObj) {
|
|
78
77
|
const keys = new AppsObj[item]();
|
|
79
78
|
if (shield.find(item => item == keys['event']))
|
|
@@ -102,8 +101,7 @@ async function synthesis(AppsObj, appname) {
|
|
|
102
101
|
x++;
|
|
103
102
|
}
|
|
104
103
|
CommandApp[itemX] = {
|
|
105
|
-
name:
|
|
106
|
-
character: keys?.startCharacter ?? defaultCharacter,
|
|
104
|
+
name: AppName,
|
|
107
105
|
APP: AppsObj[item]
|
|
108
106
|
};
|
|
109
107
|
for await (const key of keys['rule']) {
|
|
@@ -119,22 +117,26 @@ async function synthesis(AppsObj, appname) {
|
|
|
119
117
|
const fncName = key['fnc'];
|
|
120
118
|
const doc = key['doc'] ?? '';
|
|
121
119
|
const dsc = key['dsc'] ?? '';
|
|
120
|
+
/**
|
|
121
|
+
* 对比优先级,比设置的低
|
|
122
|
+
*/
|
|
123
|
+
const AppPriority = getAppPriority(AppName);
|
|
122
124
|
// 如果类型正确
|
|
123
125
|
if (typeof key['reg'] === 'string' || key['reg'] instanceof RegExp) {
|
|
124
126
|
// 存在正则就必须是MESSAGES
|
|
125
|
-
const event = 'MESSAGES';
|
|
127
|
+
const event = getAppEvent(AppName) ?? 'MESSAGES';
|
|
126
128
|
// 得到解析
|
|
127
129
|
const reg = key['reg'];
|
|
128
130
|
if (!reg)
|
|
129
131
|
continue;
|
|
130
132
|
// 推送
|
|
131
|
-
plugins[
|
|
133
|
+
plugins[AppName].push({
|
|
132
134
|
event: event,
|
|
133
135
|
eventType: eventType,
|
|
134
136
|
reg: String(reg),
|
|
135
137
|
dsc,
|
|
136
138
|
doc,
|
|
137
|
-
priority
|
|
139
|
+
priority: AppPriority && AppPriority < priority ? AppPriority : priority
|
|
138
140
|
});
|
|
139
141
|
// 保存
|
|
140
142
|
Command[event].push({
|
|
@@ -150,7 +152,7 @@ async function synthesis(AppsObj, appname) {
|
|
|
150
152
|
// 控制消息 -- 类型必须要存在的
|
|
151
153
|
const event = keys['event'];
|
|
152
154
|
// 推送
|
|
153
|
-
plugins[
|
|
155
|
+
plugins[AppName].push({
|
|
154
156
|
event: event,
|
|
155
157
|
eventType: eventType,
|
|
156
158
|
dsc,
|
|
@@ -161,7 +163,7 @@ async function synthesis(AppsObj, appname) {
|
|
|
161
163
|
CommandNotMessage[event].push({
|
|
162
164
|
event: event,
|
|
163
165
|
eventType: eventType,
|
|
164
|
-
priority,
|
|
166
|
+
priority: AppPriority && AppPriority < priority ? AppPriority : priority,
|
|
165
167
|
reg: /./,
|
|
166
168
|
fncName,
|
|
167
169
|
APP: itemX
|
|
@@ -242,13 +244,13 @@ export async function appsInit() {
|
|
|
242
244
|
// 得到所有插件名
|
|
243
245
|
const APPARR = getAppKey();
|
|
244
246
|
// 导出所有插件名
|
|
245
|
-
for await (const
|
|
247
|
+
for await (const AppName of APPARR) {
|
|
246
248
|
// 获取插件集
|
|
247
|
-
const apps = getApp(
|
|
249
|
+
const apps = getApp(AppName);
|
|
248
250
|
// 分析插件集
|
|
249
|
-
await synthesis(
|
|
251
|
+
await synthesis(AppName, apps);
|
|
250
252
|
// 删除指集
|
|
251
|
-
delApp(
|
|
253
|
+
delApp(AppName);
|
|
252
254
|
}
|
|
253
255
|
// 排序
|
|
254
256
|
for (const val in Command) {
|
|
@@ -306,12 +308,14 @@ export async function InstructionMatching(e) {
|
|
|
306
308
|
* 上下文
|
|
307
309
|
*/
|
|
308
310
|
for (const item in CommandApp) {
|
|
309
|
-
const { name, APP
|
|
310
|
-
const AppFnc =
|
|
311
|
+
const { name, APP } = CommandApp[item];
|
|
312
|
+
const AppFnc = getAppMessage(name);
|
|
311
313
|
const AppArg = getAppArg(name);
|
|
312
314
|
const _character = getAppProCoinfg('character');
|
|
313
315
|
if (_character.test(e.msg)) {
|
|
314
|
-
|
|
316
|
+
const character = getAppCharacter(name);
|
|
317
|
+
const __character = getAppProCoinfg('defaultCharacter');
|
|
318
|
+
e.msg = e.msg.replace(_character, character ?? __character);
|
|
315
319
|
}
|
|
316
320
|
try {
|
|
317
321
|
if (typeof AppFnc == 'function')
|
|
@@ -405,7 +409,7 @@ export async function typeMessage(e) {
|
|
|
405
409
|
const ARGCACHE = {};
|
|
406
410
|
for (const item in CommandApp) {
|
|
407
411
|
const { name, APP } = CommandApp[item];
|
|
408
|
-
const AppFnc =
|
|
412
|
+
const AppFnc = getAppMessage(name);
|
|
409
413
|
const AppArg = getAppArg(name);
|
|
410
414
|
try {
|
|
411
415
|
if (typeof AppFnc == 'function')
|
package/lib/core/index.js
CHANGED
package/lib/core/plugin.js
CHANGED
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
* 状态缓存
|
|
3
3
|
*/
|
|
4
4
|
const stateCache = {};
|
|
5
|
+
/**
|
|
6
|
+
* 定时器记录
|
|
7
|
+
*/
|
|
8
|
+
const timeoutCache = {};
|
|
5
9
|
/**
|
|
6
10
|
* 插件基础类
|
|
7
11
|
* @class
|
|
@@ -36,9 +40,160 @@ export class plugin {
|
|
|
36
40
|
*/
|
|
37
41
|
rule;
|
|
38
42
|
/**
|
|
39
|
-
*
|
|
43
|
+
* @deprecated 已废弃,建议使用原生模块 node-schedule
|
|
44
|
+
*/
|
|
45
|
+
task;
|
|
46
|
+
/**
|
|
47
|
+
* @param name 类名标记 default app-name
|
|
48
|
+
* @param event 事件类型 default MESSAGES
|
|
49
|
+
* @param eventType 消息类型 default CREATE
|
|
50
|
+
* @param priority 优先级 越小优越高 default 9000
|
|
51
|
+
* @param rule.reg 命令正则 RegExp | string
|
|
52
|
+
* @param rule.fnc 命令函数 function
|
|
53
|
+
* @param rule.dsc 指令示范 sdc
|
|
54
|
+
* @param rule.doc 指令文档 doc
|
|
55
|
+
* @param rule.priority 优先级 数字越小优先级越高
|
|
56
|
+
*/
|
|
57
|
+
constructor({ name = 'app-name', event = 'message', eventType = 'CREATE', priority = 9000, rule = [], task }) {
|
|
58
|
+
this.name = name;
|
|
59
|
+
this.event = event;
|
|
60
|
+
this.eventType = eventType;
|
|
61
|
+
this.priority = priority;
|
|
62
|
+
this.rule = rule;
|
|
63
|
+
this.task = {
|
|
64
|
+
name: task?.name ?? '',
|
|
65
|
+
fnc: task?.fnc ?? '',
|
|
66
|
+
cron: task?.cron ?? '',
|
|
67
|
+
log: task?.log ?? false
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* @param content 内容
|
|
72
|
+
* @param img 图片buffer | 指定图片名
|
|
73
|
+
* @param name 指定图片名
|
|
74
|
+
* @returns 是否处理完成
|
|
75
|
+
*/
|
|
76
|
+
async reply(content, select) {
|
|
77
|
+
if (!this.e.reply || !content || content == '')
|
|
78
|
+
return false;
|
|
79
|
+
return await this.e.reply(content, select);
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* 得到缓存的key
|
|
83
|
+
* @param isGroup
|
|
84
|
+
* @returns key
|
|
85
|
+
*/
|
|
86
|
+
conKey(isGroup = false) {
|
|
87
|
+
if (isGroup) {
|
|
88
|
+
// 应用名 频道号
|
|
89
|
+
return `${JSON.stringify(this.rule)}:${this.name}:${this.e.guild_id}`;
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
// 应用名 用户编号
|
|
93
|
+
return `${JSON.stringify(this.rule)}:${this.name}:${this.e.user_id}`;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* 设置上下文
|
|
98
|
+
* @param type 执行方法
|
|
99
|
+
* @param isGroup 是否群聊
|
|
100
|
+
* @param time 操作时间,默认120秒
|
|
101
|
+
*/
|
|
102
|
+
setContext(type, isGroup = false, time = 120) {
|
|
103
|
+
// 得到缓存key
|
|
104
|
+
const key = this.conKey(isGroup);
|
|
105
|
+
// 不存在
|
|
106
|
+
if (!stateCache[key])
|
|
107
|
+
stateCache[key] = {};
|
|
108
|
+
stateCache[key][type] = this.e;
|
|
109
|
+
// 定时
|
|
110
|
+
if (!(time && typeof time == 'number'))
|
|
111
|
+
return;
|
|
112
|
+
//
|
|
113
|
+
if (!timeoutCache[key])
|
|
114
|
+
timeoutCache[key] = {};
|
|
115
|
+
//
|
|
116
|
+
timeoutCache[key][type] = setTimeout(() => {
|
|
117
|
+
this.finish(type, isGroup);
|
|
118
|
+
this.e.reply('操作超时已取消');
|
|
119
|
+
}, time * 1000);
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
*
|
|
123
|
+
* 得到用户缓存消息对象
|
|
124
|
+
* @returns message
|
|
125
|
+
*/
|
|
126
|
+
getContext() {
|
|
127
|
+
return stateCache[this.conKey()];
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* 得到频道缓存消息对象
|
|
131
|
+
* @returns message
|
|
132
|
+
*/
|
|
133
|
+
getContextGroup() {
|
|
134
|
+
return stateCache[this.conKey(true)];
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* 完成上下文
|
|
138
|
+
* @param type 执行方法
|
|
139
|
+
* @param isGroup 是否公信
|
|
140
|
+
*/
|
|
141
|
+
finish(type, isGroup = false) {
|
|
142
|
+
if (!this.conKey(isGroup))
|
|
143
|
+
return;
|
|
144
|
+
if (
|
|
145
|
+
// 检擦key
|
|
146
|
+
stateCache[this.conKey(isGroup)] &&
|
|
147
|
+
// 检查方法
|
|
148
|
+
stateCache[this.conKey(isGroup)][type]) {
|
|
149
|
+
// 删除方法
|
|
150
|
+
delete stateCache[this.conKey(isGroup)][type];
|
|
151
|
+
}
|
|
152
|
+
if (
|
|
153
|
+
// 检擦key
|
|
154
|
+
timeoutCache[this.conKey(isGroup)] &&
|
|
155
|
+
// 检查方法
|
|
156
|
+
timeoutCache[this.conKey(isGroup)][type]) {
|
|
157
|
+
/**
|
|
158
|
+
* 删除定时任务
|
|
159
|
+
*/
|
|
160
|
+
clearTimeout(timeoutCache[this.conKey(isGroup)][type]);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* 插件基础类
|
|
166
|
+
* @class
|
|
167
|
+
*/
|
|
168
|
+
export class APlugin {
|
|
169
|
+
/**
|
|
170
|
+
* this.e 方法
|
|
171
|
+
*/
|
|
172
|
+
e;
|
|
173
|
+
/**
|
|
174
|
+
* 模块名
|
|
175
|
+
*/
|
|
176
|
+
name;
|
|
177
|
+
/**
|
|
178
|
+
* 模块说明
|
|
40
179
|
*/
|
|
41
|
-
|
|
180
|
+
dsc;
|
|
181
|
+
/**
|
|
182
|
+
* 事件枚举
|
|
183
|
+
*/
|
|
184
|
+
event;
|
|
185
|
+
/**
|
|
186
|
+
* 事件类型
|
|
187
|
+
*/
|
|
188
|
+
eventType;
|
|
189
|
+
/**
|
|
190
|
+
* 匹配优先级
|
|
191
|
+
*/
|
|
192
|
+
priority;
|
|
193
|
+
/**
|
|
194
|
+
* 匹配集
|
|
195
|
+
*/
|
|
196
|
+
rule;
|
|
42
197
|
/**
|
|
43
198
|
* @deprecated 已废弃,建议使用原生模块 node-schedule
|
|
44
199
|
*/
|
|
@@ -54,13 +209,12 @@ export class plugin {
|
|
|
54
209
|
* @param rule.doc 指令文档 doc
|
|
55
210
|
* @param rule.priority 优先级 数字越小优先级越高
|
|
56
211
|
*/
|
|
57
|
-
constructor({ name = 'app-name', event = 'MESSAGES', eventType = 'CREATE', priority = 9000,
|
|
212
|
+
constructor({ name = 'app-name', event = 'MESSAGES', eventType = 'CREATE', priority = 9000, rule = [], task }) {
|
|
58
213
|
this.name = name;
|
|
59
214
|
this.event = event;
|
|
60
215
|
this.eventType = eventType;
|
|
61
216
|
this.priority = priority;
|
|
62
217
|
this.rule = rule;
|
|
63
|
-
this.startCharacter = startCharacter;
|
|
64
218
|
this.task = {
|
|
65
219
|
name: task?.name ?? '',
|
|
66
220
|
fnc: task?.fnc ?? '',
|
|
@@ -104,17 +258,20 @@ export class plugin {
|
|
|
104
258
|
// 得到缓存key
|
|
105
259
|
const key = this.conKey(isGroup);
|
|
106
260
|
// 不存在
|
|
107
|
-
if (!stateCache[key])
|
|
261
|
+
if (!stateCache[key])
|
|
108
262
|
stateCache[key] = {};
|
|
109
|
-
}
|
|
110
263
|
stateCache[key][type] = this.e;
|
|
111
264
|
// 定时
|
|
112
|
-
if (time && typeof time == 'number')
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
265
|
+
if (!(time && typeof time == 'number'))
|
|
266
|
+
return;
|
|
267
|
+
//
|
|
268
|
+
if (!timeoutCache[key])
|
|
269
|
+
timeoutCache[key] = {};
|
|
270
|
+
//
|
|
271
|
+
timeoutCache[key][type] = setTimeout(() => {
|
|
272
|
+
this.finish(type, isGroup);
|
|
273
|
+
this.e.reply('操作超时已取消');
|
|
274
|
+
}, time * 1000);
|
|
118
275
|
}
|
|
119
276
|
/**
|
|
120
277
|
*
|
|
@@ -137,6 +294,8 @@ export class plugin {
|
|
|
137
294
|
* @param isGroup 是否公信
|
|
138
295
|
*/
|
|
139
296
|
finish(type, isGroup = false) {
|
|
297
|
+
if (!this.conKey(isGroup))
|
|
298
|
+
return;
|
|
140
299
|
if (
|
|
141
300
|
// 检擦key
|
|
142
301
|
stateCache[this.conKey(isGroup)] &&
|
|
@@ -145,5 +304,15 @@ export class plugin {
|
|
|
145
304
|
// 删除方法
|
|
146
305
|
delete stateCache[this.conKey(isGroup)][type];
|
|
147
306
|
}
|
|
307
|
+
if (
|
|
308
|
+
// 检擦key
|
|
309
|
+
timeoutCache[this.conKey(isGroup)] &&
|
|
310
|
+
// 检查方法
|
|
311
|
+
timeoutCache[this.conKey(isGroup)][type]) {
|
|
312
|
+
/**
|
|
313
|
+
* 删除定时任务
|
|
314
|
+
*/
|
|
315
|
+
clearTimeout(timeoutCache[this.conKey(isGroup)][type]);
|
|
316
|
+
}
|
|
148
317
|
}
|
|
149
318
|
}
|
package/lib/define/main.js
CHANGED
|
@@ -2,14 +2,14 @@ import PupOptions from '../default/pup.js';
|
|
|
2
2
|
import { rebotMap } from './map.js';
|
|
3
3
|
import { nodeScripts } from './child_process.js';
|
|
4
4
|
import { AvailableIntentsEventsEnum } from 'qq-guild-bot';
|
|
5
|
-
import {
|
|
5
|
+
import { ClientNTQQ } from '../ntqq/sdk/index.js';
|
|
6
6
|
import { command } from './command.js';
|
|
7
7
|
import { createApp, setLanchConfig, loadInit, appsInit, setAppProCoinfg, startChrom } from '../core/index.js';
|
|
8
8
|
import { getPupPath, setBotConfigByKey, getBotConfigByKey } from '../config/index.js';
|
|
9
9
|
import { createWeb } from '../koa/index.js';
|
|
10
10
|
import { autoClearImages } from '../koa/img.js';
|
|
11
11
|
// 设置ntqq独立鉴权路径
|
|
12
|
-
export const setAuthenticationByNtqq =
|
|
12
|
+
export const setAuthenticationByNtqq = ClientNTQQ.setAuthentication;
|
|
13
13
|
let OptionsCache;
|
|
14
14
|
/**
|
|
15
15
|
* 得到初始化配置
|