alemonjs 1.0.49 → 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/core/dealmsg.js +2 -1
- package/lib/core/plugin.js +155 -0
- package/package.json +1 -1
- package/types/core/plugin.d.ts +90 -0
package/lib/core/dealmsg.js
CHANGED
|
@@ -314,7 +314,8 @@ export async function InstructionMatching(e) {
|
|
|
314
314
|
const _character = getAppProCoinfg('character');
|
|
315
315
|
if (_character.test(e.msg)) {
|
|
316
316
|
const character = getAppCharacter(name);
|
|
317
|
-
|
|
317
|
+
const __character = getAppProCoinfg('defaultCharacter');
|
|
318
|
+
e.msg = e.msg.replace(_character, character ?? __character);
|
|
318
319
|
}
|
|
319
320
|
try {
|
|
320
321
|
if (typeof AppFnc == 'function')
|
package/lib/core/plugin.js
CHANGED
|
@@ -11,6 +11,161 @@ const timeoutCache = {};
|
|
|
11
11
|
* @class
|
|
12
12
|
*/
|
|
13
13
|
export class plugin {
|
|
14
|
+
/**
|
|
15
|
+
* this.e 方法
|
|
16
|
+
*/
|
|
17
|
+
e;
|
|
18
|
+
/**
|
|
19
|
+
* 模块名
|
|
20
|
+
*/
|
|
21
|
+
name;
|
|
22
|
+
/**
|
|
23
|
+
* 模块说明
|
|
24
|
+
*/
|
|
25
|
+
dsc;
|
|
26
|
+
/**
|
|
27
|
+
* 事件枚举
|
|
28
|
+
*/
|
|
29
|
+
event;
|
|
30
|
+
/**
|
|
31
|
+
* 事件类型
|
|
32
|
+
*/
|
|
33
|
+
eventType;
|
|
34
|
+
/**
|
|
35
|
+
* 匹配优先级
|
|
36
|
+
*/
|
|
37
|
+
priority;
|
|
38
|
+
/**
|
|
39
|
+
* 匹配集
|
|
40
|
+
*/
|
|
41
|
+
rule;
|
|
42
|
+
/**
|
|
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 {
|
|
14
169
|
/**
|
|
15
170
|
* this.e 方法
|
|
16
171
|
*/
|
package/package.json
CHANGED
package/types/core/plugin.d.ts
CHANGED
|
@@ -139,4 +139,94 @@ export declare class plugin {
|
|
|
139
139
|
*/
|
|
140
140
|
finish(type: string, isGroup?: boolean): void;
|
|
141
141
|
}
|
|
142
|
+
/**
|
|
143
|
+
* 插件基础类
|
|
144
|
+
* @class
|
|
145
|
+
*/
|
|
146
|
+
export declare class APlugin {
|
|
147
|
+
/**
|
|
148
|
+
* this.e 方法
|
|
149
|
+
*/
|
|
150
|
+
e: AMessage;
|
|
151
|
+
/**
|
|
152
|
+
* 模块名
|
|
153
|
+
*/
|
|
154
|
+
name?: string;
|
|
155
|
+
/**
|
|
156
|
+
* 模块说明
|
|
157
|
+
*/
|
|
158
|
+
dsc?: string;
|
|
159
|
+
/**
|
|
160
|
+
* 事件枚举
|
|
161
|
+
*/
|
|
162
|
+
event?: (typeof EventEnum)[number];
|
|
163
|
+
/**
|
|
164
|
+
* 事件类型
|
|
165
|
+
*/
|
|
166
|
+
eventType?: (typeof EventType)[number];
|
|
167
|
+
/**
|
|
168
|
+
* 匹配优先级
|
|
169
|
+
*/
|
|
170
|
+
priority?: number;
|
|
171
|
+
/**
|
|
172
|
+
* 匹配集
|
|
173
|
+
*/
|
|
174
|
+
rule?: PluginRuleType[];
|
|
175
|
+
/**
|
|
176
|
+
* @deprecated 已废弃,建议使用原生模块 node-schedule
|
|
177
|
+
*/
|
|
178
|
+
task?: TaskType;
|
|
179
|
+
/**
|
|
180
|
+
* @param name 类名标记 default app-name
|
|
181
|
+
* @param event 事件类型 default MESSAGES
|
|
182
|
+
* @param eventType 消息类型 default CREATE
|
|
183
|
+
* @param priority 优先级 越小优越高 default 9000
|
|
184
|
+
* @param rule.reg 命令正则 RegExp | string
|
|
185
|
+
* @param rule.fnc 命令函数 function
|
|
186
|
+
* @param rule.dsc 指令示范 sdc
|
|
187
|
+
* @param rule.doc 指令文档 doc
|
|
188
|
+
* @param rule.priority 优先级 数字越小优先级越高
|
|
189
|
+
*/
|
|
190
|
+
constructor({ name, event, eventType, priority, rule, task }: PluginInitType);
|
|
191
|
+
/**
|
|
192
|
+
* @param content 内容
|
|
193
|
+
* @param img 图片buffer | 指定图片名
|
|
194
|
+
* @param name 指定图片名
|
|
195
|
+
* @returns 是否处理完成
|
|
196
|
+
*/
|
|
197
|
+
reply(content: Buffer | string | number | (Buffer | number | string)[], select?: {
|
|
198
|
+
quote?: string;
|
|
199
|
+
withdraw?: number;
|
|
200
|
+
}): Promise<any>;
|
|
201
|
+
/**
|
|
202
|
+
* 得到缓存的key
|
|
203
|
+
* @param isGroup
|
|
204
|
+
* @returns key
|
|
205
|
+
*/
|
|
206
|
+
conKey(isGroup?: boolean): string;
|
|
207
|
+
/**
|
|
208
|
+
* 设置上下文
|
|
209
|
+
* @param type 执行方法
|
|
210
|
+
* @param isGroup 是否群聊
|
|
211
|
+
* @param time 操作时间,默认120秒
|
|
212
|
+
*/
|
|
213
|
+
setContext(type: string, isGroup?: boolean, time?: number): void;
|
|
214
|
+
/**
|
|
215
|
+
*
|
|
216
|
+
* 得到用户缓存消息对象
|
|
217
|
+
* @returns message
|
|
218
|
+
*/
|
|
219
|
+
getContext(): any;
|
|
220
|
+
/**
|
|
221
|
+
* 得到频道缓存消息对象
|
|
222
|
+
* @returns message
|
|
223
|
+
*/
|
|
224
|
+
getContextGroup(): any;
|
|
225
|
+
/**
|
|
226
|
+
* 完成上下文
|
|
227
|
+
* @param type 执行方法
|
|
228
|
+
* @param isGroup 是否公信
|
|
229
|
+
*/
|
|
230
|
+
finish(type: string, isGroup?: boolean): void;
|
|
231
|
+
}
|
|
142
232
|
export {};
|