node-karin 0.0.3 → 0.1.0
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/LICENSE +674 -674
- package/README.md +57 -57
- package/config/defSet/App.yaml +37 -37
- package/config/defSet/config.yaml +43 -43
- package/config/defSet/group.yaml +18 -18
- package/config/defSet/pm2.yaml +21 -21
- package/config/defSet/server.yaml +42 -42
- package/config/view/App.yaml +74 -74
- package/config/view/config.yaml +100 -100
- package/config/view/group.yaml +62 -62
- package/config/view/pm2.yaml +41 -41
- package/config/view/redis.yaml +25 -25
- package/config/view/server.yaml +93 -93
- package/lib/adapter/onebot/onebot11.d.ts +430 -430
- package/lib/adapter/onebot/onebot11.js +1265 -1302
- package/lib/core/init.js +4 -4
- package/lib/core/karin.d.ts +72 -72
- package/lib/core/karin.js +51 -51
- package/lib/core/listener.d.ts +121 -121
- package/lib/core/listener.js +178 -178
- package/lib/core/plugin.app.d.ts +15 -15
- package/lib/core/plugin.app.js +18 -18
- package/lib/core/plugin.d.ts +182 -182
- package/lib/core/plugin.js +132 -132
- package/lib/core/plugin.loader.d.ts +149 -149
- package/lib/core/plugin.loader.js +451 -451
- package/lib/core/server.d.ts +26 -26
- package/lib/core/server.js +209 -209
- package/lib/db/level.d.ts +20 -20
- package/lib/db/level.js +36 -36
- package/lib/db/redis.d.ts +41 -41
- package/lib/db/redis.js +131 -131
- package/lib/db/redis_level.d.ts +113 -113
- package/lib/db/redis_level.js +274 -274
- package/lib/event/event.d.ts +138 -138
- package/lib/event/event.handler.d.ts +29 -29
- package/lib/event/event.handler.js +138 -138
- package/lib/event/event.js +120 -120
- package/lib/event/message.d.ts +102 -102
- package/lib/event/message.handler.d.ts +25 -25
- package/lib/event/message.handler.js +237 -237
- package/lib/event/message.js +69 -69
- package/lib/event/notice.d.ts +49 -49
- package/lib/event/notice.js +14 -14
- package/lib/event/request.d.ts +49 -49
- package/lib/event/request.js +14 -14
- package/lib/event/review.handler.d.ts +54 -54
- package/lib/event/review.handler.js +374 -374
- package/lib/index.d.ts +23 -23
- package/lib/index.js +39 -40
- package/lib/renderer/app.d.ts +53 -53
- package/lib/renderer/app.js +88 -88
- package/lib/renderer/base.d.ts +30 -30
- package/lib/renderer/base.js +68 -68
- package/lib/renderer/client.d.ts +30 -30
- package/lib/renderer/client.js +155 -155
- package/lib/renderer/http.d.ts +19 -19
- package/lib/renderer/http.js +50 -50
- package/lib/renderer/server.d.ts +42 -42
- package/lib/renderer/server.js +110 -110
- package/lib/renderer/wormhole.d.ts +1 -1
- package/lib/renderer/wormhole.js +154 -154
- package/lib/types/adapter.d.ts +575 -575
- package/lib/types/adapter.js +1 -1
- package/lib/types/config.d.ts +327 -327
- package/lib/types/config.js +1 -1
- package/lib/types/element.d.ts +576 -576
- package/lib/types/element.js +1 -1
- package/lib/types/index.d.ts +8 -8
- package/lib/types/index.js +8 -8
- package/lib/types/logger.d.ts +109 -109
- package/lib/types/logger.js +1 -1
- package/lib/types/onebots11.d.ts +1371 -1371
- package/lib/types/onebots11.js +1 -1
- package/lib/types/plugin.d.ts +282 -282
- package/lib/types/plugin.js +1 -1
- package/lib/types/render.d.ts +111 -111
- package/lib/types/render.js +1 -1
- package/lib/types/reply.d.ts +40 -40
- package/lib/types/reply.js +1 -1
- package/lib/types/types.d.ts +898 -898
- package/lib/types/types.js +1 -1
- package/lib/utils/YamlEditor.d.ts +62 -62
- package/lib/utils/YamlEditor.js +197 -197
- package/lib/utils/button.d.ts +49 -49
- package/lib/utils/button.js +75 -75
- package/lib/utils/common.d.ts +123 -123
- package/lib/utils/common.js +396 -396
- package/lib/utils/config.d.ts +72 -72
- package/lib/utils/config.js +254 -254
- package/lib/utils/exec.d.ts +22 -22
- package/lib/utils/exec.js +36 -36
- package/lib/utils/ffmpeg.d.ts +12 -12
- package/lib/utils/ffmpeg.js +25 -25
- package/lib/utils/handler.d.ts +76 -76
- package/lib/utils/handler.js +98 -98
- package/lib/utils/logger.d.ts +3 -3
- package/lib/utils/logger.js +104 -104
- package/lib/utils/segment.d.ts +276 -276
- package/lib/utils/segment.js +420 -420
- package/lib/utils/update.d.ts +69 -69
- package/lib/utils/update.js +145 -145
- package/lib/utils/updateVersion.d.ts +33 -33
- package/lib/utils/updateVersion.js +140 -140
- package/package.json +92 -91
package/lib/core/plugin.d.ts
CHANGED
|
@@ -1,182 +1,182 @@
|
|
|
1
|
-
import { Plugin as PluginType } from '../types/plugin.js';
|
|
2
|
-
import { KarinElement, KarinNodeElement } from '../types/element.js';
|
|
3
|
-
import { E } from '../types/types.js';
|
|
4
|
-
/**
|
|
5
|
-
* 插件基类
|
|
6
|
-
*/
|
|
7
|
-
export default class Plugin implements PluginType {
|
|
8
|
-
e: PluginType['e'];
|
|
9
|
-
init?: () => void;
|
|
10
|
-
accept?: (e: E) => Promise<void>;
|
|
11
|
-
replyCallback: PluginType['replyCallback'];
|
|
12
|
-
/**
|
|
13
|
-
* @param name - 插件名称
|
|
14
|
-
*/
|
|
15
|
-
name: PluginType['name'];
|
|
16
|
-
/**
|
|
17
|
-
* @param dsc - 插件描述
|
|
18
|
-
* @deprecated 请使用desc
|
|
19
|
-
*/
|
|
20
|
-
dsc: PluginType['dsc'];
|
|
21
|
-
/**
|
|
22
|
-
* @param desc - 插件描述
|
|
23
|
-
*/
|
|
24
|
-
desc: PluginType['desc'];
|
|
25
|
-
/**
|
|
26
|
-
* @param event - 监听事件
|
|
27
|
-
*/
|
|
28
|
-
event: PluginType['event'];
|
|
29
|
-
/**
|
|
30
|
-
* @param priority - 优先级 默认5000
|
|
31
|
-
*/
|
|
32
|
-
priority: PluginType['priority'];
|
|
33
|
-
/**
|
|
34
|
-
* @param task - 定时任务
|
|
35
|
-
*/
|
|
36
|
-
task: PluginType['task'];
|
|
37
|
-
/**
|
|
38
|
-
* @param rule - 命令规则
|
|
39
|
-
*/
|
|
40
|
-
rule: PluginType['rule'];
|
|
41
|
-
/**
|
|
42
|
-
* @param button - 按钮
|
|
43
|
-
*/
|
|
44
|
-
button: PluginType['button'];
|
|
45
|
-
/**
|
|
46
|
-
* @param handler - handler
|
|
47
|
-
*/
|
|
48
|
-
handler: PluginType['handler'];
|
|
49
|
-
/**
|
|
50
|
-
* @param userId - 用户ID 一般上下文使用
|
|
51
|
-
*/
|
|
52
|
-
userId?: PluginType['userId'];
|
|
53
|
-
/**
|
|
54
|
-
* @param timeout - 上下文超时
|
|
55
|
-
*/
|
|
56
|
-
timeout: PluginType['timeout'];
|
|
57
|
-
constructor({ name, dsc, desc, event, priority, task, rule, handler, button, }: {
|
|
58
|
-
/**
|
|
59
|
-
* - 插件名称
|
|
60
|
-
*/
|
|
61
|
-
name: string;
|
|
62
|
-
/**
|
|
63
|
-
* - 插件描述 没有则默认为名称
|
|
64
|
-
*/
|
|
65
|
-
dsc: string;
|
|
66
|
-
/**
|
|
67
|
-
* - 插件描述 没有则默认为插件名称
|
|
68
|
-
*/
|
|
69
|
-
desc?: string;
|
|
70
|
-
/**
|
|
71
|
-
* - 监听事件 默认为message
|
|
72
|
-
*/
|
|
73
|
-
event?: PluginType['event'];
|
|
74
|
-
/**
|
|
75
|
-
* - 优先级 默认为5000
|
|
76
|
-
*/
|
|
77
|
-
priority?: PluginType['priority'];
|
|
78
|
-
/**
|
|
79
|
-
* - 定时任务
|
|
80
|
-
*/
|
|
81
|
-
task?: PluginType['task'];
|
|
82
|
-
/**
|
|
83
|
-
* - 命令规则
|
|
84
|
-
*/
|
|
85
|
-
rule?: PluginType['rule'];
|
|
86
|
-
/**
|
|
87
|
-
* - handler
|
|
88
|
-
*/
|
|
89
|
-
handler?: PluginType['handler'];
|
|
90
|
-
/**
|
|
91
|
-
* - 按钮
|
|
92
|
-
*/
|
|
93
|
-
button?: PluginType['button'];
|
|
94
|
-
});
|
|
95
|
-
/**
|
|
96
|
-
* - 快速回复
|
|
97
|
-
*/
|
|
98
|
-
reply(msg?: string | KarinElement | Array<KarinElement | string>, options?: {
|
|
99
|
-
/**
|
|
100
|
-
* @param at - 是否at用户
|
|
101
|
-
* @default false
|
|
102
|
-
*/
|
|
103
|
-
at?: boolean;
|
|
104
|
-
/**
|
|
105
|
-
* @param reply - 是否引用回复
|
|
106
|
-
* @default false
|
|
107
|
-
*/
|
|
108
|
-
reply?: boolean;
|
|
109
|
-
/**
|
|
110
|
-
* @param recallMsg - 群聊是否撤回消息,0-120秒,0不撤回
|
|
111
|
-
* @default 0
|
|
112
|
-
*/
|
|
113
|
-
recallMsg?: number;
|
|
114
|
-
/**
|
|
115
|
-
* @param button - 是否使用按钮
|
|
116
|
-
* @default false
|
|
117
|
-
*/
|
|
118
|
-
button?: boolean;
|
|
119
|
-
/**
|
|
120
|
-
* @param retry_count - 重试次数
|
|
121
|
-
* @default 1
|
|
122
|
-
*/
|
|
123
|
-
retry_count?: number;
|
|
124
|
-
}): Promise<{
|
|
125
|
-
/**
|
|
126
|
-
* @param message_id - 消息发送成功返回的消息ID
|
|
127
|
-
*/
|
|
128
|
-
message_id?: string;
|
|
129
|
-
}>;
|
|
130
|
-
/**
|
|
131
|
-
* - 快速回复合并转发
|
|
132
|
-
*/
|
|
133
|
-
replyForward(msg: KarinNodeElement[]): Promise<{
|
|
134
|
-
message_id?: string;
|
|
135
|
-
}>;
|
|
136
|
-
/**
|
|
137
|
-
* - 构建上下文键
|
|
138
|
-
*/
|
|
139
|
-
conKey(): string;
|
|
140
|
-
/**
|
|
141
|
-
* 设置上下文状态
|
|
142
|
-
*/
|
|
143
|
-
setContext(
|
|
144
|
-
/**
|
|
145
|
-
* @param fnc - 执行方法
|
|
146
|
-
*/
|
|
147
|
-
fnc: string,
|
|
148
|
-
/**
|
|
149
|
-
* @param reply - 超时后是否回复
|
|
150
|
-
*/
|
|
151
|
-
reply?: boolean,
|
|
152
|
-
/**
|
|
153
|
-
* @param time - 超时时间,默认120秒
|
|
154
|
-
*/
|
|
155
|
-
time?: number): void;
|
|
156
|
-
/**
|
|
157
|
-
* 获取上下文状态
|
|
158
|
-
*/
|
|
159
|
-
getContext(): {
|
|
160
|
-
plugin: Plugin;
|
|
161
|
-
fnc: string;
|
|
162
|
-
};
|
|
163
|
-
/**
|
|
164
|
-
* 清除上下文状态
|
|
165
|
-
*/
|
|
166
|
-
finish(): void;
|
|
167
|
-
}
|
|
168
|
-
/**
|
|
169
|
-
* 上下文状态
|
|
170
|
-
*/
|
|
171
|
-
export declare const stateArr: {
|
|
172
|
-
[key: string]: {
|
|
173
|
-
/**
|
|
174
|
-
* @param plugin - 插件实例
|
|
175
|
-
*/
|
|
176
|
-
plugin: Plugin;
|
|
177
|
-
/**
|
|
178
|
-
* @param fnc - 执行方法名称
|
|
179
|
-
*/
|
|
180
|
-
fnc: string;
|
|
181
|
-
};
|
|
182
|
-
};
|
|
1
|
+
import { Plugin as PluginType } from '../types/plugin.js';
|
|
2
|
+
import { KarinElement, KarinNodeElement } from '../types/element.js';
|
|
3
|
+
import { E } from '../types/types.js';
|
|
4
|
+
/**
|
|
5
|
+
* 插件基类
|
|
6
|
+
*/
|
|
7
|
+
export default class Plugin implements PluginType {
|
|
8
|
+
e: PluginType['e'];
|
|
9
|
+
init?: () => void;
|
|
10
|
+
accept?: (e: E) => Promise<void>;
|
|
11
|
+
replyCallback: PluginType['replyCallback'];
|
|
12
|
+
/**
|
|
13
|
+
* @param name - 插件名称
|
|
14
|
+
*/
|
|
15
|
+
name: PluginType['name'];
|
|
16
|
+
/**
|
|
17
|
+
* @param dsc - 插件描述
|
|
18
|
+
* @deprecated 请使用desc
|
|
19
|
+
*/
|
|
20
|
+
dsc: PluginType['dsc'];
|
|
21
|
+
/**
|
|
22
|
+
* @param desc - 插件描述
|
|
23
|
+
*/
|
|
24
|
+
desc: PluginType['desc'];
|
|
25
|
+
/**
|
|
26
|
+
* @param event - 监听事件
|
|
27
|
+
*/
|
|
28
|
+
event: PluginType['event'];
|
|
29
|
+
/**
|
|
30
|
+
* @param priority - 优先级 默认5000
|
|
31
|
+
*/
|
|
32
|
+
priority: PluginType['priority'];
|
|
33
|
+
/**
|
|
34
|
+
* @param task - 定时任务
|
|
35
|
+
*/
|
|
36
|
+
task: PluginType['task'];
|
|
37
|
+
/**
|
|
38
|
+
* @param rule - 命令规则
|
|
39
|
+
*/
|
|
40
|
+
rule: PluginType['rule'];
|
|
41
|
+
/**
|
|
42
|
+
* @param button - 按钮
|
|
43
|
+
*/
|
|
44
|
+
button: PluginType['button'];
|
|
45
|
+
/**
|
|
46
|
+
* @param handler - handler
|
|
47
|
+
*/
|
|
48
|
+
handler: PluginType['handler'];
|
|
49
|
+
/**
|
|
50
|
+
* @param userId - 用户ID 一般上下文使用
|
|
51
|
+
*/
|
|
52
|
+
userId?: PluginType['userId'];
|
|
53
|
+
/**
|
|
54
|
+
* @param timeout - 上下文超时
|
|
55
|
+
*/
|
|
56
|
+
timeout: PluginType['timeout'];
|
|
57
|
+
constructor({ name, dsc, desc, event, priority, task, rule, handler, button, }: {
|
|
58
|
+
/**
|
|
59
|
+
* - 插件名称
|
|
60
|
+
*/
|
|
61
|
+
name: string;
|
|
62
|
+
/**
|
|
63
|
+
* - 插件描述 没有则默认为名称
|
|
64
|
+
*/
|
|
65
|
+
dsc: string;
|
|
66
|
+
/**
|
|
67
|
+
* - 插件描述 没有则默认为插件名称
|
|
68
|
+
*/
|
|
69
|
+
desc?: string;
|
|
70
|
+
/**
|
|
71
|
+
* - 监听事件 默认为message
|
|
72
|
+
*/
|
|
73
|
+
event?: PluginType['event'];
|
|
74
|
+
/**
|
|
75
|
+
* - 优先级 默认为5000
|
|
76
|
+
*/
|
|
77
|
+
priority?: PluginType['priority'];
|
|
78
|
+
/**
|
|
79
|
+
* - 定时任务
|
|
80
|
+
*/
|
|
81
|
+
task?: PluginType['task'];
|
|
82
|
+
/**
|
|
83
|
+
* - 命令规则
|
|
84
|
+
*/
|
|
85
|
+
rule?: PluginType['rule'];
|
|
86
|
+
/**
|
|
87
|
+
* - handler
|
|
88
|
+
*/
|
|
89
|
+
handler?: PluginType['handler'];
|
|
90
|
+
/**
|
|
91
|
+
* - 按钮
|
|
92
|
+
*/
|
|
93
|
+
button?: PluginType['button'];
|
|
94
|
+
});
|
|
95
|
+
/**
|
|
96
|
+
* - 快速回复
|
|
97
|
+
*/
|
|
98
|
+
reply(msg?: string | KarinElement | Array<KarinElement | string>, options?: {
|
|
99
|
+
/**
|
|
100
|
+
* @param at - 是否at用户
|
|
101
|
+
* @default false
|
|
102
|
+
*/
|
|
103
|
+
at?: boolean;
|
|
104
|
+
/**
|
|
105
|
+
* @param reply - 是否引用回复
|
|
106
|
+
* @default false
|
|
107
|
+
*/
|
|
108
|
+
reply?: boolean;
|
|
109
|
+
/**
|
|
110
|
+
* @param recallMsg - 群聊是否撤回消息,0-120秒,0不撤回
|
|
111
|
+
* @default 0
|
|
112
|
+
*/
|
|
113
|
+
recallMsg?: number;
|
|
114
|
+
/**
|
|
115
|
+
* @param button - 是否使用按钮
|
|
116
|
+
* @default false
|
|
117
|
+
*/
|
|
118
|
+
button?: boolean;
|
|
119
|
+
/**
|
|
120
|
+
* @param retry_count - 重试次数
|
|
121
|
+
* @default 1
|
|
122
|
+
*/
|
|
123
|
+
retry_count?: number;
|
|
124
|
+
}): Promise<{
|
|
125
|
+
/**
|
|
126
|
+
* @param message_id - 消息发送成功返回的消息ID
|
|
127
|
+
*/
|
|
128
|
+
message_id?: string;
|
|
129
|
+
}>;
|
|
130
|
+
/**
|
|
131
|
+
* - 快速回复合并转发
|
|
132
|
+
*/
|
|
133
|
+
replyForward(msg: KarinNodeElement[]): Promise<{
|
|
134
|
+
message_id?: string;
|
|
135
|
+
}>;
|
|
136
|
+
/**
|
|
137
|
+
* - 构建上下文键
|
|
138
|
+
*/
|
|
139
|
+
conKey(): string;
|
|
140
|
+
/**
|
|
141
|
+
* 设置上下文状态
|
|
142
|
+
*/
|
|
143
|
+
setContext(
|
|
144
|
+
/**
|
|
145
|
+
* @param fnc - 执行方法
|
|
146
|
+
*/
|
|
147
|
+
fnc: string,
|
|
148
|
+
/**
|
|
149
|
+
* @param reply - 超时后是否回复
|
|
150
|
+
*/
|
|
151
|
+
reply?: boolean,
|
|
152
|
+
/**
|
|
153
|
+
* @param time - 超时时间,默认120秒
|
|
154
|
+
*/
|
|
155
|
+
time?: number): void;
|
|
156
|
+
/**
|
|
157
|
+
* 获取上下文状态
|
|
158
|
+
*/
|
|
159
|
+
getContext(): {
|
|
160
|
+
plugin: Plugin;
|
|
161
|
+
fnc: string;
|
|
162
|
+
};
|
|
163
|
+
/**
|
|
164
|
+
* 清除上下文状态
|
|
165
|
+
*/
|
|
166
|
+
finish(): void;
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* 上下文状态
|
|
170
|
+
*/
|
|
171
|
+
export declare const stateArr: {
|
|
172
|
+
[key: string]: {
|
|
173
|
+
/**
|
|
174
|
+
* @param plugin - 插件实例
|
|
175
|
+
*/
|
|
176
|
+
plugin: Plugin;
|
|
177
|
+
/**
|
|
178
|
+
* @param fnc - 执行方法名称
|
|
179
|
+
*/
|
|
180
|
+
fnc: string;
|
|
181
|
+
};
|
|
182
|
+
};
|
package/lib/core/plugin.js
CHANGED
|
@@ -1,138 +1,138 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 插件基类
|
|
3
|
-
*/
|
|
4
|
-
export default class Plugin {
|
|
5
|
-
e
|
|
6
|
-
init
|
|
7
|
-
accept
|
|
8
|
-
replyCallback
|
|
9
|
-
/**
|
|
10
|
-
* @param name - 插件名称
|
|
11
|
-
*/
|
|
12
|
-
name
|
|
13
|
-
/**
|
|
14
|
-
* @param dsc - 插件描述
|
|
15
|
-
* @deprecated 请使用desc
|
|
16
|
-
*/
|
|
17
|
-
dsc
|
|
18
|
-
/**
|
|
19
|
-
* @param desc - 插件描述
|
|
20
|
-
*/
|
|
21
|
-
desc
|
|
22
|
-
/**
|
|
23
|
-
* @param event - 监听事件
|
|
24
|
-
*/
|
|
25
|
-
event
|
|
26
|
-
/**
|
|
27
|
-
* @param priority - 优先级 默认5000
|
|
28
|
-
*/
|
|
29
|
-
priority
|
|
30
|
-
/**
|
|
31
|
-
* @param task - 定时任务
|
|
32
|
-
*/
|
|
33
|
-
task
|
|
34
|
-
/**
|
|
35
|
-
* @param rule - 命令规则
|
|
36
|
-
*/
|
|
37
|
-
rule
|
|
38
|
-
/**
|
|
39
|
-
* @param button - 按钮
|
|
40
|
-
*/
|
|
41
|
-
button
|
|
42
|
-
/**
|
|
43
|
-
* @param handler - handler
|
|
44
|
-
*/
|
|
45
|
-
handler
|
|
46
|
-
/**
|
|
47
|
-
* @param userId - 用户ID 一般上下文使用
|
|
48
|
-
*/
|
|
49
|
-
userId
|
|
50
|
-
/**
|
|
51
|
-
* @param timeout - 上下文超时
|
|
52
|
-
*/
|
|
53
|
-
timeout
|
|
54
|
-
constructor ({ name, dsc = name, desc = name, event = 'message', priority = 5000, task = [], rule = [], handler = [], button = [] }) {
|
|
55
|
-
this.name = name
|
|
56
|
-
this.dsc = dsc
|
|
57
|
-
this.desc = desc
|
|
58
|
-
this.event = event
|
|
59
|
-
this.priority = priority
|
|
60
|
-
this.task = task
|
|
61
|
-
this.rule = rule
|
|
62
|
-
this.button = button
|
|
63
|
-
this.handler = handler
|
|
1
|
+
/**
|
|
2
|
+
* 插件基类
|
|
3
|
+
*/
|
|
4
|
+
export default class Plugin {
|
|
5
|
+
e
|
|
6
|
+
init
|
|
7
|
+
accept
|
|
8
|
+
replyCallback
|
|
9
|
+
/**
|
|
10
|
+
* @param name - 插件名称
|
|
11
|
+
*/
|
|
12
|
+
name
|
|
13
|
+
/**
|
|
14
|
+
* @param dsc - 插件描述
|
|
15
|
+
* @deprecated 请使用desc
|
|
16
|
+
*/
|
|
17
|
+
dsc
|
|
18
|
+
/**
|
|
19
|
+
* @param desc - 插件描述
|
|
20
|
+
*/
|
|
21
|
+
desc
|
|
22
|
+
/**
|
|
23
|
+
* @param event - 监听事件
|
|
24
|
+
*/
|
|
25
|
+
event
|
|
26
|
+
/**
|
|
27
|
+
* @param priority - 优先级 默认5000
|
|
28
|
+
*/
|
|
29
|
+
priority
|
|
30
|
+
/**
|
|
31
|
+
* @param task - 定时任务
|
|
32
|
+
*/
|
|
33
|
+
task
|
|
34
|
+
/**
|
|
35
|
+
* @param rule - 命令规则
|
|
36
|
+
*/
|
|
37
|
+
rule
|
|
38
|
+
/**
|
|
39
|
+
* @param button - 按钮
|
|
40
|
+
*/
|
|
41
|
+
button
|
|
42
|
+
/**
|
|
43
|
+
* @param handler - handler
|
|
44
|
+
*/
|
|
45
|
+
handler
|
|
46
|
+
/**
|
|
47
|
+
* @param userId - 用户ID 一般上下文使用
|
|
48
|
+
*/
|
|
49
|
+
userId
|
|
50
|
+
/**
|
|
51
|
+
* @param timeout - 上下文超时
|
|
52
|
+
*/
|
|
53
|
+
timeout
|
|
54
|
+
constructor ({ name, dsc = name, desc = name, event = 'message', priority = 5000, task = [], rule = [], handler = [], button = [] }) {
|
|
55
|
+
this.name = name
|
|
56
|
+
this.dsc = dsc
|
|
57
|
+
this.desc = desc
|
|
58
|
+
this.event = event
|
|
59
|
+
this.priority = priority
|
|
60
|
+
this.task = task
|
|
61
|
+
this.rule = rule
|
|
62
|
+
this.button = button
|
|
63
|
+
this.handler = handler
|
|
64
64
|
}
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* - 快速回复
|
|
68
|
-
*/
|
|
69
|
-
reply (msg = '', options = { reply: false, recallMsg: 0, at: false, button: false, retry_count: 1 }) {
|
|
70
|
-
return this.e.reply(msg, options)
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* - 快速回复
|
|
68
|
+
*/
|
|
69
|
+
reply (msg = '', options = { reply: false, recallMsg: 0, at: false, button: false, retry_count: 1 }) {
|
|
70
|
+
return this.e.reply(msg, options)
|
|
71
71
|
}
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* - 快速回复合并转发
|
|
75
|
-
*/
|
|
76
|
-
async replyForward (msg) {
|
|
77
|
-
const result = await this.e.bot.sendForwardMessage(this.e.contact, msg)
|
|
78
|
-
return result
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* - 快速回复合并转发
|
|
75
|
+
*/
|
|
76
|
+
async replyForward (msg) {
|
|
77
|
+
const result = await this.e.bot.sendForwardMessage(this.e.contact, msg)
|
|
78
|
+
return result
|
|
79
79
|
}
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* - 构建上下文键
|
|
83
|
-
*/
|
|
84
|
-
conKey () {
|
|
85
|
-
return `${this.e.isGroup ? `${this.e.group_id}.` : ''}` + (this.userId || this.e.user_id)
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* - 构建上下文键
|
|
83
|
+
*/
|
|
84
|
+
conKey () {
|
|
85
|
+
return `${this.e.isGroup ? `${this.e.group_id}.` : ''}` + (this.userId || this.e.user_id)
|
|
86
86
|
}
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* 设置上下文状态
|
|
90
|
-
*/
|
|
91
|
-
setContext (
|
|
92
|
-
/**
|
|
93
|
-
* @param fnc - 执行方法
|
|
94
|
-
*/
|
|
95
|
-
fnc,
|
|
96
|
-
/**
|
|
97
|
-
* @param reply - 超时后是否回复
|
|
98
|
-
*/
|
|
99
|
-
reply = true,
|
|
100
|
-
/**
|
|
101
|
-
* @param time - 超时时间,默认120秒
|
|
102
|
-
*/
|
|
103
|
-
time = 120) {
|
|
104
|
-
const key = this.conKey()
|
|
105
|
-
stateArr[key] = { plugin: this, fnc }
|
|
106
|
-
/** 操作时间 */
|
|
107
|
-
this.timeout = setTimeout(() => {
|
|
108
|
-
if (stateArr[key]) {
|
|
109
|
-
delete stateArr[key]
|
|
110
|
-
if (reply) { this.e.reply('操作超时已取消', { at: true }) }
|
|
111
|
-
}
|
|
112
|
-
}, time * 1000)
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* 设置上下文状态
|
|
90
|
+
*/
|
|
91
|
+
setContext (
|
|
92
|
+
/**
|
|
93
|
+
* @param fnc - 执行方法
|
|
94
|
+
*/
|
|
95
|
+
fnc,
|
|
96
|
+
/**
|
|
97
|
+
* @param reply - 超时后是否回复
|
|
98
|
+
*/
|
|
99
|
+
reply = true,
|
|
100
|
+
/**
|
|
101
|
+
* @param time - 超时时间,默认120秒
|
|
102
|
+
*/
|
|
103
|
+
time = 120) {
|
|
104
|
+
const key = this.conKey()
|
|
105
|
+
stateArr[key] = { plugin: this, fnc }
|
|
106
|
+
/** 操作时间 */
|
|
107
|
+
this.timeout = setTimeout(() => {
|
|
108
|
+
if (stateArr[key]) {
|
|
109
|
+
delete stateArr[key]
|
|
110
|
+
if (reply) { this.e.reply('操作超时已取消', { at: true }) }
|
|
111
|
+
}
|
|
112
|
+
}, time * 1000)
|
|
113
113
|
}
|
|
114
|
-
|
|
115
|
-
/**
|
|
116
|
-
* 获取上下文状态
|
|
117
|
-
*/
|
|
118
|
-
getContext () {
|
|
119
|
-
const key = this.conKey()
|
|
120
|
-
return stateArr[key]
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* 获取上下文状态
|
|
117
|
+
*/
|
|
118
|
+
getContext () {
|
|
119
|
+
const key = this.conKey()
|
|
120
|
+
return stateArr[key]
|
|
121
121
|
}
|
|
122
|
-
|
|
123
|
-
/**
|
|
124
|
-
* 清除上下文状态
|
|
125
|
-
*/
|
|
126
|
-
finish () {
|
|
127
|
-
const key = this.conKey()
|
|
128
|
-
if (stateArr[key] && stateArr[key]) {
|
|
129
|
-
/** 清除定时器 */
|
|
130
|
-
clearTimeout(this.timeout)
|
|
131
|
-
delete stateArr[key]
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
/**
|
|
136
|
-
* 上下文状态
|
|
137
|
-
*/
|
|
138
|
-
export const stateArr = {}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* 清除上下文状态
|
|
125
|
+
*/
|
|
126
|
+
finish () {
|
|
127
|
+
const key = this.conKey()
|
|
128
|
+
if (stateArr[key] && stateArr[key]) {
|
|
129
|
+
/** 清除定时器 */
|
|
130
|
+
clearTimeout(this.timeout)
|
|
131
|
+
delete stateArr[key]
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* 上下文状态
|
|
137
|
+
*/
|
|
138
|
+
export const stateArr = {}
|