alemonjs 2.1.9 → 2.1.11

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.
@@ -1,3 +1,5 @@
1
1
  import { DefineResponseFunc } from '../types';
2
- export declare const lazy: (fnc: () => Promise<any>) => () => Promise<any>;
2
+ export declare const lazy: <T extends {
3
+ default: any;
4
+ }>(fnc: () => Promise<T>) => (() => Promise<T["default"]>);
3
5
  export declare const defineResponse: DefineResponseFunc;
@@ -1,5 +1,6 @@
1
1
  const lazy = (fnc) => {
2
- return async () => (await fnc()).default;
2
+ const back = async () => (await fnc()).default;
3
+ return back;
3
4
  };
4
5
  const defineResponse = responses => {
5
6
  return {
@@ -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 {};
@@ -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';
@@ -64,11 +64,6 @@ const cbpClient = (url, options = {}) => {
64
64
  global.chatbotClient.on('message', message => {
65
65
  try {
66
66
  const parsedMessage = flattedJSON.parse(message.toString());
67
- logger.debug({
68
- code: ResultCode.Ok,
69
- message: '客户端接收到消息',
70
- data: parsedMessage
71
- });
72
67
  if (parsedMessage?.activeId) {
73
68
  if (parsedMessage.active === 'sync') {
74
69
  const configs = parsedMessage.payload;
@@ -86,11 +86,6 @@ const cbpPlatform = (url, options = {
86
86
  global.chatbotPlatform.on('message', message => {
87
87
  try {
88
88
  const data = flattedJSON.parse(message.toString());
89
- logger.debug({
90
- code: ResultCode.Ok,
91
- message: '平台端接收消息',
92
- data: data
93
- });
94
89
  if (data.apiId) {
95
90
  for (const cb of apiReplys) {
96
91
  void cb(data, val => replyApi(data, val));
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';
@@ -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/package.json CHANGED
@@ -1,7 +1,6 @@
1
1
  {
2
- "$schema": "https://json.schemastore.org/package",
3
2
  "name": "alemonjs",
4
- "version": "2.1.9",
3
+ "version": "2.1.11",
5
4
  "description": "bot script",
6
5
  "author": "lemonade",
7
6
  "license": "MIT",
@@ -72,4 +71,4 @@
72
71
  "type": "git",
73
72
  "url": "https://github.com/lemonade-lab/alemonjs.git"
74
73
  }
75
- }
74
+ }