alemonjs 1.1.21 → 1.1.23
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/apps.js +19 -1
- package/lib/core/cache.js +29 -0
- package/lib/core/configs.js +5 -0
- package/lib/core/dealmsg.js +8 -3
- package/lib/core/index.js +0 -1
- package/lib/core/main.js +1 -0
- package/package.json +1 -1
- package/types/core/apps.d.ts +14 -0
- package/types/core/cache.d.ts +22 -0
- package/types/core/configs.d.ts +2 -0
- package/types/core/index.d.ts +0 -1
- package/types/core/main.d.ts +1 -0
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 { setAppMessage, setAppArg, setAppCharacter, setAppEvent, setAppPriority } from './cache.js';
|
|
3
|
+
import { setAppMessage, setAppArg, setAppCharacter, setAppEvent, setAppPriority, setAppSlicing } from './cache.js';
|
|
4
4
|
import { setApp } from './app.js';
|
|
5
5
|
import { setAllCall } from './call.js';
|
|
6
6
|
/**
|
|
@@ -259,6 +259,24 @@ export function createApp(url) {
|
|
|
259
259
|
}
|
|
260
260
|
return app;
|
|
261
261
|
},
|
|
262
|
+
/**
|
|
263
|
+
* 消息字符串切割
|
|
264
|
+
* @param str
|
|
265
|
+
* @param reg
|
|
266
|
+
* @returns
|
|
267
|
+
*/
|
|
268
|
+
replace: (reg, str) => {
|
|
269
|
+
try {
|
|
270
|
+
setAppSlicing(AppName, {
|
|
271
|
+
str,
|
|
272
|
+
reg
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
catch (err) {
|
|
276
|
+
console.error('APP on', err);
|
|
277
|
+
}
|
|
278
|
+
return app;
|
|
279
|
+
},
|
|
262
280
|
/**
|
|
263
281
|
* 挂起应用
|
|
264
282
|
* @returns
|
package/lib/core/cache.js
CHANGED
|
@@ -120,3 +120,32 @@ export function setAppPriority(key, val) {
|
|
|
120
120
|
export function delAppPriority(key) {
|
|
121
121
|
delete PRIORITY[key];
|
|
122
122
|
}
|
|
123
|
+
const SLICING = {};
|
|
124
|
+
/**
|
|
125
|
+
* 得到插件默认正则
|
|
126
|
+
* @param key 插件名
|
|
127
|
+
* @returns
|
|
128
|
+
*/
|
|
129
|
+
export function getAppSlicing(key) {
|
|
130
|
+
return SLICING[key];
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* @param key 插件名
|
|
134
|
+
* @param val 规则
|
|
135
|
+
*/
|
|
136
|
+
export function setAppSlicing(key, val) {
|
|
137
|
+
if (!Object.prototype.isPrototypeOf.call(SLICING, key))
|
|
138
|
+
SLICING[key] = [];
|
|
139
|
+
// 重复存在的丢掉
|
|
140
|
+
const find = SLICING[key].find(item => `${item.reg}` == `${val.reg}` && item.str == val.str);
|
|
141
|
+
if (find)
|
|
142
|
+
return;
|
|
143
|
+
SLICING[key].push(val);
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* 删除插件默认正则
|
|
147
|
+
* @param key 插件名
|
|
148
|
+
*/
|
|
149
|
+
export function delAppSlicing(key) {
|
|
150
|
+
delete SLICING[key];
|
|
151
|
+
}
|
package/lib/core/configs.js
CHANGED
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 } from 'fs';
|
|
4
4
|
import lodash from 'lodash';
|
|
5
|
-
import { getAppArg, getAppEvent, getAppCharacter, getAppMessage, getAppPriority } from './cache.js';
|
|
5
|
+
import { getAppArg, getAppEvent, getAppCharacter, getAppMessage, getAppPriority, getAppSlicing } 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';
|
|
@@ -57,9 +57,8 @@ function createPluginHelp() {
|
|
|
57
57
|
*/
|
|
58
58
|
async function synthesis(AppName, AppsObj) {
|
|
59
59
|
// 没有记载
|
|
60
|
-
if (!plugins[AppName])
|
|
60
|
+
if (!plugins[AppName])
|
|
61
61
|
plugins[AppName] = [];
|
|
62
|
-
}
|
|
63
62
|
const shield = getAppProCoinfg('event');
|
|
64
63
|
for (const item in AppsObj) {
|
|
65
64
|
const keys = new AppsObj[item]();
|
|
@@ -382,6 +381,12 @@ export async function InstructionMatching(e) {
|
|
|
382
381
|
const character = getAppCharacter(name);
|
|
383
382
|
const __character = getAppProCoinfg('defaultCharacter');
|
|
384
383
|
e.msg = e.msg.replace(_character, character ?? __character);
|
|
384
|
+
const arr = getAppSlicing(name);
|
|
385
|
+
if (arr && Array.isArray(arr) && arr.length != 0) {
|
|
386
|
+
for (const item of arr) {
|
|
387
|
+
e.msg = e.msg.replace(item.reg, item.str);
|
|
388
|
+
}
|
|
389
|
+
}
|
|
385
390
|
}
|
|
386
391
|
try {
|
|
387
392
|
if (typeof AppFnc == 'function')
|
package/lib/core/index.js
CHANGED
|
@@ -10,7 +10,6 @@ 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';
|
|
14
13
|
export * from './qrcode.js';
|
|
15
14
|
export * from './dealmsg.js';
|
|
16
15
|
export * from './puppeteer.js';
|
package/lib/core/main.js
CHANGED
package/package.json
CHANGED
package/types/core/apps.d.ts
CHANGED
|
@@ -82,6 +82,13 @@ export declare function createApps(url: string): {
|
|
|
82
82
|
* @param priority 优先级
|
|
83
83
|
*/
|
|
84
84
|
on: (event: "message" | "GUILD_MEMBERS" | "GUILD_MESSAGE_REACTIONS" | "MESSAGE_AUDIT" | "INTERACTION" | "GUILD" | "GUILD_BOT" | "CHANNEL" | "FORUMS_THREAD" | "FORUMS_POST" | "FORUMS_REPLY" | "MESSAGES" | "MESSAGE_BUTTON" | "AUDIO_FREQUENCY" | "AUDIO_MICROPHONE", call: (e: AMessage) => any, priority?: number) => any;
|
|
85
|
+
/**
|
|
86
|
+
* 消息字符串切割
|
|
87
|
+
* @param str
|
|
88
|
+
* @param reg
|
|
89
|
+
* @returns
|
|
90
|
+
*/
|
|
91
|
+
replace: (reg: RegExp, str: string) => any;
|
|
85
92
|
/**
|
|
86
93
|
* 挂起应用
|
|
87
94
|
* @returns
|
|
@@ -149,6 +156,13 @@ export declare function createApp(url: string): {
|
|
|
149
156
|
* @param priority 优先级
|
|
150
157
|
*/
|
|
151
158
|
on: (event: (typeof EventEnum)[number], call: (e: AMessage) => any, priority?: number) => any;
|
|
159
|
+
/**
|
|
160
|
+
* 消息字符串切割
|
|
161
|
+
* @param str
|
|
162
|
+
* @param reg
|
|
163
|
+
* @returns
|
|
164
|
+
*/
|
|
165
|
+
replace: (reg: RegExp, str: string) => any;
|
|
152
166
|
/**
|
|
153
167
|
* 挂起应用
|
|
154
168
|
* @returns
|
package/types/core/cache.d.ts
CHANGED
|
@@ -83,3 +83,25 @@ export declare function setAppPriority(key: string, val: number): void;
|
|
|
83
83
|
* @param key 插件名
|
|
84
84
|
*/
|
|
85
85
|
export declare function delAppPriority(key: string): void;
|
|
86
|
+
/**
|
|
87
|
+
* 得到插件默认正则
|
|
88
|
+
* @param key 插件名
|
|
89
|
+
* @returns
|
|
90
|
+
*/
|
|
91
|
+
export declare function getAppSlicing(key: string): {
|
|
92
|
+
str: string;
|
|
93
|
+
reg: RegExp;
|
|
94
|
+
}[];
|
|
95
|
+
/**
|
|
96
|
+
* @param key 插件名
|
|
97
|
+
* @param val 规则
|
|
98
|
+
*/
|
|
99
|
+
export declare function setAppSlicing(key: string, val: {
|
|
100
|
+
str: string;
|
|
101
|
+
reg: RegExp;
|
|
102
|
+
}): void;
|
|
103
|
+
/**
|
|
104
|
+
* 删除插件默认正则
|
|
105
|
+
* @param key 插件名
|
|
106
|
+
*/
|
|
107
|
+
export declare function delAppSlicing(key: string): void;
|
package/types/core/configs.d.ts
CHANGED
package/types/core/index.d.ts
CHANGED
|
@@ -10,7 +10,6 @@ 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';
|
|
14
13
|
export * from './qrcode.js';
|
|
15
14
|
export * from './dealmsg.js';
|
|
16
15
|
export * from './puppeteer.js';
|
package/types/core/main.d.ts
CHANGED