alemonjs 1.1.31 → 1.1.33
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/README.md +36 -9
- package/lib/core/call.js +2 -2
- package/lib/core/conversation/dialogue.js +61 -0
- package/lib/core/conversation/index.js +26 -0
- package/lib/core/dealmsg.js +26 -40
- package/lib/core/index.js +4 -4
- package/lib/core/main.js +5 -5
- package/lib/core/plugin/plugin.js +201 -0
- package/lib/core/plugin/types.js +1 -0
- package/lib/core/plugin.js +52 -12
- package/lib/core/screenshot.js +2 -2
- package/lib/core/utils/puppeteer.js +181 -0
- package/lib/core/utils/screenshot.js +92 -0
- package/lib/discord/alemon/segment.js +2 -0
- package/lib/discord/sdk/wss.js +9 -9
- package/lib/index.js +6 -6
- package/lib/kook/alemon/segment.js +2 -0
- package/lib/ntqq/alemon/group/segment.js +2 -0
- package/lib/qq/alemon/segment.js +2 -0
- package/lib/villa/alemon/segment.js +6 -4
- package/lib/villa/sdk/proto/command.proto +112 -112
- package/lib/villa/sdk/proto/model.proto +158 -158
- package/lib/villa/sdk/proto/robot_event_message.proto +10 -10
- package/package.json +80 -73
- package/types/core/apps.d.ts +1 -1
- package/types/core/conversation/dialogue.d.ts +57 -0
- package/types/core/conversation/index.d.ts +20 -0
- package/types/core/index.d.ts +4 -4
- package/types/core/main.d.ts +5 -5
- package/types/core/plugin/plugin.d.ts +144 -0
- package/types/core/plugin/types.d.ts +60 -0
- package/types/core/plugin.d.ts +51 -2
- package/types/core/plugin.types.d.ts +5 -5
- package/types/core/typings.d.ts +7 -0
- package/types/core/utils/puppeteer.d.ts +57 -0
- package/types/core/utils/screenshot.d.ts +28 -0
- package/types/discord/alemon/segment.d.ts +2 -0
- package/types/discord/sdk/api.d.ts +2 -2
- package/types/index.d.ts +6 -6
- package/types/kook/alemon/segment.d.ts +2 -0
- package/types/login.d.ts +1 -1
- package/types/ntqq/alemon/group/segment.d.ts +2 -0
- package/types/qq/alemon/segment.d.ts +2 -0
- package/types/villa/alemon/segment.d.ts +4 -2
package/README.md
CHANGED
|
@@ -16,20 +16,19 @@
|
|
|
16
16
|
|
|
17
17
|
<div align="center">
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
提供了热开发和打包编译工具,除此,也能自行混淆压缩来提高机器人响应速度
|
|
19
|
+
事件驱动的跨平台开发框架,支持 QQ (群&频道)、KOOK、Discord、米游社大别野等平台
|
|
22
20
|
|
|
23
21
|
</div>
|
|
24
22
|
|
|
25
23
|
### Ecosystem
|
|
26
24
|
|
|
27
|
-
| Project | Status | Description
|
|
28
|
-
| ----------------- | ---------------------------------------------------- |
|
|
29
|
-
| [alemonjs] | [![alemonjs-status]][alemonjs-package] |
|
|
30
|
-
| [create-alemonjs] | [![create-alemonjs-status]][create-alemonjs-package] | 模板创建脚手架
|
|
31
|
-
| [afloat] | [![afloat-status]][afloat-package] |
|
|
32
|
-
| [alemon-ffmpeg] | [![alemon-ffmpeg-status]][alemon-ffmpeg-package] | ffmpeg
|
|
25
|
+
| Project | Status | Description |
|
|
26
|
+
| ----------------- | ---------------------------------------------------- | --------------- |
|
|
27
|
+
| [alemonjs] | [![alemonjs-status]][alemonjs-package] | 标准应用解析器 |
|
|
28
|
+
| [create-alemonjs] | [![create-alemonjs-status]][create-alemonjs-package] | 模板创建脚手架 |
|
|
29
|
+
| [afloat] | [![afloat-status]][afloat-package] | 热开发&打包工具 |
|
|
30
|
+
| [alemon-ffmpeg] | [![alemon-ffmpeg-status]][alemon-ffmpeg-package] | ffmpeg 自动下载 |
|
|
31
|
+
| [alemon-onebot] | [![alemon-onebot-status]][alemon-onebot-package] | OneBot 协议平台 |
|
|
33
32
|
|
|
34
33
|
<p>
|
|
35
34
|
|
|
@@ -55,6 +54,12 @@
|
|
|
55
54
|
[alemon-ffmpeg-status]: https://img.shields.io/npm/v/alemon-ffmpeg.svg
|
|
56
55
|
[alemon-ffmpeg-package]: https://www.npmjs.com/package/alemon-ffmpeg
|
|
57
56
|
|
|
57
|
+
<p>
|
|
58
|
+
|
|
59
|
+
[alemon-onebot]: https://github.com/ningmengchongshui/alemon/tree/alemon-onebot
|
|
60
|
+
[alemon-onebot-status]: https://img.shields.io/npm/v/alemon-onebot.svg
|
|
61
|
+
[alemon-onebot-package]: https://www.npmjs.com/package/alemon-onebot
|
|
62
|
+
|
|
58
63
|
### Quick Start
|
|
59
64
|
|
|
60
65
|
可直接执行脚手架 并快速启动程序
|
|
@@ -191,3 +196,25 @@ npm run build
|
|
|
191
196
|
打包完成后,会生成`dist/main.js`和`package.json`文件
|
|
192
197
|
|
|
193
198
|
该程序可放置于`plugins/your plugin name`文件夹下
|
|
199
|
+
|
|
200
|
+
### dependencies
|
|
201
|
+
|
|
202
|
+
```json
|
|
203
|
+
{
|
|
204
|
+
"axios": "接口",
|
|
205
|
+
"file-type": "文件类型判断",
|
|
206
|
+
"form-data": "文件流",
|
|
207
|
+
"image-size": "图片大小",
|
|
208
|
+
"koa": "服务框架",
|
|
209
|
+
"koa-bodyparser": "数据解析",
|
|
210
|
+
"koa-router": "路由处理",
|
|
211
|
+
"koa2-cors": "跨域处理",
|
|
212
|
+
"lodash-es": "工具包",
|
|
213
|
+
"mime-types": "文件类型",
|
|
214
|
+
"protobufjs": "新文件格式",
|
|
215
|
+
"public-ip": "公网识别",
|
|
216
|
+
"puppeteer": "浏览器",
|
|
217
|
+
"qrcode": "二维码",
|
|
218
|
+
"ws": "连接协议"
|
|
219
|
+
}
|
|
220
|
+
```
|
package/lib/core/call.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { orderBy } from 'lodash-es';
|
|
2
2
|
const CALL = {
|
|
3
3
|
AUDIO_FREQUENCY: [],
|
|
4
4
|
AUDIO_MICROPHONE: [],
|
|
@@ -20,7 +20,7 @@ const CALL = {
|
|
|
20
20
|
export function orderByAppCall() {
|
|
21
21
|
// 排序
|
|
22
22
|
for (const val in CALL) {
|
|
23
|
-
CALL[val] =
|
|
23
|
+
CALL[val] = orderBy(CALL[val], ['priority'], ['asc']);
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
26
|
/**
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 注册对话处理器
|
|
3
|
+
* @deprecated Conversation.add
|
|
4
|
+
*/
|
|
5
|
+
export const conversationHandlers = new Map();
|
|
6
|
+
/**
|
|
7
|
+
*对话缓存
|
|
8
|
+
*/
|
|
9
|
+
const Sockes = {};
|
|
10
|
+
/**
|
|
11
|
+
* 得到对话
|
|
12
|
+
* @param key 对话键
|
|
13
|
+
* @returns 对话值
|
|
14
|
+
*/
|
|
15
|
+
const getAsync = async (key) => {
|
|
16
|
+
return Sockes[key];
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* 设置对话
|
|
20
|
+
* @param key 对话键
|
|
21
|
+
* @param val 对话值
|
|
22
|
+
*/
|
|
23
|
+
const setAsync = async (key, val) => {
|
|
24
|
+
Sockes[key] = val;
|
|
25
|
+
return;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* 删除对话
|
|
29
|
+
* @param key 对话键
|
|
30
|
+
*/
|
|
31
|
+
const delAsync = async (key) => {
|
|
32
|
+
delete Sockes[key];
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* 获取对话状态
|
|
36
|
+
* @param ID 编号
|
|
37
|
+
* @returns 对话状态值
|
|
38
|
+
* @deprecated 不推荐使用
|
|
39
|
+
*/
|
|
40
|
+
export const getConversationState = async (ID) => {
|
|
41
|
+
const state = await getAsync(`conversation-state:${ID}`);
|
|
42
|
+
return state ? JSON.parse(state) : null;
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* 设置对话状态
|
|
46
|
+
* @param ID 编号
|
|
47
|
+
* @param state 状态记录
|
|
48
|
+
* @deprecated Conversation.passing
|
|
49
|
+
*/
|
|
50
|
+
export const setConversationState = async (ID, state) => {
|
|
51
|
+
await setAsync(`conversation-state:${ID}`, JSON.stringify(state));
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* 删除对话状态
|
|
55
|
+
* @param ID 编号
|
|
56
|
+
* @deprecated Conversation.del
|
|
57
|
+
*/
|
|
58
|
+
export const deleteConversationState = async (ID) => {
|
|
59
|
+
// 删除数据
|
|
60
|
+
await delAsync(`conversation-state:${ID}`);
|
|
61
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { conversationHandlers, deleteConversationState, setConversationState } from './dialogue.js';
|
|
2
|
+
/**
|
|
3
|
+
* 对话机
|
|
4
|
+
*/
|
|
5
|
+
export const Conversation = {
|
|
6
|
+
/**
|
|
7
|
+
* 设置对话状态
|
|
8
|
+
* @param ID 用户编号
|
|
9
|
+
* @param state 状态记录
|
|
10
|
+
*/
|
|
11
|
+
passing: setConversationState,
|
|
12
|
+
/**
|
|
13
|
+
* 删除对话状态
|
|
14
|
+
* @param ID 用户编号
|
|
15
|
+
*/
|
|
16
|
+
remove: (ID) => {
|
|
17
|
+
// 删除数据
|
|
18
|
+
deleteConversationState(ID);
|
|
19
|
+
// 删除函数
|
|
20
|
+
conversationHandlers.delete(ID);
|
|
21
|
+
},
|
|
22
|
+
/**
|
|
23
|
+
* 注册对话
|
|
24
|
+
*/
|
|
25
|
+
add: conversationHandlers.set
|
|
26
|
+
};
|
package/lib/core/dealmsg.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { join } from 'path';
|
|
2
2
|
import { writeFile } from 'fs/promises';
|
|
3
3
|
import { existsSync, mkdirSync, readdirSync } from 'fs';
|
|
4
|
-
import
|
|
4
|
+
import { isEmpty, orderBy } from 'lodash-es';
|
|
5
5
|
import { getAppArg, getAppEvent, getAppMessage, getAppPriority, getAppSlicing, getApp, delApp, getAppKey } from './cache.js';
|
|
6
6
|
import { EventEnum } from './typings.js';
|
|
7
|
-
import { conversationHandlers, getConversationState } from './dialogue.js';
|
|
7
|
+
import { conversationHandlers, getConversationState } from './conversation/dialogue.js';
|
|
8
8
|
import { getAppProCoinfg } from './configs.js';
|
|
9
9
|
import { getAppCall, orderByAppCall } from './call.js';
|
|
10
10
|
const Command = {};
|
|
@@ -272,11 +272,11 @@ export async function appsInit() {
|
|
|
272
272
|
}
|
|
273
273
|
// 排序
|
|
274
274
|
for (const val in Command) {
|
|
275
|
-
Command[val] =
|
|
275
|
+
Command[val] = orderBy(Command[val], ['priority'], ['asc']);
|
|
276
276
|
}
|
|
277
277
|
// 排序
|
|
278
278
|
for (const val in CommandNotMessage) {
|
|
279
|
-
CommandNotMessage[val] =
|
|
279
|
+
CommandNotMessage[val] = orderBy(CommandNotMessage[val], ['priority'], ['asc']);
|
|
280
280
|
}
|
|
281
281
|
// 排序之后把所有正则变成一条正则
|
|
282
282
|
const mergedRegexArr = [];
|
|
@@ -394,14 +394,11 @@ export async function InstructionMatching(e) {
|
|
|
394
394
|
// 得到缓存
|
|
395
395
|
const context = app.getContext();
|
|
396
396
|
// 是否为 null && undefined && '' && [] && {}
|
|
397
|
-
if (!
|
|
397
|
+
if (!isEmpty(context)) {
|
|
398
398
|
// 得到缓存中的e消息
|
|
399
399
|
for (const fnc in context) {
|
|
400
400
|
// 丢给自己
|
|
401
|
-
|
|
402
|
-
if (back && typeof back == 'function') {
|
|
403
|
-
back(context[fnc]);
|
|
404
|
-
}
|
|
401
|
+
await app[fnc](context[fnc]);
|
|
405
402
|
}
|
|
406
403
|
return;
|
|
407
404
|
}
|
|
@@ -411,14 +408,11 @@ export async function InstructionMatching(e) {
|
|
|
411
408
|
// 得到缓存
|
|
412
409
|
const context = app.getContextGroup();
|
|
413
410
|
// 是否为 null && undefined && '' && [] && {}
|
|
414
|
-
if (!
|
|
411
|
+
if (!isEmpty(context)) {
|
|
415
412
|
// 得到缓存中的e消息
|
|
416
413
|
for (const fnc in context) {
|
|
417
414
|
// 丢给自己
|
|
418
|
-
|
|
419
|
-
if (back && typeof back == 'function') {
|
|
420
|
-
back(context[fnc]);
|
|
421
|
-
}
|
|
415
|
+
await app[fnc](context[fnc]);
|
|
422
416
|
return;
|
|
423
417
|
}
|
|
424
418
|
}
|
|
@@ -445,20 +439,16 @@ export async function InstructionMatching(e) {
|
|
|
445
439
|
continue;
|
|
446
440
|
}
|
|
447
441
|
try {
|
|
448
|
-
const
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
.
|
|
454
|
-
|
|
455
|
-
e.reply(res).catch(err => {
|
|
456
|
-
console.error('APP REPLY', err);
|
|
457
|
-
});
|
|
458
|
-
}
|
|
459
|
-
if (res != false)
|
|
460
|
-
break;
|
|
442
|
+
const res = await APPCACHE[data.APP][data.fncName](e, ...(ARGCACHE[data.APP] ?? []))
|
|
443
|
+
.then(info(data))
|
|
444
|
+
.catch(logErr(data));
|
|
445
|
+
if (typeof res != 'boolean') {
|
|
446
|
+
e.reply(res).catch(err => {
|
|
447
|
+
console.error('APP REPLY', err);
|
|
448
|
+
});
|
|
461
449
|
}
|
|
450
|
+
if (res != false)
|
|
451
|
+
break;
|
|
462
452
|
}
|
|
463
453
|
catch (err) {
|
|
464
454
|
logErr(data)(err);
|
|
@@ -519,20 +509,16 @@ export async function InstructionMatchingByNotMessage(e) {
|
|
|
519
509
|
if (e.typing != data.typing)
|
|
520
510
|
continue;
|
|
521
511
|
try {
|
|
522
|
-
const
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
.
|
|
528
|
-
|
|
529
|
-
e.reply(res).catch(err => {
|
|
530
|
-
console.error('APP REPLY', err);
|
|
531
|
-
});
|
|
532
|
-
}
|
|
533
|
-
if (res != false)
|
|
534
|
-
break;
|
|
512
|
+
const res = await APPCACHE[data.APP][data.fncName](e, ...(ARGCACHE[data.APP] ?? []))
|
|
513
|
+
.then(info(data))
|
|
514
|
+
.catch(logErr(data));
|
|
515
|
+
if (typeof res != 'boolean') {
|
|
516
|
+
e.reply(res).catch(err => {
|
|
517
|
+
console.error('APP REPLY', err);
|
|
518
|
+
});
|
|
535
519
|
}
|
|
520
|
+
if (res != false)
|
|
521
|
+
break;
|
|
536
522
|
}
|
|
537
523
|
catch (err) {
|
|
538
524
|
logErr(data)(err);
|
package/lib/core/index.js
CHANGED
|
@@ -3,15 +3,15 @@
|
|
|
3
3
|
* private
|
|
4
4
|
* ********
|
|
5
5
|
*/
|
|
6
|
-
export * from './plugin.js';
|
|
6
|
+
export * from './plugin/plugin.js';
|
|
7
7
|
export * from './configs.js';
|
|
8
8
|
export * from './apps.js';
|
|
9
9
|
export * from './cache.js';
|
|
10
|
-
export * from './dialogue.js';
|
|
10
|
+
export * from './conversation/dialogue.js';
|
|
11
11
|
export * from './utils/qrcode.js';
|
|
12
12
|
export * from './dealmsg.js';
|
|
13
|
-
export * from './puppeteer.js';
|
|
14
|
-
export * from './screenshot.js';
|
|
13
|
+
export * from './utils/puppeteer.js';
|
|
14
|
+
export * from './utils/screenshot.js';
|
|
15
15
|
export * from './typings.js';
|
|
16
16
|
export * from './utils/buffer.js';
|
|
17
17
|
export * from './utils/ip.js';
|
package/lib/core/main.js
CHANGED
|
@@ -7,11 +7,11 @@ export * from './apps.js';
|
|
|
7
7
|
export * from './utils/buffer.js';
|
|
8
8
|
export * from './configs.js';
|
|
9
9
|
export * from './help.js';
|
|
10
|
-
export * from './dialogue.js';
|
|
11
|
-
export * from './conversation.js';
|
|
10
|
+
export * from './conversation/dialogue.js';
|
|
11
|
+
export * from './conversation/index.js';
|
|
12
12
|
export * from './utils/ip.js';
|
|
13
|
-
export * from './plugin.js';
|
|
14
|
-
export * from './puppeteer.js';
|
|
13
|
+
export * from './plugin/plugin.js';
|
|
14
|
+
export * from './utils/puppeteer.js';
|
|
15
15
|
export * from './utils/qrcode.js';
|
|
16
|
-
export * from './screenshot.js';
|
|
16
|
+
export * from './utils/screenshot.js';
|
|
17
17
|
export * from './typings.js';
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 状态缓存
|
|
3
|
+
*/
|
|
4
|
+
const stateCache = {};
|
|
5
|
+
/**
|
|
6
|
+
* 定时器记录
|
|
7
|
+
*/
|
|
8
|
+
const timeoutCache = {};
|
|
9
|
+
/**
|
|
10
|
+
* base plugin
|
|
11
|
+
* 插件基础类
|
|
12
|
+
* @class
|
|
13
|
+
*/
|
|
14
|
+
export class BPlugin {
|
|
15
|
+
/**
|
|
16
|
+
* this.e 方法
|
|
17
|
+
*/
|
|
18
|
+
e;
|
|
19
|
+
/**
|
|
20
|
+
* 模块名
|
|
21
|
+
*/
|
|
22
|
+
name = '';
|
|
23
|
+
/**
|
|
24
|
+
* 模块说明
|
|
25
|
+
*/
|
|
26
|
+
dsc = '';
|
|
27
|
+
/**
|
|
28
|
+
* 事件枚举
|
|
29
|
+
*/
|
|
30
|
+
event = 'MESSAGES';
|
|
31
|
+
/**
|
|
32
|
+
* 事件类型
|
|
33
|
+
*/
|
|
34
|
+
typing = 'CREATE';
|
|
35
|
+
/**
|
|
36
|
+
* 匹配优先级
|
|
37
|
+
*/
|
|
38
|
+
priority = 9000;
|
|
39
|
+
/**
|
|
40
|
+
* 匹配集
|
|
41
|
+
*/
|
|
42
|
+
rule = [];
|
|
43
|
+
/**
|
|
44
|
+
* @param name 类名标记 default app-name
|
|
45
|
+
* @param event 事件类型 default MESSAGES
|
|
46
|
+
* @param typing 消息类型 default CREATE
|
|
47
|
+
* @param priority 优先级 default 9000 越小优先级越高
|
|
48
|
+
* @param rule.reg 命令正则 RegExp | string
|
|
49
|
+
* @param rule.fnc 命令函数 Function
|
|
50
|
+
* @param rule.dsc 指令示范 sdc
|
|
51
|
+
* @param rule.doc 指令文档 doc
|
|
52
|
+
* @param rule.priority 优先级 数字越小优先级越高
|
|
53
|
+
*/
|
|
54
|
+
constructor(init) {
|
|
55
|
+
Object.assign(this, init);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* alemonjs plugin
|
|
60
|
+
* 插件标准类
|
|
61
|
+
* @class
|
|
62
|
+
*/
|
|
63
|
+
export class APlugin {
|
|
64
|
+
/**
|
|
65
|
+
* this.e 方法
|
|
66
|
+
*/
|
|
67
|
+
e;
|
|
68
|
+
/**
|
|
69
|
+
* 模块名
|
|
70
|
+
*/
|
|
71
|
+
name;
|
|
72
|
+
/**
|
|
73
|
+
* 模块说明
|
|
74
|
+
*/
|
|
75
|
+
dsc;
|
|
76
|
+
/**
|
|
77
|
+
* 事件枚举
|
|
78
|
+
*/
|
|
79
|
+
event;
|
|
80
|
+
/**
|
|
81
|
+
* 事件类型
|
|
82
|
+
*/
|
|
83
|
+
typing;
|
|
84
|
+
/**
|
|
85
|
+
* 匹配优先级
|
|
86
|
+
*/
|
|
87
|
+
priority;
|
|
88
|
+
/**
|
|
89
|
+
* 匹配集
|
|
90
|
+
*/
|
|
91
|
+
rule;
|
|
92
|
+
/**
|
|
93
|
+
* @deprecated 已废弃,建议使用原生模块 node-schedule
|
|
94
|
+
*/
|
|
95
|
+
task;
|
|
96
|
+
/**
|
|
97
|
+
* @param name 类名标记 default app-name
|
|
98
|
+
* @param event 事件类型 default MESSAGES
|
|
99
|
+
* @param typing 消息类型 default CREATE
|
|
100
|
+
* @param priority 优先级 越小优越高 default 9000
|
|
101
|
+
* @param rule.reg 命令正则 RegExp | string
|
|
102
|
+
* @param rule.fnc 命令函数 function
|
|
103
|
+
* @param rule.dsc 指令示范 sdc
|
|
104
|
+
* @param rule.doc 指令文档 doc
|
|
105
|
+
* @param rule.priority 优先级 数字越小优先级越高
|
|
106
|
+
*/
|
|
107
|
+
constructor(init) {
|
|
108
|
+
Object.assign(this, init);
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* @param content 内容
|
|
112
|
+
* @param img 图片buffer | 指定图片名
|
|
113
|
+
* @param name 指定图片名
|
|
114
|
+
* @returns 是否处理完成
|
|
115
|
+
*/
|
|
116
|
+
async reply(content, select) {
|
|
117
|
+
if (!this.e.reply || !content || content == '')
|
|
118
|
+
return false;
|
|
119
|
+
return await this.e.reply(content, select);
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* 得到缓存的key
|
|
123
|
+
* @param isGroup
|
|
124
|
+
* @returns key
|
|
125
|
+
*/
|
|
126
|
+
conKey(isGroup = false) {
|
|
127
|
+
// 应用名 频道号
|
|
128
|
+
if (isGroup)
|
|
129
|
+
return `${JSON.stringify(this.rule)}:${this.name}:${this.e.guild_id}`;
|
|
130
|
+
// 应用名 用户编号
|
|
131
|
+
return `${JSON.stringify(this.rule)}:${this.name}:${this.e.user_id}`;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* 设置上下文
|
|
135
|
+
* @param type 执行方法
|
|
136
|
+
* @param isGroup 是否群聊
|
|
137
|
+
* @param time 操作时间,默认120秒
|
|
138
|
+
*/
|
|
139
|
+
setContext(type, isGroup = false, time = 120) {
|
|
140
|
+
// 得到缓存key
|
|
141
|
+
const key = this.conKey(isGroup);
|
|
142
|
+
// 不存在
|
|
143
|
+
if (!stateCache[key])
|
|
144
|
+
stateCache[key] = {};
|
|
145
|
+
stateCache[key][type] = this.e;
|
|
146
|
+
// 定时
|
|
147
|
+
if (!(time && typeof time == 'number'))
|
|
148
|
+
return;
|
|
149
|
+
//
|
|
150
|
+
if (!timeoutCache[key])
|
|
151
|
+
timeoutCache[key] = {};
|
|
152
|
+
//
|
|
153
|
+
timeoutCache[key][type] = setTimeout(() => {
|
|
154
|
+
this.finish(type, isGroup);
|
|
155
|
+
this.e.reply('操作超时已取消');
|
|
156
|
+
}, time * 1000);
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
*
|
|
160
|
+
* 得到用户缓存消息对象
|
|
161
|
+
* @returns message
|
|
162
|
+
*/
|
|
163
|
+
getContext() {
|
|
164
|
+
return stateCache[this.conKey()];
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* 得到频道缓存消息对象
|
|
168
|
+
* @returns message
|
|
169
|
+
*/
|
|
170
|
+
getContextGroup() {
|
|
171
|
+
return stateCache[this.conKey(true)];
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* 完成上下文
|
|
175
|
+
* @param type 执行方法
|
|
176
|
+
* @param isGroup 是否公信
|
|
177
|
+
*/
|
|
178
|
+
finish(type, isGroup = false) {
|
|
179
|
+
if (!this.conKey(isGroup))
|
|
180
|
+
return;
|
|
181
|
+
if (
|
|
182
|
+
// 检擦key
|
|
183
|
+
stateCache[this.conKey(isGroup)] &&
|
|
184
|
+
// 检查方法
|
|
185
|
+
stateCache[this.conKey(isGroup)][type]) {
|
|
186
|
+
// 删除方法
|
|
187
|
+
delete stateCache[this.conKey(isGroup)][type];
|
|
188
|
+
}
|
|
189
|
+
if (
|
|
190
|
+
// 检擦key
|
|
191
|
+
timeoutCache[this.conKey(isGroup)] &&
|
|
192
|
+
// 检查方法
|
|
193
|
+
timeoutCache[this.conKey(isGroup)][type]) {
|
|
194
|
+
/**
|
|
195
|
+
* 删除定时任务
|
|
196
|
+
*/
|
|
197
|
+
clearTimeout(timeoutCache[this.conKey(isGroup)][type]);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
export const plugin = APlugin;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/lib/core/plugin.js
CHANGED
|
@@ -7,9 +7,59 @@ const stateCache = {};
|
|
|
7
7
|
*/
|
|
8
8
|
const timeoutCache = {};
|
|
9
9
|
/**
|
|
10
|
+
* base plugin
|
|
10
11
|
* 插件基础类
|
|
11
12
|
* @class
|
|
12
13
|
*/
|
|
14
|
+
export class BPlugin {
|
|
15
|
+
/**
|
|
16
|
+
* this.e 方法
|
|
17
|
+
*/
|
|
18
|
+
e;
|
|
19
|
+
/**
|
|
20
|
+
* 模块名
|
|
21
|
+
*/
|
|
22
|
+
name = '';
|
|
23
|
+
/**
|
|
24
|
+
* 模块说明
|
|
25
|
+
*/
|
|
26
|
+
dsc = '';
|
|
27
|
+
/**
|
|
28
|
+
* 事件枚举
|
|
29
|
+
*/
|
|
30
|
+
event = 'MESSAGES';
|
|
31
|
+
/**
|
|
32
|
+
* 事件类型
|
|
33
|
+
*/
|
|
34
|
+
typing = 'CREATE';
|
|
35
|
+
/**
|
|
36
|
+
* 匹配优先级
|
|
37
|
+
*/
|
|
38
|
+
priority = 9000;
|
|
39
|
+
/**
|
|
40
|
+
* 匹配集
|
|
41
|
+
*/
|
|
42
|
+
rule = [];
|
|
43
|
+
/**
|
|
44
|
+
* @param name 类名标记 default app-name
|
|
45
|
+
* @param event 事件类型 default MESSAGES
|
|
46
|
+
* @param typing 消息类型 default CREATE
|
|
47
|
+
* @param priority 优先级 default 9000 越小优先级越高
|
|
48
|
+
* @param rule.reg 命令正则 RegExp | string
|
|
49
|
+
* @param rule.fnc 命令函数 Function
|
|
50
|
+
* @param rule.dsc 指令示范 sdc
|
|
51
|
+
* @param rule.doc 指令文档 doc
|
|
52
|
+
* @param rule.priority 优先级 数字越小优先级越高
|
|
53
|
+
*/
|
|
54
|
+
constructor(init) {
|
|
55
|
+
Object.assign(this, init);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* alemonjs plugin
|
|
60
|
+
* 插件标准类
|
|
61
|
+
* @class
|
|
62
|
+
*/
|
|
13
63
|
export class APlugin {
|
|
14
64
|
/**
|
|
15
65
|
* this.e 方法
|
|
@@ -54,18 +104,8 @@ export class APlugin {
|
|
|
54
104
|
* @param rule.doc 指令文档 doc
|
|
55
105
|
* @param rule.priority 优先级 数字越小优先级越高
|
|
56
106
|
*/
|
|
57
|
-
constructor(
|
|
58
|
-
this
|
|
59
|
-
this.event = event;
|
|
60
|
-
this.typing = typing;
|
|
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
|
-
};
|
|
107
|
+
constructor(init) {
|
|
108
|
+
Object.assign(this, init);
|
|
69
109
|
}
|
|
70
110
|
/**
|
|
71
111
|
* @param content 内容
|
package/lib/core/screenshot.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { isEqual } from 'lodash-es';
|
|
2
2
|
import { join, basename } from 'path';
|
|
3
3
|
import { readFileSync, watch, mkdirSync } from 'fs';
|
|
4
4
|
import { getAppProCoinfg } from './configs.js';
|
|
@@ -168,7 +168,7 @@ export function createStr(Options) {
|
|
|
168
168
|
/**
|
|
169
169
|
* 模板对象不同需要更新数据
|
|
170
170
|
*/
|
|
171
|
-
if (!
|
|
171
|
+
if (!isEqual(CacheData[tplFile], data ?? {})) {
|
|
172
172
|
CacheData[tplFile] = data ?? {};
|
|
173
173
|
control = true;
|
|
174
174
|
}
|