alemonjs 2.1.10 → 2.1.12
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 +3 -0
- package/lib/app/hook-use-api.js +26 -1
- package/lib/app/index.js +1 -1
- package/lib/index.js +1 -1
- package/lib/types/actions.d.ts +5 -1
- package/lib/utils.d.ts +8 -4
- package/lib/utils.js +36 -8
- package/package.json +1 -2
|
@@ -22,4 +22,7 @@ export declare const unChildren: (name?: string) => void;
|
|
|
22
22
|
export declare const onSelects: <T extends EventKeys[] | EventKeys>(values: T) => T;
|
|
23
23
|
export declare const createSelects: <T extends EventKeys[] | EventKeys>(values: T) => T;
|
|
24
24
|
export declare const useClient: <T extends object>(event: any, _ApiClass: new (...args: any[]) => T) => readonly [T];
|
|
25
|
+
export declare const useMe: () => readonly [{
|
|
26
|
+
info: () => Promise<Result<any>>;
|
|
27
|
+
}];
|
|
25
28
|
export {};
|
package/lib/app/hook-use-api.js
CHANGED
|
@@ -202,5 +202,30 @@ const useClient = (event, _ApiClass) => {
|
|
|
202
202
|
});
|
|
203
203
|
return [client];
|
|
204
204
|
};
|
|
205
|
+
const useMe = () => {
|
|
206
|
+
const info = async () => {
|
|
207
|
+
try {
|
|
208
|
+
const results = await sendAction({
|
|
209
|
+
action: 'me.info',
|
|
210
|
+
payload: {}
|
|
211
|
+
});
|
|
212
|
+
const result = results.find(item => item.code === ResultCode.Ok);
|
|
213
|
+
if (result) {
|
|
214
|
+
const data = result.data;
|
|
215
|
+
return createResult(ResultCode.Ok, 'Successfully retrieved bot information', data);
|
|
216
|
+
}
|
|
217
|
+
else {
|
|
218
|
+
return createResult(ResultCode.Warn, 'No bot information found', null);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
catch (err) {
|
|
222
|
+
return createResult(ResultCode.Fail, err?.message || 'Failed to get bot information', null);
|
|
223
|
+
}
|
|
224
|
+
};
|
|
225
|
+
const control = {
|
|
226
|
+
info
|
|
227
|
+
};
|
|
228
|
+
return [control];
|
|
229
|
+
};
|
|
205
230
|
|
|
206
|
-
export { createSelects, onSelects, unChildren, useChannel, useClient, useMenber, useMention, useMessage, useSend, useSends };
|
|
231
|
+
export { createSelects, onSelects, unChildren, useChannel, useClient, useMe, useMenber, useMention, useMessage, useSend, useSends };
|
package/lib/app/index.js
CHANGED
|
@@ -12,7 +12,7 @@ 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, useMenber, useMention, useMessage, useSend, useSends } from './hook-use-api.js';
|
|
15
|
+
export { createSelects, onSelects, unChildren, useChannel, useClient, useMe, useMenber, 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
18
|
export { createDataFormat, createEventValue, format, sendToChannel, sendToUser } from './message-api.js';
|
package/lib/index.js
CHANGED
|
@@ -19,7 +19,7 @@ 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, useMenber, useMention, useMessage, useSend, useSends } from './app/hook-use-api.js';
|
|
22
|
+
export { createSelects, onSelects, unChildren, useChannel, useClient, useMe, useMenber, 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
25
|
export { createDataFormat, createEventValue, format, sendToChannel, sendToUser } from './app/message-api.js';
|
package/lib/types/actions.d.ts
CHANGED
|
@@ -83,9 +83,13 @@ export type ActionMessageForwardChannel = {
|
|
|
83
83
|
}[];
|
|
84
84
|
};
|
|
85
85
|
};
|
|
86
|
+
export type ActionMeInfo = {
|
|
87
|
+
action: 'me.info';
|
|
88
|
+
payload: object;
|
|
89
|
+
};
|
|
86
90
|
type base = {
|
|
87
91
|
actionId?: string;
|
|
88
92
|
DeviceId?: string;
|
|
89
93
|
};
|
|
90
|
-
export type Actions = (ActionMessageSend | ActionMentionGet | ActionMessageSendChannel | ActionMessageSendUser | ActionMessageDelete | ActionFileSendChannel | ActionFileSendUser | ActionMessageForwardUser | ActionMessageForwardChannel) & base;
|
|
94
|
+
export type Actions = (ActionMessageSend | ActionMentionGet | ActionMessageSendChannel | ActionMessageSendUser | ActionMessageDelete | ActionFileSendChannel | ActionFileSendUser | ActionMessageForwardUser | ActionMessageForwardChannel | ActionMeInfo) & base;
|
|
91
95
|
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
|
|