alemonjs 2.1.63 → 2.1.65
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/app/index.js +1 -1
- package/lib/app/message-format.d.ts +1 -12
- package/lib/app/message-format.js +1 -49
- package/lib/index.js +1 -1
- package/lib/types/message/index.d.ts +1 -3
- package/lib/types/message/modal.d.ts +1 -21
- package/lib/utils.d.ts +6 -0
- package/lib/utils.js +111 -1
- package/package.json +2 -1
package/lib/app/index.js
CHANGED
|
@@ -38,5 +38,5 @@ export { getCurrentEvent, getCurrentNext, withEventContext } from './hook-event-
|
|
|
38
38
|
export { registerAppDir, scheduleCancel, scheduleCancelAll, scheduleCancelByApp, scheduleCron, scheduleInterval, scheduleList, schedulePause, scheduleResume, scheduleTimeout, unregisterAppDir } from './schedule-store.js';
|
|
39
39
|
export { createEventValue, createSelects, onSelects, onState, unChildren, unState, useState } from './event-utils.js';
|
|
40
40
|
export { MessageDirect, createDataFormat, format, getMessageIntent, sendToChannel, sendToUser } from './message-api.js';
|
|
41
|
-
export { Format, FormatButtonGroup, FormatMarkDown,
|
|
41
|
+
export { Format, FormatButtonGroup, FormatMarkDown, FormatSelect } from './message-format.js';
|
|
42
42
|
export { Attachment, Audio, BT, Button, Image, ImageFile, ImageURL, Link, MD, Markdown, MarkdownOriginal, Mention, Text, Video } from './message-format-old.js';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DataMention, DataText, DataImageURL, DataImageFile, DataButtonRow, DataButtonGroup, DataButton, DataMarkDown, DataLink, DataMarkdownCode, DataAttachment, DataMarkdownMention, DataMarkdownButton, DataEnums, DataSelect, DataSelectOption,
|
|
1
|
+
import { DataMention, DataText, DataImageURL, DataImageFile, DataButtonRow, DataButtonGroup, DataButton, DataMarkDown, DataLink, DataMarkdownCode, DataAttachment, DataMarkdownMention, DataMarkdownButton, DataEnums, DataSelect, DataSelectOption, DataEmbed } from '../types';
|
|
2
2
|
export * from './message-format-old.js';
|
|
3
3
|
export declare class FormatButtonGroup {
|
|
4
4
|
#private;
|
|
@@ -46,21 +46,12 @@ export declare class FormatSelect {
|
|
|
46
46
|
addOption(label: string, value: string, extra?: Omit<DataSelectOption, 'label' | 'value'>): this;
|
|
47
47
|
clear(): this;
|
|
48
48
|
}
|
|
49
|
-
export declare class FormatModal {
|
|
50
|
-
#private;
|
|
51
|
-
get value(): DataModal;
|
|
52
|
-
setCustomId(customId: string): this;
|
|
53
|
-
setTitle(title: string): this;
|
|
54
|
-
addInput(label: string, options: DataTextInput['options']): this;
|
|
55
|
-
clear(): this;
|
|
56
|
-
}
|
|
57
49
|
export declare class Format {
|
|
58
50
|
#private;
|
|
59
51
|
static create(): Format;
|
|
60
52
|
static createMarkdown(): FormatMarkDown;
|
|
61
53
|
static createButtonGroup(): FormatButtonGroup;
|
|
62
54
|
static createSelect(): FormatSelect;
|
|
63
|
-
static createModal(): FormatModal;
|
|
64
55
|
get value(): DataEnums[];
|
|
65
56
|
absorb(format: Format): this;
|
|
66
57
|
addText(val: DataText['value'], options?: DataText['options']): this;
|
|
@@ -79,8 +70,6 @@ export declare class Format {
|
|
|
79
70
|
addImageURL(val: DataImageURL['value']): this;
|
|
80
71
|
addSelect(select: FormatSelect): this;
|
|
81
72
|
addSelect(options: DataSelectOption[], meta?: DataSelect['options']): this;
|
|
82
|
-
addModal(modal: FormatModal): this;
|
|
83
|
-
addModal(inputs: DataTextInput[], meta: DataModal['options']): this;
|
|
84
73
|
addEmbed(embed: DataEmbed['value']): this;
|
|
85
74
|
clear(): this;
|
|
86
75
|
}
|
|
@@ -238,38 +238,6 @@ class FormatSelect {
|
|
|
238
238
|
return this;
|
|
239
239
|
}
|
|
240
240
|
}
|
|
241
|
-
class FormatModal {
|
|
242
|
-
#inputs = [];
|
|
243
|
-
#meta = { customId: '', title: '' };
|
|
244
|
-
get value() {
|
|
245
|
-
return {
|
|
246
|
-
type: 'Modal',
|
|
247
|
-
value: this.#inputs,
|
|
248
|
-
options: this.#meta
|
|
249
|
-
};
|
|
250
|
-
}
|
|
251
|
-
setCustomId(customId) {
|
|
252
|
-
this.#meta.customId = customId;
|
|
253
|
-
return this;
|
|
254
|
-
}
|
|
255
|
-
setTitle(title) {
|
|
256
|
-
this.#meta.title = title;
|
|
257
|
-
return this;
|
|
258
|
-
}
|
|
259
|
-
addInput(label, options) {
|
|
260
|
-
this.#inputs.push({
|
|
261
|
-
type: 'TextInput',
|
|
262
|
-
value: label,
|
|
263
|
-
options
|
|
264
|
-
});
|
|
265
|
-
return this;
|
|
266
|
-
}
|
|
267
|
-
clear() {
|
|
268
|
-
this.#inputs = [];
|
|
269
|
-
this.#meta = { customId: '', title: '' };
|
|
270
|
-
return this;
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
241
|
class Format {
|
|
274
242
|
#data = [];
|
|
275
243
|
static create() {
|
|
@@ -284,9 +252,6 @@ class Format {
|
|
|
284
252
|
static createSelect() {
|
|
285
253
|
return new FormatSelect();
|
|
286
254
|
}
|
|
287
|
-
static createModal() {
|
|
288
|
-
return new FormatModal();
|
|
289
|
-
}
|
|
290
255
|
get value() {
|
|
291
256
|
return this.#data;
|
|
292
257
|
}
|
|
@@ -405,19 +370,6 @@ class Format {
|
|
|
405
370
|
}
|
|
406
371
|
return this;
|
|
407
372
|
}
|
|
408
|
-
addModal(...args) {
|
|
409
|
-
if (args[0] instanceof FormatModal) {
|
|
410
|
-
this.#data.push(args[0].value);
|
|
411
|
-
}
|
|
412
|
-
else {
|
|
413
|
-
this.#data.push({
|
|
414
|
-
type: 'Modal',
|
|
415
|
-
value: args[0],
|
|
416
|
-
options: args[1]
|
|
417
|
-
});
|
|
418
|
-
}
|
|
419
|
-
return this;
|
|
420
|
-
}
|
|
421
373
|
addEmbed(embed) {
|
|
422
374
|
this.#data.push({
|
|
423
375
|
type: 'Embed',
|
|
@@ -431,4 +383,4 @@ class Format {
|
|
|
431
383
|
}
|
|
432
384
|
}
|
|
433
385
|
|
|
434
|
-
export { Format, FormatButtonGroup, FormatMarkDown,
|
|
386
|
+
export { Format, FormatButtonGroup, FormatMarkDown, FormatSelect };
|
package/lib/index.js
CHANGED
|
@@ -45,6 +45,6 @@ export { getCurrentEvent, getCurrentNext, withEventContext } from './app/hook-ev
|
|
|
45
45
|
export { registerAppDir, scheduleCancel, scheduleCancelAll, scheduleCancelByApp, scheduleCron, scheduleInterval, scheduleList, schedulePause, scheduleResume, scheduleTimeout, unregisterAppDir } from './app/schedule-store.js';
|
|
46
46
|
export { createEventValue, createSelects, onSelects, onState, unChildren, unState, useState } from './app/event-utils.js';
|
|
47
47
|
export { MessageDirect, createDataFormat, format, getMessageIntent, sendToChannel, sendToUser } from './app/message-api.js';
|
|
48
|
-
export { Format, FormatButtonGroup, FormatMarkDown,
|
|
48
|
+
export { Format, FormatButtonGroup, FormatMarkDown, FormatSelect } from './app/message-format.js';
|
|
49
49
|
export { start } from './main.js';
|
|
50
50
|
export { Attachment, Audio, BT, Button, Image, ImageFile, ImageURL, Link, MD, Markdown, MarkdownOriginal, Mention, Text, Video } from './app/message-format-old.js';
|
|
@@ -9,7 +9,6 @@ import { DataAudio } from './audio';
|
|
|
9
9
|
import { DataVideo } from './video';
|
|
10
10
|
import { DataMarkdownOriginal } from './markdown-raw';
|
|
11
11
|
import { DataSelect } from './select';
|
|
12
|
-
import { DataModal, DataTextInput } from './modal';
|
|
13
12
|
import { DataEmbed } from './embed';
|
|
14
13
|
export * from './text';
|
|
15
14
|
export * from './link';
|
|
@@ -22,7 +21,6 @@ export * from './attachment';
|
|
|
22
21
|
export * from './audio';
|
|
23
22
|
export * from './video';
|
|
24
23
|
export * from './select';
|
|
25
|
-
export * from './modal';
|
|
26
24
|
export * from './embed';
|
|
27
|
-
export type DataEnums = DataText | DataLink | DataImage | DataImageURL | DataImageFile | DataMention | DataButtonGroup | DataMarkDown | DataMarkdownOriginal | DataAttachment | DataAudio | DataVideo | DataSelect |
|
|
25
|
+
export type DataEnums = DataText | DataLink | DataImage | DataImageURL | DataImageFile | DataMention | DataButtonGroup | DataMarkDown | DataMarkdownOriginal | DataAttachment | DataAudio | DataVideo | DataSelect | DataEmbed;
|
|
28
26
|
export type MessageDataFormat = DataEnums[];
|
|
@@ -1,21 +1 @@
|
|
|
1
|
-
export
|
|
2
|
-
type: 'TextInput';
|
|
3
|
-
value: string;
|
|
4
|
-
options: {
|
|
5
|
-
customId: string;
|
|
6
|
-
style?: 'short' | 'paragraph';
|
|
7
|
-
placeholder?: string;
|
|
8
|
-
minLength?: number;
|
|
9
|
-
maxLength?: number;
|
|
10
|
-
required?: boolean;
|
|
11
|
-
defaultValue?: string;
|
|
12
|
-
};
|
|
13
|
-
};
|
|
14
|
-
export type DataModal = {
|
|
15
|
-
type: 'Modal';
|
|
16
|
-
value: DataTextInput[];
|
|
17
|
-
options: {
|
|
18
|
-
customId: string;
|
|
19
|
-
title: string;
|
|
20
|
-
};
|
|
21
|
-
};
|
|
1
|
+
export {};
|
package/lib/utils.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { PathLike } from 'fs';
|
|
2
2
|
import { Readable } from 'node:stream';
|
|
3
3
|
import { Options } from 'public-ip';
|
|
4
|
+
import { AxiosInstance, AxiosRequestConfig } from 'axios';
|
|
5
|
+
import { Buffer } from 'buffer';
|
|
4
6
|
export declare const getBufferByURL: (url: string) => Promise<Buffer>;
|
|
5
7
|
export declare const createQRCode: (text: string, targetPath?: string) => Promise<Buffer | false>;
|
|
6
8
|
export declare class Counter {
|
|
@@ -31,3 +33,7 @@ export declare class Regular extends RegExp {
|
|
|
31
33
|
withFlags(flags: 'i' | 'g' | 'm' | 's' | 'u' | 'y'): Regular;
|
|
32
34
|
withoutFlags(flagsToRemove: 'i' | 'g' | 'm' | 's' | 'u' | 'y'): Regular;
|
|
33
35
|
}
|
|
36
|
+
export declare const createAxiosInstance: (service: AxiosInstance, options: AxiosRequestConfig) => Promise<any>;
|
|
37
|
+
export declare const request: (options: AxiosRequestConfig & {
|
|
38
|
+
requestProxy: string;
|
|
39
|
+
}) => Promise<any>;
|
package/lib/utils.js
CHANGED
|
@@ -5,6 +5,8 @@ import { isReadable, Readable } from 'node:stream';
|
|
|
5
5
|
import { basename } from 'path';
|
|
6
6
|
import { fileTypeFromBuffer, fileTypeFromStream } from 'file-type';
|
|
7
7
|
import { publicIp } from 'public-ip';
|
|
8
|
+
import { Buffer } from 'buffer';
|
|
9
|
+
import { HttpsProxyAgent } from 'https-proxy-agent';
|
|
8
10
|
|
|
9
11
|
const getBufferByURL = async (url) => {
|
|
10
12
|
return await axios
|
|
@@ -178,5 +180,113 @@ class Regular extends RegExp {
|
|
|
178
180
|
return new Regular(this.source, newFlags);
|
|
179
181
|
}
|
|
180
182
|
}
|
|
183
|
+
const filterHeaders = (headers = {}) => {
|
|
184
|
+
if (!headers) {
|
|
185
|
+
return headers;
|
|
186
|
+
}
|
|
187
|
+
const filtered = {};
|
|
188
|
+
const sensitiveKeys = [/^authorization$/i, /^cookie$/i, /^set-cookie$/i, /token/i, /key/i, /jwt/i, /^session[-_]id$/i, /^uid$/i, /^user[-_]id$/i];
|
|
189
|
+
for (const key in headers) {
|
|
190
|
+
if (/^_/.test(key)) {
|
|
191
|
+
continue;
|
|
192
|
+
}
|
|
193
|
+
if (typeof key === 'symbol') {
|
|
194
|
+
continue;
|
|
195
|
+
}
|
|
196
|
+
if (typeof headers[key] === 'function') {
|
|
197
|
+
continue;
|
|
198
|
+
}
|
|
199
|
+
if (sensitiveKeys.some(re => re.test(key))) {
|
|
200
|
+
filtered[key] = '******';
|
|
201
|
+
}
|
|
202
|
+
else {
|
|
203
|
+
filtered[key] = headers[key];
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
return filtered;
|
|
207
|
+
};
|
|
208
|
+
const filterConfig = (config = {}) => {
|
|
209
|
+
if (!config) {
|
|
210
|
+
return config;
|
|
211
|
+
}
|
|
212
|
+
const filtered = {};
|
|
213
|
+
for (const key in config) {
|
|
214
|
+
if (/^_/.test(key)) {
|
|
215
|
+
continue;
|
|
216
|
+
}
|
|
217
|
+
if (typeof key === 'symbol') {
|
|
218
|
+
continue;
|
|
219
|
+
}
|
|
220
|
+
if (typeof config[key] === 'function') {
|
|
221
|
+
continue;
|
|
222
|
+
}
|
|
223
|
+
filtered[key] = config[key];
|
|
224
|
+
}
|
|
225
|
+
return filtered;
|
|
226
|
+
};
|
|
227
|
+
const filterRequest = (request = {}) => {
|
|
228
|
+
if (!request) {
|
|
229
|
+
return request;
|
|
230
|
+
}
|
|
231
|
+
const filtered = {};
|
|
232
|
+
for (const key in request) {
|
|
233
|
+
if (/^_/.test(key)) {
|
|
234
|
+
continue;
|
|
235
|
+
}
|
|
236
|
+
if (typeof key === 'symbol') {
|
|
237
|
+
continue;
|
|
238
|
+
}
|
|
239
|
+
if (typeof request[key] === 'function') {
|
|
240
|
+
continue;
|
|
241
|
+
}
|
|
242
|
+
filtered[key] = request[key];
|
|
243
|
+
}
|
|
244
|
+
return filtered;
|
|
245
|
+
};
|
|
246
|
+
const loggerError = err => {
|
|
247
|
+
const errorData = {
|
|
248
|
+
config: {
|
|
249
|
+
headers: filterHeaders(err?.config?.headers),
|
|
250
|
+
params: err?.config?.params,
|
|
251
|
+
data: err?.config?.data
|
|
252
|
+
},
|
|
253
|
+
response: {
|
|
254
|
+
status: err?.response?.status,
|
|
255
|
+
statusText: err?.response?.statusText,
|
|
256
|
+
headers: filterHeaders(err?.response?.headers),
|
|
257
|
+
config: filterConfig(err?.response?.config),
|
|
258
|
+
request: filterRequest(err?.response?.request),
|
|
259
|
+
data: err?.response?.data
|
|
260
|
+
},
|
|
261
|
+
message: err?.message
|
|
262
|
+
};
|
|
263
|
+
if (global?.logger) {
|
|
264
|
+
global.logger.error(errorData);
|
|
265
|
+
}
|
|
266
|
+
else {
|
|
267
|
+
console.error(errorData);
|
|
268
|
+
}
|
|
269
|
+
};
|
|
270
|
+
const createAxiosInstance = async (service, options) => {
|
|
271
|
+
try {
|
|
272
|
+
const res = await service(options);
|
|
273
|
+
return res?.data ?? {};
|
|
274
|
+
}
|
|
275
|
+
catch (err) {
|
|
276
|
+
loggerError(err);
|
|
277
|
+
throw err?.response?.data ?? err;
|
|
278
|
+
}
|
|
279
|
+
};
|
|
280
|
+
const request = (options) => {
|
|
281
|
+
const { requestProxy, ...requestConfig } = options;
|
|
282
|
+
if (requestProxy) {
|
|
283
|
+
requestConfig.httpsAgent = new HttpsProxyAgent(requestProxy);
|
|
284
|
+
}
|
|
285
|
+
const service = axios.create({
|
|
286
|
+
...requestConfig,
|
|
287
|
+
timeout: 6000
|
|
288
|
+
});
|
|
289
|
+
return createAxiosInstance(service, options);
|
|
290
|
+
};
|
|
181
291
|
|
|
182
|
-
export { Counter, Regular, createPicFrom, createQRCode, getBufferByURL, getPublicIP };
|
|
292
|
+
export { Counter, Regular, createAxiosInstance, createPicFrom, createQRCode, getBufferByURL, getPublicIP, request };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "alemonjs",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.65",
|
|
4
4
|
"description": "bot script",
|
|
5
5
|
"author": "lemonade",
|
|
6
6
|
"license": "MIT",
|
|
@@ -43,6 +43,7 @@
|
|
|
43
43
|
"qrcode": "^1.5.4",
|
|
44
44
|
"uuid": "11.1.0",
|
|
45
45
|
"ws": "^8.18.0",
|
|
46
|
+
"https-proxy-agent": "^9.0.0",
|
|
46
47
|
"yaml": "^2.5.1"
|
|
47
48
|
},
|
|
48
49
|
"devDependencies": {
|