alemonjs 1.1.20 → 1.1.21
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/core/conversation.js +26 -0
- package/lib/core/dealmsg.js +20 -11
- package/lib/core/dialogue.js +18 -13
- package/lib/core/index.js +1 -0
- package/lib/core/plugin.js +8 -8
- package/lib/core/typings.js +1 -1
- package/lib/discord/alemon/message/MESSAGE_CREATE.js +1 -1
- package/lib/kook/alemon/message/DIRECT_MESSAGE.js +1 -1
- package/lib/kook/alemon/message/GUILD_MESSAGE_REACTIONS.js +1 -1
- package/lib/kook/alemon/message/PUBLIC_GUILD_MESSAGES.js +1 -1
- package/lib/ntqq/alemon/group/message/C2C_MESSAGE_CREATE.js +1 -1
- package/lib/ntqq/alemon/group/message/GROUP_AT_MESSAGE_CREATE.js +1 -1
- package/lib/one/alemon/message/DIRECT_MESSAGE.js +1 -1
- package/lib/one/alemon/message/MESSAGES.js +1 -1
- package/lib/qq/alemon/message/AUDIO_ACTION.js +5 -5
- package/lib/qq/alemon/message/CHANNEL.js +3 -3
- package/lib/qq/alemon/message/DIRECT_MESSAGE.js +4 -4
- package/lib/qq/alemon/message/FORUMS_EVENT.js +3 -3
- package/lib/qq/alemon/message/GUILDS.js +3 -3
- package/lib/qq/alemon/message/GUILD_MEMBERS.js +3 -3
- package/lib/qq/alemon/message/GUILD_MESSAGES.js +4 -4
- package/lib/qq/alemon/message/GUILD_MESSAGE_REACTIONS.js +3 -3
- package/lib/qq/alemon/message/INTERACTION.js +4 -4
- package/lib/qq/alemon/message/MESSAGE_AUDIT.js +4 -4
- package/lib/qq/alemon/message/OPEN_FORUMS_EVENT.js +6 -6
- package/lib/qq/alemon/message/PUBLIC_GUILD_MESSAGES.js +4 -4
- package/lib/villa/alemon/message/GUILD_BOT.js +3 -3
- package/lib/villa/alemon/message/GUILD_MEMBERS.js +3 -3
- package/lib/villa/alemon/message/GUILD_MESSAGE_REACTIONS.js +3 -3
- package/lib/villa/alemon/message/MESSAGES.js +1 -1
- package/lib/villa/alemon/message/MESSAGE_AUDIT.js +3 -3
- package/lib/villa/alemon/message/MESSAGE_BUTTON.js +1 -1
- package/package.json +1 -1
- package/types/core/conversation.d.ts +20 -0
- package/types/core/dialogue.d.ts +11 -7
- package/types/core/index.d.ts +1 -0
- package/types/core/plugin.d.ts +8 -8
- package/types/core/typings.d.ts +2 -2
|
@@ -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
|
@@ -66,7 +66,7 @@ async function synthesis(AppName, AppsObj) {
|
|
|
66
66
|
if (shield.find(item => item == keys['event']))
|
|
67
67
|
continue;
|
|
68
68
|
// 控制类型
|
|
69
|
-
const
|
|
69
|
+
const typing = keys['typing'] ?? 'CREATE';
|
|
70
70
|
// 不合法
|
|
71
71
|
if (!keys['rule'] ||
|
|
72
72
|
!Array.isArray(keys['rule']) ||
|
|
@@ -118,7 +118,7 @@ async function synthesis(AppName, AppsObj) {
|
|
|
118
118
|
// 推送
|
|
119
119
|
plugins[AppName].push({
|
|
120
120
|
event: event,
|
|
121
|
-
|
|
121
|
+
typing: typing,
|
|
122
122
|
reg: String(reg),
|
|
123
123
|
dsc,
|
|
124
124
|
doc,
|
|
@@ -127,7 +127,7 @@ async function synthesis(AppName, AppsObj) {
|
|
|
127
127
|
// 保存
|
|
128
128
|
Command[event].push({
|
|
129
129
|
event: event,
|
|
130
|
-
|
|
130
|
+
typing: typing,
|
|
131
131
|
reg: new RegExp(reg),
|
|
132
132
|
priority,
|
|
133
133
|
fncName,
|
|
@@ -140,7 +140,7 @@ async function synthesis(AppName, AppsObj) {
|
|
|
140
140
|
// 推送
|
|
141
141
|
plugins[AppName].push({
|
|
142
142
|
event: event,
|
|
143
|
-
|
|
143
|
+
typing: typing,
|
|
144
144
|
dsc,
|
|
145
145
|
doc,
|
|
146
146
|
priority
|
|
@@ -148,7 +148,7 @@ async function synthesis(AppName, AppsObj) {
|
|
|
148
148
|
// 保存
|
|
149
149
|
CommandNotMessage[event].push({
|
|
150
150
|
event: event,
|
|
151
|
-
|
|
151
|
+
typing: typing,
|
|
152
152
|
priority: AppPriority && AppPriority < priority ? AppPriority : priority,
|
|
153
153
|
reg: /./,
|
|
154
154
|
fncName,
|
|
@@ -316,10 +316,19 @@ export async function InstructionMatching(e) {
|
|
|
316
316
|
/**
|
|
317
317
|
* 对话机
|
|
318
318
|
*/
|
|
319
|
-
const
|
|
320
|
-
const
|
|
321
|
-
|
|
322
|
-
|
|
319
|
+
const guild_state = await getConversationState(e.guild_id);
|
|
320
|
+
const channel_state = await getConversationState(e.channel_id);
|
|
321
|
+
const user_state = await getConversationState(e.user_id);
|
|
322
|
+
if (guild_state || channel_state || user_state) {
|
|
323
|
+
const guild_handler = conversationHandlers.get(e.guild_id);
|
|
324
|
+
if (guild_handler)
|
|
325
|
+
await guild_handler(e, guild_state);
|
|
326
|
+
const channel_handler = conversationHandlers.get(e.channel_id);
|
|
327
|
+
if (channel_handler)
|
|
328
|
+
await channel_handler(e, channel_state);
|
|
329
|
+
const user_handler = conversationHandlers.get(e.user_id);
|
|
330
|
+
if (user_handler)
|
|
331
|
+
await user_handler(e, user_state);
|
|
323
332
|
return true;
|
|
324
333
|
}
|
|
325
334
|
let t = false;
|
|
@@ -428,7 +437,7 @@ export async function InstructionMatching(e) {
|
|
|
428
437
|
* 循环所有指令
|
|
429
438
|
*/
|
|
430
439
|
for (const data of Command[e.event]) {
|
|
431
|
-
if (e.
|
|
440
|
+
if (e.typing != data.typing ||
|
|
432
441
|
data.reg === undefined ||
|
|
433
442
|
!data.reg.test(e.msg)) {
|
|
434
443
|
continue;
|
|
@@ -502,7 +511,7 @@ export async function typeMessage(e) {
|
|
|
502
511
|
}
|
|
503
512
|
// 循环查找
|
|
504
513
|
for (const data of CommandNotMessage[e.event]) {
|
|
505
|
-
if (e.
|
|
514
|
+
if (e.typing != data.typing)
|
|
506
515
|
continue;
|
|
507
516
|
try {
|
|
508
517
|
const app = APPCACHE[data.APP];
|
package/lib/core/dialogue.js
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 注册对话处理器
|
|
3
|
+
* @deprecated Conversation.add
|
|
4
|
+
*/
|
|
5
|
+
export const conversationHandlers = new Map();
|
|
1
6
|
/**
|
|
2
7
|
*对话缓存
|
|
3
8
|
*/
|
|
@@ -26,31 +31,31 @@ const setAsync = async (key, val) => {
|
|
|
26
31
|
const delAsync = async (key) => {
|
|
27
32
|
delete Sockes[key];
|
|
28
33
|
};
|
|
29
|
-
/**
|
|
30
|
-
* 注册对话处理器
|
|
31
|
-
*/
|
|
32
|
-
export const conversationHandlers = new Map();
|
|
33
34
|
/**
|
|
34
35
|
* 获取对话状态
|
|
35
|
-
* @param
|
|
36
|
+
* @param ID 编号
|
|
36
37
|
* @returns 对话状态值
|
|
38
|
+
* @deprecated 不推荐使用
|
|
37
39
|
*/
|
|
38
|
-
export const getConversationState = async (
|
|
39
|
-
const state = await getAsync(`conversation-state:${
|
|
40
|
+
export const getConversationState = async (ID) => {
|
|
41
|
+
const state = await getAsync(`conversation-state:${ID}`);
|
|
40
42
|
return state ? JSON.parse(state) : null;
|
|
41
43
|
};
|
|
42
44
|
/**
|
|
43
45
|
* 设置对话状态
|
|
44
|
-
* @param
|
|
46
|
+
* @param ID 编号
|
|
45
47
|
* @param state 状态记录
|
|
48
|
+
* @deprecated Conversation.passing
|
|
46
49
|
*/
|
|
47
|
-
export const setConversationState = async (
|
|
48
|
-
await setAsync(`conversation-state:${
|
|
50
|
+
export const setConversationState = async (ID, state) => {
|
|
51
|
+
await setAsync(`conversation-state:${ID}`, JSON.stringify(state));
|
|
49
52
|
};
|
|
50
53
|
/**
|
|
51
54
|
* 删除对话状态
|
|
52
|
-
* @param
|
|
55
|
+
* @param ID 编号
|
|
56
|
+
* @deprecated Conversation.del
|
|
53
57
|
*/
|
|
54
|
-
export const deleteConversationState = async (
|
|
55
|
-
|
|
58
|
+
export const deleteConversationState = async (ID) => {
|
|
59
|
+
// 删除数据
|
|
60
|
+
await delAsync(`conversation-state:${ID}`);
|
|
56
61
|
};
|
package/lib/core/index.js
CHANGED
|
@@ -10,6 +10,7 @@ export * from './configs.js';
|
|
|
10
10
|
export * from './apps.js';
|
|
11
11
|
export * from './cache.js';
|
|
12
12
|
export * from './dialogue.js';
|
|
13
|
+
export * from './conversation.js';
|
|
13
14
|
export * from './qrcode.js';
|
|
14
15
|
export * from './dealmsg.js';
|
|
15
16
|
export * from './puppeteer.js';
|
package/lib/core/plugin.js
CHANGED
|
@@ -30,7 +30,7 @@ export class plugin {
|
|
|
30
30
|
/**
|
|
31
31
|
* 事件类型
|
|
32
32
|
*/
|
|
33
|
-
|
|
33
|
+
typing;
|
|
34
34
|
/**
|
|
35
35
|
* 匹配优先级
|
|
36
36
|
*/
|
|
@@ -46,7 +46,7 @@ export class plugin {
|
|
|
46
46
|
/**
|
|
47
47
|
* @param name 类名标记 default app-name
|
|
48
48
|
* @param event 事件类型 default MESSAGES
|
|
49
|
-
* @param
|
|
49
|
+
* @param typing 消息类型 default CREATE
|
|
50
50
|
* @param priority 优先级 越小优越高 default 9000
|
|
51
51
|
* @param rule.reg 命令正则 RegExp | string
|
|
52
52
|
* @param rule.fnc 命令函数 function
|
|
@@ -54,10 +54,10 @@ export class plugin {
|
|
|
54
54
|
* @param rule.doc 指令文档 doc
|
|
55
55
|
* @param rule.priority 优先级 数字越小优先级越高
|
|
56
56
|
*/
|
|
57
|
-
constructor({ name = 'app-name', event = 'message',
|
|
57
|
+
constructor({ name = 'app-name', event = 'message', typing = 'CREATE', priority = 9000, rule = [], task }) {
|
|
58
58
|
this.name = name;
|
|
59
59
|
this.event = event;
|
|
60
|
-
this.
|
|
60
|
+
this.typing = typing;
|
|
61
61
|
this.priority = priority;
|
|
62
62
|
this.rule = rule;
|
|
63
63
|
this.task = {
|
|
@@ -185,7 +185,7 @@ export class APlugin {
|
|
|
185
185
|
/**
|
|
186
186
|
* 事件类型
|
|
187
187
|
*/
|
|
188
|
-
|
|
188
|
+
typing;
|
|
189
189
|
/**
|
|
190
190
|
* 匹配优先级
|
|
191
191
|
*/
|
|
@@ -201,7 +201,7 @@ export class APlugin {
|
|
|
201
201
|
/**
|
|
202
202
|
* @param name 类名标记 default app-name
|
|
203
203
|
* @param event 事件类型 default MESSAGES
|
|
204
|
-
* @param
|
|
204
|
+
* @param typing 消息类型 default CREATE
|
|
205
205
|
* @param priority 优先级 越小优越高 default 9000
|
|
206
206
|
* @param rule.reg 命令正则 RegExp | string
|
|
207
207
|
* @param rule.fnc 命令函数 function
|
|
@@ -209,10 +209,10 @@ export class APlugin {
|
|
|
209
209
|
* @param rule.doc 指令文档 doc
|
|
210
210
|
* @param rule.priority 优先级 数字越小优先级越高
|
|
211
211
|
*/
|
|
212
|
-
constructor({ name = 'app-name', event = 'MESSAGES',
|
|
212
|
+
constructor({ name = 'app-name', event = 'MESSAGES', typing = 'CREATE', priority = 9000, rule = [], task }) {
|
|
213
213
|
this.name = name;
|
|
214
214
|
this.event = event;
|
|
215
|
-
this.
|
|
215
|
+
this.typing = typing;
|
|
216
216
|
this.priority = priority;
|
|
217
217
|
this.rule = rule;
|
|
218
218
|
this.task = {
|
package/lib/core/typings.js
CHANGED
|
@@ -36,7 +36,7 @@ export const AUDIO_ACTION = async (event) => {
|
|
|
36
36
|
const e = {
|
|
37
37
|
platform: 'qq',
|
|
38
38
|
event: 'AUDIO_MICROPHONE',
|
|
39
|
-
|
|
39
|
+
typing: 'CREATE',
|
|
40
40
|
boundaries: 'publick',
|
|
41
41
|
attribute: 'group',
|
|
42
42
|
bot: getBotMsgByQQ(),
|
|
@@ -90,7 +90,7 @@ export const AUDIO_ACTION = async (event) => {
|
|
|
90
90
|
if (new RegExp(/MIC$/).test(event.eventType)) {
|
|
91
91
|
if (!new RegExp(/ON_MIC$/).test(event.eventType)) {
|
|
92
92
|
// 下麦
|
|
93
|
-
e.
|
|
93
|
+
e.typing = 'DELETE';
|
|
94
94
|
}
|
|
95
95
|
}
|
|
96
96
|
else {
|
|
@@ -98,10 +98,10 @@ export const AUDIO_ACTION = async (event) => {
|
|
|
98
98
|
e.event = 'AUDIO_FREQUENCY';
|
|
99
99
|
if (!new RegExp(/^AUDIO_START$/).test(event.eventType)) {
|
|
100
100
|
// 音频播放结束时
|
|
101
|
-
e.
|
|
101
|
+
e.typing = 'DELETE';
|
|
102
102
|
}
|
|
103
103
|
}
|
|
104
104
|
return await typeMessage(e)
|
|
105
|
-
.then(() => AlemonJSEventLog(e.event, e.
|
|
106
|
-
.catch(err => AlemonJSEventError(err, e.event, e.
|
|
105
|
+
.then(() => AlemonJSEventLog(e.event, e.typing))
|
|
106
|
+
.catch(err => AlemonJSEventError(err, e.event, e.typing));
|
|
107
107
|
};
|
|
@@ -35,7 +35,7 @@ export const CHANNEL = async (event) => {
|
|
|
35
35
|
event: new RegExp(/^GUILD.*$/).test(event.eventType)
|
|
36
36
|
? 'GUILD'
|
|
37
37
|
: 'CHANNEL',
|
|
38
|
-
|
|
38
|
+
typing: new RegExp(/CREATE$/).test(event.eventType)
|
|
39
39
|
? 'CREATE'
|
|
40
40
|
: new RegExp(/UPDATE$/).test(event.eventType)
|
|
41
41
|
? 'UPDATE'
|
|
@@ -96,6 +96,6 @@ export const CHANNEL = async (event) => {
|
|
|
96
96
|
* 只匹配类型
|
|
97
97
|
*/
|
|
98
98
|
return await typeMessage(e)
|
|
99
|
-
.then(() => AlemonJSEventLog(e.event, e.
|
|
100
|
-
.catch(err => AlemonJSEventError(err, e.event, e.
|
|
99
|
+
.then(() => AlemonJSEventLog(e.event, e.typing))
|
|
100
|
+
.catch(err => AlemonJSEventError(err, e.event, e.typing));
|
|
101
101
|
};
|
|
@@ -28,7 +28,7 @@ export const DIRECT_MESSAGE = async (event) => {
|
|
|
28
28
|
const e = {
|
|
29
29
|
platform: 'qq',
|
|
30
30
|
event: 'MESSAGES',
|
|
31
|
-
|
|
31
|
+
typing: 'CREATE',
|
|
32
32
|
boundaries: 'publick',
|
|
33
33
|
attribute: 'single',
|
|
34
34
|
bot: getBotMsgByQQ(),
|
|
@@ -69,13 +69,13 @@ export const DIRECT_MESSAGE = async (event) => {
|
|
|
69
69
|
* 撤回事件
|
|
70
70
|
*/
|
|
71
71
|
if (new RegExp(/^DIRECT_MESSAGE_DELETE$/).test(event.eventType)) {
|
|
72
|
-
e.
|
|
72
|
+
e.typing = 'DELETE';
|
|
73
73
|
/**
|
|
74
74
|
* 只匹配类型
|
|
75
75
|
*/
|
|
76
76
|
return await typeMessage(e)
|
|
77
|
-
.then(() => AlemonJSEventLog(e.event, e.
|
|
78
|
-
.catch(err => AlemonJSEventError(err, e.event, e.
|
|
77
|
+
.then(() => AlemonJSEventLog(e.event, e.typing))
|
|
78
|
+
.catch(err => AlemonJSEventError(err, e.event, e.typing));
|
|
79
79
|
}
|
|
80
80
|
/**
|
|
81
81
|
* 业务处理
|
|
@@ -42,7 +42,7 @@ export const FORUMS_EVENT = async (event) => {
|
|
|
42
42
|
: new RegExp(/^FORUM_POST/).test(event.eventType)
|
|
43
43
|
? 'FORUMS_POST'
|
|
44
44
|
: 'FORUMS_REPLY',
|
|
45
|
-
|
|
45
|
+
typing: new RegExp(/CREATE$/).test(event.eventType)
|
|
46
46
|
? 'CREATE'
|
|
47
47
|
: new RegExp(/UPDATE$/).test(event.eventType)
|
|
48
48
|
? 'UPDATE'
|
|
@@ -100,6 +100,6 @@ export const FORUMS_EVENT = async (event) => {
|
|
|
100
100
|
Message
|
|
101
101
|
};
|
|
102
102
|
return await typeMessage(e)
|
|
103
|
-
.then(() => AlemonJSEventLog(e.event, e.
|
|
104
|
-
.catch(err => AlemonJSEventError(err, e.event, e.
|
|
103
|
+
.then(() => AlemonJSEventLog(e.event, e.typing))
|
|
104
|
+
.catch(err => AlemonJSEventError(err, e.event, e.typing));
|
|
105
105
|
};
|
|
@@ -35,7 +35,7 @@ export const GUILD = async (event) => {
|
|
|
35
35
|
event: new RegExp(/^GUILD.*$/).test(event.eventType)
|
|
36
36
|
? 'GUILD'
|
|
37
37
|
: 'CHANNEL',
|
|
38
|
-
|
|
38
|
+
typing: new RegExp(/CREATE$/).test(event.eventType)
|
|
39
39
|
? 'CREATE'
|
|
40
40
|
: new RegExp(/UPDATE$/).test(event.eventType)
|
|
41
41
|
? 'UPDATE'
|
|
@@ -96,6 +96,6 @@ export const GUILD = async (event) => {
|
|
|
96
96
|
* 只匹配类型
|
|
97
97
|
*/
|
|
98
98
|
return await typeMessage(e)
|
|
99
|
-
.then(() => AlemonJSEventLog(e.event, e.
|
|
100
|
-
.catch(err => AlemonJSEventError(err, e.event, e.
|
|
99
|
+
.then(() => AlemonJSEventLog(e.event, e.typing))
|
|
100
|
+
.catch(err => AlemonJSEventError(err, e.event, e.typing));
|
|
101
101
|
};
|
|
@@ -31,7 +31,7 @@ export const GUILD_MEMBERS = async (event) => {
|
|
|
31
31
|
const e = {
|
|
32
32
|
platform: 'qq',
|
|
33
33
|
event: 'GUILD_MEMBERS',
|
|
34
|
-
|
|
34
|
+
typing: new RegExp(/ADD$/).test(event.eventType)
|
|
35
35
|
? 'CREATE'
|
|
36
36
|
: new RegExp(/UPDATE$/).test(event.eventType)
|
|
37
37
|
? 'UPDATE'
|
|
@@ -91,6 +91,6 @@ export const GUILD_MEMBERS = async (event) => {
|
|
|
91
91
|
Message
|
|
92
92
|
};
|
|
93
93
|
return await typeMessage(e)
|
|
94
|
-
.then(() => AlemonJSEventLog(e.event, e.
|
|
95
|
-
.catch(err => AlemonJSEventError(err, e.event, e.
|
|
94
|
+
.then(() => AlemonJSEventLog(e.event, e.typing))
|
|
95
|
+
.catch(err => AlemonJSEventError(err, e.event, e.typing));
|
|
96
96
|
};
|
|
@@ -39,7 +39,7 @@ export const GUILD_MESSAGES = async (event) => {
|
|
|
39
39
|
const e = {
|
|
40
40
|
platform: 'qq',
|
|
41
41
|
event: 'MESSAGES',
|
|
42
|
-
|
|
42
|
+
typing: 'CREATE',
|
|
43
43
|
boundaries: 'private',
|
|
44
44
|
attribute: 'group',
|
|
45
45
|
bot: getBotMsgByQQ(),
|
|
@@ -92,10 +92,10 @@ export const GUILD_MESSAGES = async (event) => {
|
|
|
92
92
|
* 撤回消息
|
|
93
93
|
*/
|
|
94
94
|
if (new RegExp(/DELETE$/).test(event.eventType)) {
|
|
95
|
-
e.
|
|
95
|
+
e.typing = 'DELETE';
|
|
96
96
|
return await typeMessage(e)
|
|
97
|
-
.then(() => AlemonJSEventLog(e.event, e.
|
|
98
|
-
.catch(err => AlemonJSEventError(err, e.event, e.
|
|
97
|
+
.then(() => AlemonJSEventLog(e.event, e.typing))
|
|
98
|
+
.catch(err => AlemonJSEventError(err, e.event, e.typing));
|
|
99
99
|
}
|
|
100
100
|
// 屏蔽其他机器人的消息
|
|
101
101
|
if (event.msg.author.bot)
|
|
@@ -30,7 +30,7 @@ export const GUILD_MESSAGE_REACTIONS = async (event) => {
|
|
|
30
30
|
const e = {
|
|
31
31
|
platform: 'qq',
|
|
32
32
|
event: 'GUILD_MESSAGE_REACTIONS',
|
|
33
|
-
|
|
33
|
+
typing: new RegExp(/ADD$/).test(event.eventType)
|
|
34
34
|
? 'CREATE'
|
|
35
35
|
: 'DELETE',
|
|
36
36
|
boundaries: 'publick',
|
|
@@ -95,6 +95,6 @@ export const GUILD_MESSAGE_REACTIONS = async (event) => {
|
|
|
95
95
|
* 只匹配类型
|
|
96
96
|
*/
|
|
97
97
|
return await typeMessage(e)
|
|
98
|
-
.then(() => AlemonJSEventLog(e.event, e.
|
|
99
|
-
.catch(err => AlemonJSEventError(err, e.event, e.
|
|
98
|
+
.then(() => AlemonJSEventLog(e.event, e.typing))
|
|
99
|
+
.catch(err => AlemonJSEventError(err, e.event, e.typing));
|
|
100
100
|
};
|
|
@@ -29,7 +29,7 @@ export const INTERACTION = async (event) => {
|
|
|
29
29
|
const e = {
|
|
30
30
|
platform: 'qq',
|
|
31
31
|
event: 'INTERACTION',
|
|
32
|
-
|
|
32
|
+
typing: 'CREATE',
|
|
33
33
|
boundaries: 'publick',
|
|
34
34
|
attribute: 'group',
|
|
35
35
|
bot: getBotMsgByQQ(),
|
|
@@ -84,9 +84,9 @@ export const INTERACTION = async (event) => {
|
|
|
84
84
|
* 事件匹配
|
|
85
85
|
*/
|
|
86
86
|
if (!new RegExp(/CREATE$/).test(event.eventType)) {
|
|
87
|
-
e.
|
|
87
|
+
e.typing = 'DELETE';
|
|
88
88
|
}
|
|
89
89
|
return await typeMessage(e)
|
|
90
|
-
.then(() => AlemonJSEventLog(e.event, e.
|
|
91
|
-
.catch(err => AlemonJSEventError(err, e.event, e.
|
|
90
|
+
.then(() => AlemonJSEventLog(e.event, e.typing))
|
|
91
|
+
.catch(err => AlemonJSEventError(err, e.event, e.typing));
|
|
92
92
|
};
|
|
@@ -30,7 +30,7 @@ export const MESSAGE_AUDIT = async (event) => {
|
|
|
30
30
|
const e = {
|
|
31
31
|
platform: 'qq',
|
|
32
32
|
event: 'MESSAGE_AUDIT',
|
|
33
|
-
|
|
33
|
+
typing: 'CREATE',
|
|
34
34
|
boundaries: 'publick',
|
|
35
35
|
attribute: 'group',
|
|
36
36
|
bot: getBotMsgByQQ(),
|
|
@@ -84,12 +84,12 @@ export const MESSAGE_AUDIT = async (event) => {
|
|
|
84
84
|
*/
|
|
85
85
|
e.event = 'MESSAGE_AUDIT';
|
|
86
86
|
if (new RegExp(/REJECT$/).test(event.eventType)) {
|
|
87
|
-
e.
|
|
87
|
+
e.typing = 'DELETE';
|
|
88
88
|
}
|
|
89
89
|
/**
|
|
90
90
|
* 只匹配类型
|
|
91
91
|
*/
|
|
92
92
|
return await typeMessage(e)
|
|
93
|
-
.then(() => AlemonJSEventLog(e.event, e.
|
|
94
|
-
.catch(err => AlemonJSEventError(err, e.event, e.
|
|
93
|
+
.then(() => AlemonJSEventLog(e.event, e.typing))
|
|
94
|
+
.catch(err => AlemonJSEventError(err, e.event, e.typing));
|
|
95
95
|
};
|
|
@@ -41,7 +41,7 @@ export const OPEN_FORUMS_EVENT = async (event) => {
|
|
|
41
41
|
const e = {
|
|
42
42
|
platform: 'qq',
|
|
43
43
|
event: 'FORUMS_THREAD',
|
|
44
|
-
|
|
44
|
+
typing: 'CREATE',
|
|
45
45
|
boundaries: 'publick',
|
|
46
46
|
attribute: 'group',
|
|
47
47
|
bot: getBotMsgByQQ(),
|
|
@@ -110,15 +110,15 @@ export const OPEN_FORUMS_EVENT = async (event) => {
|
|
|
110
110
|
* 类型匹配
|
|
111
111
|
*/
|
|
112
112
|
if (new RegExp(/CREATE$/).test(event.eventType)) {
|
|
113
|
-
e.
|
|
113
|
+
e.typing = 'CREATE';
|
|
114
114
|
}
|
|
115
115
|
else if (new RegExp(/UPDATE$/).test(event.eventType)) {
|
|
116
|
-
e.
|
|
116
|
+
e.typing = 'UPDATE';
|
|
117
117
|
}
|
|
118
118
|
else {
|
|
119
|
-
e.
|
|
119
|
+
e.typing = 'DELETE';
|
|
120
120
|
}
|
|
121
121
|
return await typeMessage(e)
|
|
122
|
-
.then(() => AlemonJSEventLog(e.event, e.
|
|
123
|
-
.catch(err => AlemonJSEventError(err, e.event, e.
|
|
122
|
+
.then(() => AlemonJSEventLog(e.event, e.typing))
|
|
123
|
+
.catch(err => AlemonJSEventError(err, e.event, e.typing));
|
|
124
124
|
};
|
|
@@ -38,7 +38,7 @@ export const PUBLIC_GUILD_MESSAGES = async (event) => {
|
|
|
38
38
|
const e = {
|
|
39
39
|
platform: 'qq',
|
|
40
40
|
event: 'MESSAGES',
|
|
41
|
-
|
|
41
|
+
typing: 'CREATE',
|
|
42
42
|
boundaries: 'publick',
|
|
43
43
|
attribute: 'group',
|
|
44
44
|
bot: getBotMsgByQQ(),
|
|
@@ -93,10 +93,10 @@ export const PUBLIC_GUILD_MESSAGES = async (event) => {
|
|
|
93
93
|
* 消息撤回
|
|
94
94
|
*/
|
|
95
95
|
if (new RegExp(/DELETE$/).test(event.eventType)) {
|
|
96
|
-
e.
|
|
96
|
+
e.typing = 'DELETE';
|
|
97
97
|
return await typeMessage(e)
|
|
98
|
-
.then(() => AlemonJSEventLog(e.event, e.
|
|
99
|
-
.catch(err => AlemonJSEventError(err, e.event, e.
|
|
98
|
+
.then(() => AlemonJSEventLog(e.event, e.typing))
|
|
99
|
+
.catch(err => AlemonJSEventError(err, e.event, e.typing));
|
|
100
100
|
}
|
|
101
101
|
// 屏蔽其他机器人的消息
|
|
102
102
|
if (event.msg.author.bot)
|
|
@@ -29,7 +29,7 @@ export async function GUILD_BOT(event) {
|
|
|
29
29
|
const e = {
|
|
30
30
|
platform: 'villa',
|
|
31
31
|
event: 'GUILD_BOT',
|
|
32
|
-
|
|
32
|
+
typing: event.type == 3 ? 'CREATE' : 'DELETE',
|
|
33
33
|
boundaries: 'publick',
|
|
34
34
|
attribute: 'group',
|
|
35
35
|
bot: {
|
|
@@ -86,6 +86,6 @@ export async function GUILD_BOT(event) {
|
|
|
86
86
|
* 只匹配类型
|
|
87
87
|
*/
|
|
88
88
|
return await typeMessage(e)
|
|
89
|
-
.then(() => AlemonJSEventLog(e.event, e.
|
|
90
|
-
.catch(err => AlemonJSEventError(err, e.event, e.
|
|
89
|
+
.then(() => AlemonJSEventLog(e.event, e.typing))
|
|
90
|
+
.catch(err => AlemonJSEventError(err, e.event, e.typing));
|
|
91
91
|
}
|
|
@@ -30,7 +30,7 @@ export async function GUILD_MEMBERS(event) {
|
|
|
30
30
|
const e = {
|
|
31
31
|
platform: 'villa',
|
|
32
32
|
event: 'GUILD_MEMBERS',
|
|
33
|
-
|
|
33
|
+
typing: 'CREATE',
|
|
34
34
|
boundaries: 'publick',
|
|
35
35
|
attribute: 'group',
|
|
36
36
|
bot: {
|
|
@@ -92,6 +92,6 @@ export async function GUILD_MEMBERS(event) {
|
|
|
92
92
|
* 只匹配类型
|
|
93
93
|
*/
|
|
94
94
|
return await typeMessage(e)
|
|
95
|
-
.then(() => AlemonJSEventLog(e.event, e.
|
|
96
|
-
.catch(err => AlemonJSEventError(err, e.event, e.
|
|
95
|
+
.then(() => AlemonJSEventLog(e.event, e.typing))
|
|
96
|
+
.catch(err => AlemonJSEventError(err, e.event, e.typing));
|
|
97
97
|
}
|
|
@@ -30,7 +30,7 @@ export async function GUILD_MESSAGE_REACTIONS(event) {
|
|
|
30
30
|
const e = {
|
|
31
31
|
platform: 'villa',
|
|
32
32
|
event: 'GUILD_MESSAGE_REACTIONS',
|
|
33
|
-
|
|
33
|
+
typing: event.extendData.addQuickEmoticon.isCancel
|
|
34
34
|
? 'DELETE'
|
|
35
35
|
: 'CREATE',
|
|
36
36
|
boundaries: 'publick',
|
|
@@ -94,6 +94,6 @@ export async function GUILD_MESSAGE_REACTIONS(event) {
|
|
|
94
94
|
* 只匹配类型
|
|
95
95
|
*/
|
|
96
96
|
return await typeMessage(e)
|
|
97
|
-
.then(() => AlemonJSEventLog(e.event, e.
|
|
98
|
-
.catch(err => AlemonJSEventError(err, e.event, e.
|
|
97
|
+
.then(() => AlemonJSEventLog(e.event, e.typing))
|
|
98
|
+
.catch(err => AlemonJSEventError(err, e.event, e.typing));
|
|
99
99
|
}
|
|
@@ -30,7 +30,7 @@ export async function MESSAGE_AUDIT(event) {
|
|
|
30
30
|
const e = {
|
|
31
31
|
platform: 'villa',
|
|
32
32
|
event: 'MESSAGE_AUDIT',
|
|
33
|
-
|
|
33
|
+
typing: 'CREATE',
|
|
34
34
|
boundaries: 'publick',
|
|
35
35
|
attribute: 'group',
|
|
36
36
|
bot: {
|
|
@@ -85,6 +85,6 @@ export async function MESSAGE_AUDIT(event) {
|
|
|
85
85
|
* 只匹配类型
|
|
86
86
|
*/
|
|
87
87
|
return await typeMessage(e)
|
|
88
|
-
.then(() => AlemonJSEventLog(e.event, e.
|
|
89
|
-
.catch(err => AlemonJSEventError(err, e.event, e.
|
|
88
|
+
.then(() => AlemonJSEventLog(e.event, e.typing))
|
|
89
|
+
.catch(err => AlemonJSEventError(err, e.event, e.typing));
|
|
90
90
|
}
|
package/package.json
CHANGED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 对话机
|
|
3
|
+
*/
|
|
4
|
+
export declare const Conversation: {
|
|
5
|
+
/**
|
|
6
|
+
* 设置对话状态
|
|
7
|
+
* @param ID 用户编号
|
|
8
|
+
* @param state 状态记录
|
|
9
|
+
*/
|
|
10
|
+
passing: (ID: string, state: import("./dialogue.js").ConversationState) => Promise<void>;
|
|
11
|
+
/**
|
|
12
|
+
* 删除对话状态
|
|
13
|
+
* @param ID 用户编号
|
|
14
|
+
*/
|
|
15
|
+
remove: (ID: string) => void;
|
|
16
|
+
/**
|
|
17
|
+
* 注册对话
|
|
18
|
+
*/
|
|
19
|
+
add: (key: string, value: import("./dialogue.js").ConversationHandler) => import("./dialogue.js").conversationHandlersMap;
|
|
20
|
+
};
|
package/types/core/dialogue.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AMessage } from './typings.js';
|
|
2
2
|
/**
|
|
3
3
|
* 对话处理函数集
|
|
4
4
|
*/
|
|
@@ -32,22 +32,26 @@ export type ConversationHandler = (e: AMessage, state: ConversationState) => Pro
|
|
|
32
32
|
export type conversationHandlersMap = Map<string, ConversationHandler>;
|
|
33
33
|
/**
|
|
34
34
|
* 注册对话处理器
|
|
35
|
+
* @deprecated Conversation.add
|
|
35
36
|
*/
|
|
36
37
|
export declare const conversationHandlers: conversationHandlersMap;
|
|
37
38
|
/**
|
|
38
39
|
* 获取对话状态
|
|
39
|
-
* @param
|
|
40
|
+
* @param ID 编号
|
|
40
41
|
* @returns 对话状态值
|
|
42
|
+
* @deprecated 不推荐使用
|
|
41
43
|
*/
|
|
42
|
-
export declare const getConversationState: (
|
|
44
|
+
export declare const getConversationState: (ID: string) => Promise<ConversationState | null>;
|
|
43
45
|
/**
|
|
44
46
|
* 设置对话状态
|
|
45
|
-
* @param
|
|
47
|
+
* @param ID 编号
|
|
46
48
|
* @param state 状态记录
|
|
49
|
+
* @deprecated Conversation.passing
|
|
47
50
|
*/
|
|
48
|
-
export declare const setConversationState: (
|
|
51
|
+
export declare const setConversationState: (ID: string, state: ConversationState) => Promise<void>;
|
|
49
52
|
/**
|
|
50
53
|
* 删除对话状态
|
|
51
|
-
* @param
|
|
54
|
+
* @param ID 编号
|
|
55
|
+
* @deprecated Conversation.del
|
|
52
56
|
*/
|
|
53
|
-
export declare const deleteConversationState: (
|
|
57
|
+
export declare const deleteConversationState: (ID: string) => Promise<void>;
|
package/types/core/index.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ export * from './configs.js';
|
|
|
10
10
|
export * from './apps.js';
|
|
11
11
|
export * from './cache.js';
|
|
12
12
|
export * from './dialogue.js';
|
|
13
|
+
export * from './conversation.js';
|
|
13
14
|
export * from './qrcode.js';
|
|
14
15
|
export * from './dealmsg.js';
|
|
15
16
|
export * from './puppeteer.js';
|
package/types/core/plugin.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
-
import { type AMessage, type EventEnum, type
|
|
2
|
+
import { type AMessage, type EventEnum, type TypingEnum } from './typings.js';
|
|
3
3
|
/**
|
|
4
4
|
* 定时类型
|
|
5
5
|
*/
|
|
@@ -14,7 +14,7 @@ interface TaskType {
|
|
|
14
14
|
*/
|
|
15
15
|
export interface PluginInitType {
|
|
16
16
|
event?: (typeof EventEnum)[number];
|
|
17
|
-
|
|
17
|
+
typing?: (typeof TypingEnum)[number];
|
|
18
18
|
priority?: number;
|
|
19
19
|
name?: string;
|
|
20
20
|
dsc?: string;
|
|
@@ -73,7 +73,7 @@ export declare class plugin {
|
|
|
73
73
|
/**
|
|
74
74
|
* 事件类型
|
|
75
75
|
*/
|
|
76
|
-
|
|
76
|
+
typing?: (typeof TypingEnum)[number];
|
|
77
77
|
/**
|
|
78
78
|
* 匹配优先级
|
|
79
79
|
*/
|
|
@@ -89,7 +89,7 @@ export declare class plugin {
|
|
|
89
89
|
/**
|
|
90
90
|
* @param name 类名标记 default app-name
|
|
91
91
|
* @param event 事件类型 default MESSAGES
|
|
92
|
-
* @param
|
|
92
|
+
* @param typing 消息类型 default CREATE
|
|
93
93
|
* @param priority 优先级 越小优越高 default 9000
|
|
94
94
|
* @param rule.reg 命令正则 RegExp | string
|
|
95
95
|
* @param rule.fnc 命令函数 function
|
|
@@ -97,7 +97,7 @@ export declare class plugin {
|
|
|
97
97
|
* @param rule.doc 指令文档 doc
|
|
98
98
|
* @param rule.priority 优先级 数字越小优先级越高
|
|
99
99
|
*/
|
|
100
|
-
constructor({ name, event,
|
|
100
|
+
constructor({ name, event, typing, priority, rule, task }: PluginInitType);
|
|
101
101
|
/**
|
|
102
102
|
* @param content 内容
|
|
103
103
|
* @param img 图片buffer | 指定图片名
|
|
@@ -163,7 +163,7 @@ export declare class APlugin {
|
|
|
163
163
|
/**
|
|
164
164
|
* 事件类型
|
|
165
165
|
*/
|
|
166
|
-
|
|
166
|
+
typing?: (typeof TypingEnum)[number];
|
|
167
167
|
/**
|
|
168
168
|
* 匹配优先级
|
|
169
169
|
*/
|
|
@@ -179,7 +179,7 @@ export declare class APlugin {
|
|
|
179
179
|
/**
|
|
180
180
|
* @param name 类名标记 default app-name
|
|
181
181
|
* @param event 事件类型 default MESSAGES
|
|
182
|
-
* @param
|
|
182
|
+
* @param typing 消息类型 default CREATE
|
|
183
183
|
* @param priority 优先级 越小优越高 default 9000
|
|
184
184
|
* @param rule.reg 命令正则 RegExp | string
|
|
185
185
|
* @param rule.fnc 命令函数 function
|
|
@@ -187,7 +187,7 @@ export declare class APlugin {
|
|
|
187
187
|
* @param rule.doc 指令文档 doc
|
|
188
188
|
* @param rule.priority 优先级 数字越小优先级越高
|
|
189
189
|
*/
|
|
190
|
-
constructor({ name, event,
|
|
190
|
+
constructor({ name, event, typing, priority, rule, task }: PluginInitType);
|
|
191
191
|
/**
|
|
192
192
|
* @param content 内容
|
|
193
193
|
* @param img 图片buffer | 指定图片名
|
package/types/core/typings.d.ts
CHANGED
|
@@ -19,7 +19,7 @@ interface EventBase {
|
|
|
19
19
|
/**
|
|
20
20
|
* 消息类型
|
|
21
21
|
*/
|
|
22
|
-
|
|
22
|
+
typing: (typeof TypingEnum)[number];
|
|
23
23
|
}
|
|
24
24
|
/**
|
|
25
25
|
* 平台枚举
|
|
@@ -32,7 +32,7 @@ export declare const EventEnum: readonly ["GUILD", "GUILD_BOT", "CHANNEL", "GUIL
|
|
|
32
32
|
/**
|
|
33
33
|
* 消息判断
|
|
34
34
|
*/
|
|
35
|
-
export declare const
|
|
35
|
+
export declare const TypingEnum: readonly ["CREATE", "UPDATE", "DELETE"];
|
|
36
36
|
/**
|
|
37
37
|
* 机器人相关
|
|
38
38
|
*/
|