alemonjs 2.1.11 → 2.1.13
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/hook-use-api.d.ts +28 -4
- package/lib/app/hook-use-api.js +66 -12
- package/lib/app/index.js +2 -2
- package/lib/app/message-api.d.ts +22 -3
- package/lib/app/message-api.js +12 -1
- package/lib/index.js +2 -2
- package/lib/types/actions.d.ts +4 -1
- package/lib/utils.d.ts +8 -4
- package/lib/utils.js +36 -8
- package/package.json +1 -1
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { DataEnums, EventKeys, Events, User } from '../types';
|
|
2
2
|
import { Result } from '../core/utils';
|
|
3
|
+
import { BT, MD } from './message-format';
|
|
3
4
|
type Options = {
|
|
4
5
|
UserId?: string;
|
|
5
6
|
UserKey?: string;
|
|
@@ -12,17 +13,40 @@ export declare const useMention: <T extends EventKeys>(event: Events[T]) => [{
|
|
|
12
13
|
findOne: (options?: Options) => Promise<Result<User | null>>;
|
|
13
14
|
}];
|
|
14
15
|
export declare const useMessage: <T extends EventKeys>(event: Events[T]) => readonly [{
|
|
15
|
-
|
|
16
|
+
"__#7@#format": DataEnums[];
|
|
17
|
+
readonly currentFormat: DataEnums[];
|
|
18
|
+
addText(val: string, options?: {
|
|
19
|
+
style?: "none" | "bold" | "block" | "strikethrough" | "boldItalic" | "italic";
|
|
20
|
+
}): any;
|
|
21
|
+
addLink(val: string, options?: {
|
|
22
|
+
style?: "none" | "bold" | "block" | "strikethrough" | "boldItalic" | "italic";
|
|
23
|
+
}): any;
|
|
24
|
+
addImage(val: Buffer<ArrayBufferLike>): any;
|
|
25
|
+
addImageFile(val: string): any;
|
|
26
|
+
addImageURL(val: string): any;
|
|
27
|
+
addMention(UserId?: string, options?: {
|
|
28
|
+
belong?: "user" | "guild" | "channel" | "everyone";
|
|
29
|
+
payload?: User | import("..").Guild | import("..").Channel | "everyone";
|
|
30
|
+
}): any;
|
|
31
|
+
addButtonGroup(...args: Parameters<typeof BT.group>): any;
|
|
32
|
+
addButtonTemplate(templateId: string): any;
|
|
33
|
+
addMarkdown(...args: Parameters<typeof MD>): any;
|
|
34
|
+
addMarkdownTemplate(templateId: string, params?: {
|
|
35
|
+
[key: string]: string;
|
|
36
|
+
}): any;
|
|
37
|
+
addFormat(val: DataEnums[]): any;
|
|
38
|
+
clear(): any;
|
|
39
|
+
send(val?: DataEnums[]): Promise<Result[]>;
|
|
16
40
|
}];
|
|
17
|
-
export declare const
|
|
41
|
+
export declare const useMember: <T extends EventKeys>(event: Events[T]) => readonly [{}];
|
|
18
42
|
export declare const useChannel: <T extends EventKeys>(event: Events[T]) => readonly [{}];
|
|
19
43
|
export declare const useSend: <T extends EventKeys>(event: Events[T]) => (...val: DataEnums[]) => Promise<Result[]>;
|
|
20
|
-
export declare const useSends: <T extends EventKeys>(event: Events[T]) => readonly [(val
|
|
44
|
+
export declare const useSends: <T extends EventKeys>(event: Events[T]) => readonly [(val?: DataEnums[]) => Promise<Result[]>];
|
|
21
45
|
export declare const unChildren: (name?: string) => void;
|
|
22
46
|
export declare const onSelects: <T extends EventKeys[] | EventKeys>(values: T) => T;
|
|
23
47
|
export declare const createSelects: <T extends EventKeys[] | EventKeys>(values: T) => T;
|
|
24
48
|
export declare const useClient: <T extends object>(event: any, _ApiClass: new (...args: any[]) => T) => readonly [T];
|
|
25
49
|
export declare const useMe: () => readonly [{
|
|
26
|
-
info: () => Promise<Result<
|
|
50
|
+
info: () => Promise<Result<User | null>>;
|
|
27
51
|
}];
|
|
28
52
|
export {};
|
package/lib/app/hook-use-api.js
CHANGED
|
@@ -3,6 +3,7 @@ import { ChildrenApp } from './store.js';
|
|
|
3
3
|
import { createResult } from '../core/utils.js';
|
|
4
4
|
import { sendAction } from '../cbp/processor/actions.js';
|
|
5
5
|
import { sendAPI } from '../cbp/processor/api.js';
|
|
6
|
+
import { Text, Link, Image, ImageFile, ImageURL, Mention, BT, MD } from './message-format.js';
|
|
6
7
|
|
|
7
8
|
const useMention = (event) => {
|
|
8
9
|
if (!event || typeof event !== 'object') {
|
|
@@ -130,12 +131,67 @@ const useMessage = (event) => {
|
|
|
130
131
|
});
|
|
131
132
|
return Array.isArray(result) ? result : [result];
|
|
132
133
|
};
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
134
|
+
class MessageController {
|
|
135
|
+
#format = [];
|
|
136
|
+
get currentFormat() {
|
|
137
|
+
return this.#format;
|
|
138
|
+
}
|
|
139
|
+
addText(...args) {
|
|
140
|
+
this.#format.push(Text(...args));
|
|
141
|
+
return this;
|
|
142
|
+
}
|
|
143
|
+
addLink(...args) {
|
|
144
|
+
this.#format.push(Link(...args));
|
|
145
|
+
return this;
|
|
146
|
+
}
|
|
147
|
+
addImage(...args) {
|
|
148
|
+
this.#format.push(Image(...args));
|
|
149
|
+
return this;
|
|
150
|
+
}
|
|
151
|
+
addImageFile(...args) {
|
|
152
|
+
this.#format.push(ImageFile(...args));
|
|
153
|
+
return this;
|
|
154
|
+
}
|
|
155
|
+
addImageURL(...args) {
|
|
156
|
+
this.#format.push(ImageURL(...args));
|
|
157
|
+
return this;
|
|
158
|
+
}
|
|
159
|
+
addMention(...args) {
|
|
160
|
+
this.#format.push(Mention(...args));
|
|
161
|
+
return this;
|
|
162
|
+
}
|
|
163
|
+
addButtonGroup(...args) {
|
|
164
|
+
this.#format.push(BT.group(...args));
|
|
165
|
+
return this;
|
|
166
|
+
}
|
|
167
|
+
addButtonTemplate(...args) {
|
|
168
|
+
this.#format.push(BT.template(...args));
|
|
169
|
+
return this;
|
|
170
|
+
}
|
|
171
|
+
addMarkdown(...args) {
|
|
172
|
+
this.#format.push(MD(...args));
|
|
173
|
+
return this;
|
|
174
|
+
}
|
|
175
|
+
addMarkdownTemplate(...args) {
|
|
176
|
+
this.#format.push(MD.template(...args));
|
|
177
|
+
return this;
|
|
178
|
+
}
|
|
179
|
+
addFormat(val) {
|
|
180
|
+
this.#format.push(...val);
|
|
181
|
+
return this;
|
|
182
|
+
}
|
|
183
|
+
clear() {
|
|
184
|
+
this.#format = [];
|
|
185
|
+
return this;
|
|
186
|
+
}
|
|
187
|
+
send(val) {
|
|
188
|
+
const dataToSend = val && val.length > 0 ? val : this.#format;
|
|
189
|
+
return send(dataToSend);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
return [new MessageController()];
|
|
137
193
|
};
|
|
138
|
-
const
|
|
194
|
+
const useMember = (event) => {
|
|
139
195
|
if (!event || typeof event !== 'object') {
|
|
140
196
|
logger.error({
|
|
141
197
|
code: ResultCode.FailParams,
|
|
@@ -211,15 +267,13 @@ const useMe = () => {
|
|
|
211
267
|
});
|
|
212
268
|
const result = results.find(item => item.code === ResultCode.Ok);
|
|
213
269
|
if (result) {
|
|
214
|
-
const data = result
|
|
270
|
+
const data = result?.data ?? null;
|
|
215
271
|
return createResult(ResultCode.Ok, 'Successfully retrieved bot information', data);
|
|
216
272
|
}
|
|
217
|
-
|
|
218
|
-
return createResult(ResultCode.Warn, 'No bot information found', null);
|
|
219
|
-
}
|
|
273
|
+
return createResult(ResultCode.Warn, 'No bot information found', null);
|
|
220
274
|
}
|
|
221
|
-
catch
|
|
222
|
-
return createResult(ResultCode.Fail,
|
|
275
|
+
catch {
|
|
276
|
+
return createResult(ResultCode.Fail, 'Failed to get bot information', null);
|
|
223
277
|
}
|
|
224
278
|
};
|
|
225
279
|
const control = {
|
|
@@ -228,4 +282,4 @@ const useMe = () => {
|
|
|
228
282
|
return [control];
|
|
229
283
|
};
|
|
230
284
|
|
|
231
|
-
export { createSelects, onSelects, unChildren, useChannel, useClient, useMe,
|
|
285
|
+
export { createSelects, onSelects, unChildren, useChannel, useClient, useMe, useMember, useMention, useMessage, useSend, useSends };
|
package/lib/app/index.js
CHANGED
|
@@ -12,8 +12,8 @@ export { expendCycle } from './event-processor-cycle.js';
|
|
|
12
12
|
export { expendEvent } from './event-processor-event.js';
|
|
13
13
|
export { expendMiddleware } from './event-processor-middleware.js';
|
|
14
14
|
export { expendSubscribe, expendSubscribeCreate, expendSubscribeMount, expendSubscribeUnmount } from './event-processor-subscribe.js';
|
|
15
|
-
export { createSelects, onSelects, unChildren, useChannel, useClient, useMe,
|
|
15
|
+
export { createSelects, onSelects, unChildren, useChannel, useClient, useMe, useMember, useMention, useMessage, useSend, useSends } from './hook-use-api.js';
|
|
16
16
|
export { onState, unState, useState } from './hook-use-state.js';
|
|
17
17
|
export { useObserver, useSubscribe } from './hook-use-subscribe.js';
|
|
18
|
-
export { createDataFormat, createEventValue, format, sendToChannel, sendToUser } from './message-api.js';
|
|
18
|
+
export { createDataFormat, createEventValue, format, getMessageIntent, sendToChannel, sendToUser } from './message-api.js';
|
|
19
19
|
export { Ark, BT, Image, ImageFile, ImageURL, Link, MD, Mention, Text } from './message-format.js';
|
package/lib/app/message-api.d.ts
CHANGED
|
@@ -1,12 +1,31 @@
|
|
|
1
1
|
import { DataEnums, OnDataFormatFunc } from '../types';
|
|
2
|
+
import { Result } from '../core';
|
|
2
3
|
type BaseMap = {
|
|
3
|
-
[key: string]:
|
|
4
|
+
[key: string]: unknown;
|
|
4
5
|
};
|
|
5
6
|
export declare const createEventValue: <T extends keyof R, R extends BaseMap>(event: {
|
|
6
7
|
value: R[T];
|
|
7
8
|
}) => R[T];
|
|
8
9
|
export declare const format: OnDataFormatFunc;
|
|
9
10
|
export declare const createDataFormat: OnDataFormatFunc;
|
|
10
|
-
export declare const sendToChannel: (SpaceId: string, data: DataEnums[]) => Promise<
|
|
11
|
-
export declare const sendToUser: (OpenID: string, data: DataEnums[]) => Promise<
|
|
11
|
+
export declare const sendToChannel: (SpaceId: string, data: DataEnums[]) => Promise<Result[]>;
|
|
12
|
+
export declare const sendToUser: (OpenID: string, data: DataEnums[]) => Promise<Result[]>;
|
|
13
|
+
type IntentResult = {
|
|
14
|
+
[key: string]: boolean | number;
|
|
15
|
+
maxImageCount?: number;
|
|
16
|
+
maxImageSize?: number;
|
|
17
|
+
maxTextLength?: number;
|
|
18
|
+
maxMarkdownLength?: number;
|
|
19
|
+
allowMarkdownLink?: boolean;
|
|
20
|
+
allowMarkdownImage?: boolean;
|
|
21
|
+
allowMarkdownMention?: boolean;
|
|
22
|
+
maxFileCount?: number;
|
|
23
|
+
maxFileSize?: number;
|
|
24
|
+
maxVideoCount?: number;
|
|
25
|
+
maxVideoSize?: number;
|
|
26
|
+
allowButton?: boolean;
|
|
27
|
+
allowMixImageText?: boolean;
|
|
28
|
+
allowMixMarkdownButton?: boolean;
|
|
29
|
+
};
|
|
30
|
+
export declare const getMessageIntent: () => Promise<Result<IntentResult>>;
|
|
12
31
|
export {};
|
package/lib/app/message-api.js
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { ResultCode } from '../core/variable.js';
|
|
2
2
|
import { sendAction } from '../cbp/processor/actions.js';
|
|
3
|
+
import 'fs';
|
|
4
|
+
import 'path';
|
|
5
|
+
import 'yaml';
|
|
6
|
+
import { createResult } from '../core/utils.js';
|
|
3
7
|
|
|
4
8
|
const createEventValue = (event) => {
|
|
5
9
|
return event.value;
|
|
@@ -55,5 +59,12 @@ const sendToUser = async (OpenID, data) => {
|
|
|
55
59
|
}
|
|
56
60
|
});
|
|
57
61
|
};
|
|
62
|
+
const getMessageIntent = async () => {
|
|
63
|
+
const results = await sendAction({
|
|
64
|
+
action: 'message.intent',
|
|
65
|
+
payload: {}
|
|
66
|
+
});
|
|
67
|
+
return createResult(ResultCode.Ok, '获取成功', results[0]?.data ?? null);
|
|
68
|
+
};
|
|
58
69
|
|
|
59
|
-
export { createDataFormat, createEventValue, format, sendToChannel, sendToUser };
|
|
70
|
+
export { createDataFormat, createEventValue, format, getMessageIntent, sendToChannel, sendToUser };
|
package/lib/index.js
CHANGED
|
@@ -19,9 +19,9 @@ export { expendCycle } from './app/event-processor-cycle.js';
|
|
|
19
19
|
export { expendEvent } from './app/event-processor-event.js';
|
|
20
20
|
export { expendMiddleware } from './app/event-processor-middleware.js';
|
|
21
21
|
export { expendSubscribe, expendSubscribeCreate, expendSubscribeMount, expendSubscribeUnmount } from './app/event-processor-subscribe.js';
|
|
22
|
-
export { createSelects, onSelects, unChildren, useChannel, useClient, useMe,
|
|
22
|
+
export { createSelects, onSelects, unChildren, useChannel, useClient, useMe, useMember, useMention, useMessage, useSend, useSends } from './app/hook-use-api.js';
|
|
23
23
|
export { onState, unState, useState } from './app/hook-use-state.js';
|
|
24
24
|
export { useObserver, useSubscribe } from './app/hook-use-subscribe.js';
|
|
25
|
-
export { createDataFormat, createEventValue, format, sendToChannel, sendToUser } from './app/message-api.js';
|
|
25
|
+
export { createDataFormat, createEventValue, format, getMessageIntent, sendToChannel, sendToUser } from './app/message-api.js';
|
|
26
26
|
export { Ark, BT, Image, ImageFile, ImageURL, Link, MD, Mention, Text } from './app/message-format.js';
|
|
27
27
|
export { start } from './main.js';
|
package/lib/types/actions.d.ts
CHANGED
|
@@ -91,5 +91,8 @@ type base = {
|
|
|
91
91
|
actionId?: string;
|
|
92
92
|
DeviceId?: string;
|
|
93
93
|
};
|
|
94
|
-
export type Actions = (ActionMessageSend | ActionMentionGet | ActionMessageSendChannel | ActionMessageSendUser | ActionMessageDelete | ActionFileSendChannel | ActionFileSendUser | ActionMessageForwardUser | ActionMessageForwardChannel | ActionMeInfo
|
|
94
|
+
export type Actions = (ActionMessageSend | ActionMentionGet | ActionMessageSendChannel | ActionMessageSendUser | ActionMessageDelete | ActionFileSendChannel | ActionFileSendUser | ActionMessageForwardUser | ActionMessageForwardChannel | ActionMeInfo | {
|
|
95
|
+
action: string;
|
|
96
|
+
payload: object;
|
|
97
|
+
}) & base;
|
|
95
98
|
export {};
|
package/lib/utils.d.ts
CHANGED
|
@@ -22,8 +22,12 @@ export declare const getPublicIP: (options?: Options & {
|
|
|
22
22
|
force?: boolean;
|
|
23
23
|
}) => Promise<string>;
|
|
24
24
|
export declare class Regular extends RegExp {
|
|
25
|
-
static
|
|
26
|
-
static
|
|
27
|
-
or(...
|
|
28
|
-
and(...
|
|
25
|
+
static create(pattern: RegExp | string, flags?: string): Regular;
|
|
26
|
+
private static mergeFlags;
|
|
27
|
+
static or(...regulars: RegExp[]): Regular;
|
|
28
|
+
static and(...regulars: RegExp[]): Regular;
|
|
29
|
+
or(...regulars: RegExp[]): Regular;
|
|
30
|
+
and(...regulars: RegExp[]): Regular;
|
|
31
|
+
withFlags(flags: 'i' | 'g' | 'm' | 's' | 'u' | 'y'): Regular;
|
|
32
|
+
withoutFlags(flagsToRemove: 'i' | 'g' | 'm' | 's' | 'u' | 'y'): Regular;
|
|
29
33
|
}
|
package/lib/utils.js
CHANGED
|
@@ -137,17 +137,45 @@ const getPublicIP = async (options = {}) => {
|
|
|
137
137
|
});
|
|
138
138
|
};
|
|
139
139
|
class Regular extends RegExp {
|
|
140
|
-
static
|
|
141
|
-
return new Regular(
|
|
140
|
+
static create(pattern, flags) {
|
|
141
|
+
return new Regular(pattern, flags);
|
|
142
|
+
}
|
|
143
|
+
static mergeFlags(...flags) {
|
|
144
|
+
const flagSet = new Set();
|
|
145
|
+
for (const flagStr of flags) {
|
|
146
|
+
for (const char of flagStr) {
|
|
147
|
+
flagSet.add(char);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
return Array.from(flagSet).sort().join('');
|
|
151
|
+
}
|
|
152
|
+
static or(...regulars) {
|
|
153
|
+
const source = regulars.map(reg => `(?:${reg.source})`).join('|');
|
|
154
|
+
const flags = Regular.mergeFlags(...regulars.map(reg => reg.flags));
|
|
155
|
+
return new Regular(`(?:${source})`, flags);
|
|
142
156
|
}
|
|
143
|
-
static and(...
|
|
144
|
-
|
|
157
|
+
static and(...regulars) {
|
|
158
|
+
const lookAHeads = regulars.map(reg => `(?=.*${reg.source})`).join('');
|
|
159
|
+
const flags = Regular.mergeFlags(...regulars.map(reg => reg.flags));
|
|
160
|
+
return new Regular(`${lookAHeads}.*`, flags);
|
|
145
161
|
}
|
|
146
|
-
or(...
|
|
147
|
-
return Regular.or(this, ...
|
|
162
|
+
or(...regulars) {
|
|
163
|
+
return Regular.or(this, ...regulars);
|
|
148
164
|
}
|
|
149
|
-
and(...
|
|
150
|
-
return Regular.and(this, ...
|
|
165
|
+
and(...regulars) {
|
|
166
|
+
return Regular.and(this, ...regulars);
|
|
167
|
+
}
|
|
168
|
+
withFlags(flags) {
|
|
169
|
+
const mergedFlags = Regular.mergeFlags(this.flags, flags);
|
|
170
|
+
return new Regular(this.source, mergedFlags);
|
|
171
|
+
}
|
|
172
|
+
withoutFlags(flagsToRemove) {
|
|
173
|
+
const currentFlagsSet = new Set(this.flags);
|
|
174
|
+
for (const char of flagsToRemove) {
|
|
175
|
+
currentFlagsSet.delete(char);
|
|
176
|
+
}
|
|
177
|
+
const newFlags = Array.from(currentFlagsSet).sort().join('');
|
|
178
|
+
return new Regular(this.source, newFlags);
|
|
151
179
|
}
|
|
152
180
|
}
|
|
153
181
|
|