alemonjs 2.1.12 → 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.
@@ -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
- send: (val: DataEnums[]) => Promise<Result[]>;
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 useMenber: <T extends EventKeys>(event: Events[T]) => readonly [{}];
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: DataEnums[]) => Promise<Result[]>];
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<any>>;
50
+ info: () => Promise<Result<User | null>>;
27
51
  }];
28
52
  export {};
@@ -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
- const message = {
134
- send
135
- };
136
- return [message];
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 useMenber = (event) => {
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.data;
270
+ const data = result?.data ?? null;
215
271
  return createResult(ResultCode.Ok, 'Successfully retrieved bot information', data);
216
272
  }
217
- else {
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 (err) {
222
- return createResult(ResultCode.Fail, err?.message || 'Failed to get bot information', null);
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, useMenber, useMention, useMessage, useSend, useSends };
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, useMenber, useMention, useMessage, useSend, useSends } from './hook-use-api.js';
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';
@@ -1,12 +1,31 @@
1
1
  import { DataEnums, OnDataFormatFunc } from '../types';
2
+ import { Result } from '../core';
2
3
  type BaseMap = {
3
- [key: string]: any;
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<import("..").Result[]>;
11
- export declare const sendToUser: (OpenID: string, data: DataEnums[]) => Promise<import("..").Result[]>;
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 {};
@@ -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, useMenber, useMention, useMessage, useSend, useSends } from './app/hook-use-api.js';
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';
@@ -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) & base;
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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "alemonjs",
3
- "version": "2.1.12",
3
+ "version": "2.1.13",
4
4
  "description": "bot script",
5
5
  "author": "lemonade",
6
6
  "license": "MIT",