alemonjs 2.1.19 → 2.1.21

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.
@@ -5,7 +5,6 @@ const lazy = (fnc) => {
5
5
  return c;
6
6
  }
7
7
  const mod = await fnc();
8
- console.warn('Lazy load module:', mod);
9
8
  if (!mod || !mod.default) ;
10
9
  c = mod.default;
11
10
  return c;
@@ -4,13 +4,13 @@ import 'path';
4
4
  import 'yaml';
5
5
  import { showErrorModule } from '../core/utils.js';
6
6
 
7
- function isPromise(value) {
8
- return value !== null && (typeof value === 'object' || typeof value === 'function') && typeof value.then === 'function';
9
- }
10
7
  function isAsyncFunction(fn) {
11
8
  const AsyncFunction = (async () => { }).constructor;
12
9
  return fn instanceof AsyncFunction;
13
10
  }
11
+ function isFunction(value) {
12
+ return isAsyncFunction(value) || typeof value === 'function' || value instanceof Function;
13
+ }
14
14
  const createRouteProcessChildren = (valueEvent, select, nextCycle, callHandler) => {
15
15
  const processChildren = (nodes, middleware, next) => {
16
16
  if (!nodes || nodes.length === 0) {
@@ -67,7 +67,7 @@ const createRouteProcessChildren = (valueEvent, select, nextCycle, callHandler)
67
67
  const currents = [];
68
68
  for (const item of currentsAndMiddleware) {
69
69
  const app = await item();
70
- if (isPromise(app) || isAsyncFunction(app)) {
70
+ if (isFunction(app)) {
71
71
  currents.push(app);
72
72
  continue;
73
73
  }
@@ -17,7 +17,7 @@ export declare const useMention: <T extends EventKeys>(event: Events[T]) => [{
17
17
  }>;
18
18
  }];
19
19
  export declare const useMessage: <T extends EventKeys>(event: Events[T]) => readonly [{
20
- "__#8@#format": DataEnums[];
20
+ "__#10@#format": DataEnums[];
21
21
  readonly currentFormat: DataEnums[];
22
22
  addText(val: string, options?: {
23
23
  style?: "none" | "bold" | "block" | "strikethrough" | "boldItalic" | "italic";
@@ -3,7 +3,8 @@ 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, Format } from './message-format.js';
6
+ import { Format } from './message-format.js';
7
+ import { Text, Link, Image, ImageFile, ImageURL, Mention, BT, MD } from './message-format-old.js';
7
8
 
8
9
  const useMention = (event) => {
9
10
  if (!event || typeof event !== 'object') {
package/lib/app/index.js CHANGED
@@ -18,4 +18,5 @@ export { createSelects, onSelects, unChildren, useChannel, useClient, useMe, use
18
18
  export { onState, unState, useState } from './hook-use-state.js';
19
19
  export { useObserver, useSubscribe } from './hook-use-subscribe.js';
20
20
  export { createDataFormat, createEventValue, format, getMessageIntent, sendToChannel, sendToUser } from './message-api.js';
21
- export { Ark, BT, Format, Image, ImageFile, ImageURL, Link, MD, Mention, Text, createEvent } from './message-format.js';
21
+ export { Format, createEvent } from './message-format.js';
22
+ export { Ark, BT, Image, ImageFile, ImageURL, Link, MD, Mention, Text } from './message-format-old.js';
@@ -0,0 +1,50 @@
1
+ import { DataMention, DataImage, DataText, DataImageURL, DataImageFile, ButtonRow, DataButtonGroup, DataButton, DataArkList, DataArkListTip, DataArkListContent, DataArkListItem, DataArkCard, DataArkBigCard, DataMarkdownTemplate, DataMarkDown, DataMarkdownTitle, DataMarkdownSubtitle, DataMarkdownBold, DataMarkdownItalic, DataMarkdownItalicStar, DataMarkdownStrikethrough, DataMarkdownLink, DataMarkdownImage, DataMarkdownList, DataMarkdownListItem, DataMarkdownBlockquote, DataMarkdownDivider, DataMarkdownNewline, DataLink, DataMarkdownText, DataButtonTemplate, DataMarkdownCode } from '../types';
2
+ export declare const Text: (val: DataText["value"], options?: DataText["options"]) => DataText;
3
+ export declare const Link: (val: DataLink["value"], options?: DataText["options"]) => DataText;
4
+ export declare const ImageURL: (val: DataImageURL["value"]) => DataImageURL;
5
+ export declare const ImageFile: (val: DataImageFile["value"]) => DataImageFile;
6
+ declare const Image: {
7
+ (val: Buffer): DataImage;
8
+ url: (val: DataImageURL["value"]) => DataImageURL;
9
+ file: (val: DataImageFile["value"]) => DataImageFile;
10
+ };
11
+ export { Image };
12
+ export declare const Mention: (UserId?: DataMention["value"], options?: DataMention["options"]) => DataMention;
13
+ declare const BT: {
14
+ (title: string, data: DataButton["options"]["data"], options?: Omit<DataButton["options"], "data">): DataButton;
15
+ group(...rows: ButtonRow[]): DataButtonGroup;
16
+ template(templateId: DataButtonTemplate["value"]): DataButtonTemplate;
17
+ row(...buttons: DataButton[]): ButtonRow;
18
+ };
19
+ export { BT };
20
+ export declare const Ark: {
21
+ list: (values_0: DataArkListTip, values_1: DataArkListContent) => DataArkList;
22
+ listTip: (options: DataArkListTip["value"]) => DataArkListTip;
23
+ listContent: (...values: DataArkListContent["value"]) => DataArkListContent;
24
+ listItem: (value: DataArkListItem["value"]) => DataArkListItem;
25
+ Card: (value: DataArkCard["value"]) => DataArkCard;
26
+ BigCard: (value: DataArkBigCard["value"]) => DataArkBigCard;
27
+ };
28
+ declare const MD: {
29
+ (...values: DataMarkDown["value"]): DataMarkDown;
30
+ template(templateId: DataMarkdownTemplate["value"], params?: DataMarkdownTemplate["options"]["params"]): DataMarkdownTemplate;
31
+ text(text: string): DataMarkdownText;
32
+ title(text: string): DataMarkdownTitle;
33
+ subtitle(text: string): DataMarkdownSubtitle;
34
+ bold(text: string): DataMarkdownBold;
35
+ italic(text: string): DataMarkdownItalic;
36
+ italicStar(text: string): DataMarkdownItalicStar;
37
+ strikethrough(text: string): DataMarkdownStrikethrough;
38
+ link(text: string, url: string): DataMarkdownLink;
39
+ image(url: string, options?: {
40
+ width?: number;
41
+ height?: number;
42
+ }): DataMarkdownImage;
43
+ list(...items: any[]): DataMarkdownList;
44
+ listItem(indexOrText: number | string, text?: string): DataMarkdownListItem;
45
+ blockquote(text: string): DataMarkdownBlockquote;
46
+ divider(): DataMarkdownDivider;
47
+ newline(value?: boolean): DataMarkdownNewline;
48
+ code(value: DataMarkdownCode["value"], options?: DataMarkdownCode["options"]): DataMarkdownCode;
49
+ };
50
+ export { MD };
@@ -0,0 +1,217 @@
1
+ const Text = (val, options) => {
2
+ return {
3
+ type: 'Text',
4
+ value: val,
5
+ options
6
+ };
7
+ };
8
+ const Link = (val, options) => {
9
+ return {
10
+ type: 'Text',
11
+ value: val,
12
+ options
13
+ };
14
+ };
15
+ const ImageURL = (val) => {
16
+ return {
17
+ type: 'ImageURL',
18
+ value: val
19
+ };
20
+ };
21
+ const ImageFile = (val) => {
22
+ return {
23
+ type: 'ImageFile',
24
+ value: val
25
+ };
26
+ };
27
+ const Image = (val) => {
28
+ return {
29
+ type: 'Image',
30
+ value: val.toString('base64')
31
+ };
32
+ };
33
+ Image.url = ImageURL;
34
+ Image.file = ImageFile;
35
+ const Mention = (UserId, options) => {
36
+ return {
37
+ type: 'Mention',
38
+ value: UserId,
39
+ options: options ?? {
40
+ belong: 'user'
41
+ }
42
+ };
43
+ };
44
+ const BT = (title, data, options) => {
45
+ return {
46
+ type: 'Button',
47
+ value: title,
48
+ options: {
49
+ data,
50
+ ...options
51
+ }
52
+ };
53
+ };
54
+ BT.group = function Group(...rows) {
55
+ return {
56
+ type: 'BT.group',
57
+ value: rows
58
+ };
59
+ };
60
+ BT.template = function Template(templateId) {
61
+ return {
62
+ type: 'ButtonTemplate',
63
+ value: templateId
64
+ };
65
+ };
66
+ BT.row = function Row(...buttons) {
67
+ return {
68
+ type: 'BT.row',
69
+ value: buttons
70
+ };
71
+ };
72
+ const Ark = {
73
+ list: (...values) => {
74
+ return {
75
+ type: 'Ark.list',
76
+ value: values
77
+ };
78
+ },
79
+ listTip: (options) => {
80
+ return {
81
+ type: 'Ark.listTip',
82
+ value: options
83
+ };
84
+ },
85
+ listContent: (...values) => {
86
+ return {
87
+ type: 'Ark.listContent',
88
+ value: values
89
+ };
90
+ },
91
+ listItem: (value) => {
92
+ return {
93
+ type: 'Ark.listItem',
94
+ value: value
95
+ };
96
+ },
97
+ Card: (value) => {
98
+ return {
99
+ type: 'Ark.Card',
100
+ value: value
101
+ };
102
+ },
103
+ BigCard: (value) => {
104
+ return {
105
+ type: 'Ark.BigCard',
106
+ value
107
+ };
108
+ }
109
+ };
110
+ const MD = (...values) => {
111
+ return {
112
+ type: 'Markdown',
113
+ value: values
114
+ };
115
+ };
116
+ MD.template = (templateId, params) => {
117
+ return {
118
+ type: 'MarkdownTemplate',
119
+ value: templateId,
120
+ options: {
121
+ params
122
+ }
123
+ };
124
+ };
125
+ MD.text = (text) => {
126
+ return {
127
+ type: 'MD.text',
128
+ value: text
129
+ };
130
+ };
131
+ MD.title = (text) => {
132
+ return {
133
+ type: 'MD.title',
134
+ value: text
135
+ };
136
+ };
137
+ MD.subtitle = (text) => {
138
+ return {
139
+ type: 'MD.subtitle',
140
+ value: text
141
+ };
142
+ };
143
+ MD.bold = (text) => {
144
+ return {
145
+ type: 'MD.bold',
146
+ value: text
147
+ };
148
+ };
149
+ MD.italic = (text) => {
150
+ return {
151
+ type: 'MD.italic',
152
+ value: text
153
+ };
154
+ };
155
+ MD.italicStar = (text) => {
156
+ return {
157
+ type: 'MD.italicStar',
158
+ value: text
159
+ };
160
+ };
161
+ MD.strikethrough = (text) => {
162
+ return {
163
+ type: 'MD.strikethrough',
164
+ value: text
165
+ };
166
+ };
167
+ MD.link = (text, url) => {
168
+ return {
169
+ type: 'MD.link',
170
+ value: { text, url }
171
+ };
172
+ };
173
+ MD.image = (url, options) => {
174
+ return {
175
+ type: 'MD.image',
176
+ value: url,
177
+ options
178
+ };
179
+ };
180
+ MD.list = (...items) => {
181
+ return {
182
+ type: 'MD.list',
183
+ value: items
184
+ };
185
+ };
186
+ MD.listItem = (indexOrText, text) => {
187
+ return {
188
+ type: 'MD.listItem',
189
+ value: typeof indexOrText === 'number' ? { index: indexOrText, text } : indexOrText
190
+ };
191
+ };
192
+ MD.blockquote = (text) => {
193
+ return {
194
+ type: 'MD.blockquote',
195
+ value: text
196
+ };
197
+ };
198
+ MD.divider = () => {
199
+ return {
200
+ type: 'MD.divider'
201
+ };
202
+ };
203
+ MD.newline = (value = false) => {
204
+ return {
205
+ type: 'MD.newline',
206
+ value: value
207
+ };
208
+ };
209
+ MD.code = (value, options) => {
210
+ return {
211
+ type: 'MD.code',
212
+ value: value,
213
+ options: options
214
+ };
215
+ };
216
+
217
+ export { Ark, BT, Image, ImageFile, ImageURL, Link, MD, Mention, Text };
@@ -1,56 +1,38 @@
1
- import { DataMention, DataImage, DataText, DataImageURL, DataImageFile, ButtonRow, DataButtonGroup, DataButton, DataArkList, DataArkListTip, DataArkListContent, DataArkListItem, DataArkCard, DataArkBigCard, DataMarkdownTemplate, DataMarkDown, DataMarkdownTitle, DataMarkdownSubtitle, DataMarkdownBold, DataMarkdownItalic, DataMarkdownItalicStar, DataMarkdownStrikethrough, DataMarkdownLink, DataMarkdownImage, DataMarkdownList, DataMarkdownListItem, DataMarkdownBlockquote, DataMarkdownDivider, DataMarkdownNewline, DataLink, DataMarkdownText, DataButtonTemplate, DataMarkdownCode, DataEnums, EventKeys, Events } from '../types';
2
- export declare const Text: (val: DataText["value"], options?: DataText["options"]) => DataText;
3
- export declare const Link: (val: DataLink["value"], options?: DataText["options"]) => DataText;
4
- export declare const ImageURL: (val: DataImageURL["value"]) => DataImageURL;
5
- export declare const ImageFile: (val: DataImageFile["value"]) => DataImageFile;
6
- declare const Image: {
7
- (val: Buffer): DataImage;
8
- url: (val: DataImageURL["value"]) => DataImageURL;
9
- file: (val: DataImageFile["value"]) => DataImageFile;
10
- };
11
- export { Image };
12
- export declare const Mention: (UserId?: DataMention["value"], options?: DataMention["options"]) => DataMention;
13
- declare const BT: {
14
- (title: string, data: DataButton["options"]["data"], options?: Omit<DataButton["options"], "data">): DataButton;
15
- group(...rows: ButtonRow[]): DataButtonGroup;
16
- template(templateId: DataButtonTemplate["value"]): DataButtonTemplate;
17
- row(...buttons: DataButton[]): ButtonRow;
18
- };
19
- export { BT };
20
- export declare const Ark: {
21
- list: (values_0: DataArkListTip, values_1: DataArkListContent) => DataArkList;
22
- listTip: (options: DataArkListTip["value"]) => DataArkListTip;
23
- listContent: (...values: DataArkListContent["value"]) => DataArkListContent;
24
- listItem: (value: DataArkListItem["value"]) => DataArkListItem;
25
- Card: (value: DataArkCard["value"]) => DataArkCard;
26
- BigCard: (value: DataArkBigCard["value"]) => DataArkBigCard;
27
- };
28
- declare const MD: {
29
- (...values: DataMarkDown["value"]): DataMarkDown;
30
- template(templateId: DataMarkdownTemplate["value"], params?: DataMarkdownTemplate["options"]["params"]): DataMarkdownTemplate;
31
- text(text: string): DataMarkdownText;
32
- title(text: string): DataMarkdownTitle;
33
- subtitle(text: string): DataMarkdownSubtitle;
34
- bold(text: string): DataMarkdownBold;
35
- italic(text: string): DataMarkdownItalic;
36
- italicStar(text: string): DataMarkdownItalicStar;
37
- strikethrough(text: string): DataMarkdownStrikethrough;
38
- link(text: string, url: string): DataMarkdownLink;
39
- image(url: string, options?: {
40
- width?: number;
41
- height?: number;
42
- }): DataMarkdownImage;
43
- list(...items: any[]): DataMarkdownList;
44
- listItem(indexOrText: number | string, text?: string): DataMarkdownListItem;
45
- blockquote(text: string): DataMarkdownBlockquote;
46
- divider(): DataMarkdownDivider;
47
- newline(value?: boolean): DataMarkdownNewline;
48
- code(value: DataMarkdownCode["value"], options?: DataMarkdownCode["options"]): DataMarkdownCode;
49
- };
50
- export { MD };
1
+ import { DataButtonGroup, DataMarkDown, DataEnums, EventKeys, Events } from '../types';
2
+ import { Text, Link, Image, ImageFile, ImageURL, Mention, BT, MD } from './message-format-old.js';
3
+ export * from './message-format-old.js';
4
+ declare class FormatButtonGroup {
5
+ #private;
6
+ get value(): DataButtonGroup;
7
+ addRow(): this;
8
+ addButton(...args: Parameters<typeof BT>): this;
9
+ clear(): this;
10
+ }
11
+ declare class FormatMarkDown {
12
+ #private;
13
+ get value(): DataMarkDown;
14
+ addText(...args: Parameters<typeof MD.text>): this;
15
+ addTitle(...args: Parameters<typeof MD.title>): this;
16
+ addSubtitle(...args: Parameters<typeof MD.subtitle>): this;
17
+ addBold(...args: Parameters<typeof MD.bold>): this;
18
+ addItalic(...args: Parameters<typeof MD.italic>): this;
19
+ addItalicStar(...args: Parameters<typeof MD.italicStar>): this;
20
+ addStrikethrough(...args: Parameters<typeof MD.strikethrough>): this;
21
+ addLink(...args: Parameters<typeof MD.link>): this;
22
+ addImage(...args: Parameters<typeof MD.image>): this;
23
+ addList(...args: Parameters<typeof MD.list>): this;
24
+ addBlockquote(...args: Parameters<typeof MD.blockquote>): this;
25
+ addDivider(): this;
26
+ addNewline(...args: Parameters<typeof MD.newline>): this;
27
+ addCode(...args: Parameters<typeof MD.code>): this;
28
+ addBreak(): this;
29
+ clear(): this;
30
+ }
51
31
  export declare class Format {
52
32
  #private;
53
33
  static create(): Format;
34
+ createMarkdown(): FormatMarkDown;
35
+ createButtonGroup(): FormatButtonGroup;
54
36
  get value(): DataEnums[];
55
37
  addText(...args: Parameters<typeof Text>): this;
56
38
  addTextBreak(): this;
@@ -59,10 +41,10 @@ export declare class Format {
59
41
  addImageFile(...args: Parameters<typeof ImageFile>): this;
60
42
  addImageURL(...args: Parameters<typeof ImageURL>): this;
61
43
  addMention(...args: Parameters<typeof Mention>): this;
44
+ addButtonGroup(bt: FormatButtonGroup): this;
62
45
  addButtonGroup(...args: Parameters<typeof BT.group>): this;
63
- addButtonTemplate(...args: Parameters<typeof BT.template>): this;
46
+ addMarkdown(md: FormatMarkDown): this;
64
47
  addMarkdown(...args: Parameters<typeof MD>): this;
65
- addMarkdownTemplate(...args: Parameters<typeof MD.template>): this;
66
48
  clear(): this;
67
49
  }
68
50
  export declare function createEvent<T extends EventKeys>(options: {
@@ -71,9 +53,9 @@ export declare function createEvent<T extends EventKeys>(options: {
71
53
  regular?: RegExp;
72
54
  prefix?: string;
73
55
  exact?: string;
74
- }): (Events[T] & {
56
+ }): Events[T] & {
75
57
  selects: boolean;
76
58
  regular: boolean;
77
59
  prefix: boolean;
78
60
  exact: boolean;
79
- });
61
+ };
@@ -1,223 +1,118 @@
1
- const Text = (val, options) => {
2
- return {
3
- type: 'Text',
4
- value: val,
5
- options
6
- };
7
- };
8
- const Link = (val, options) => {
9
- return {
10
- type: 'Text',
11
- value: val,
12
- options
13
- };
14
- };
15
- const ImageURL = (val) => {
16
- return {
17
- type: 'ImageURL',
18
- value: val
19
- };
20
- };
21
- const ImageFile = (val) => {
22
- return {
23
- type: 'ImageFile',
24
- value: val
25
- };
26
- };
27
- const Image = (val) => {
28
- return {
29
- type: 'Image',
30
- value: val.toString('base64')
31
- };
32
- };
33
- Image.url = ImageURL;
34
- Image.file = ImageFile;
35
- const Mention = (UserId, options) => {
36
- return {
37
- type: 'Mention',
38
- value: UserId,
39
- options: options ?? {
40
- belong: 'user'
41
- }
42
- };
43
- };
44
- const BT = (title, data, options) => {
45
- return {
46
- type: 'Button',
47
- value: title,
48
- options: {
49
- data,
50
- ...options
1
+ import { Text, Link, Image, ImageFile, ImageURL, Mention, BT, MD } from './message-format-old.js';
2
+ export { Ark } from './message-format-old.js';
3
+
4
+ class FormatButtonGroup {
5
+ #rows = [];
6
+ #currentRow = null;
7
+ get value() {
8
+ this.#flush();
9
+ return BT.group(...this.#rows);
10
+ }
11
+ #flush() {
12
+ if (this.#currentRow && this.#currentRow.length > 0) {
13
+ this.#rows.push(BT.row(...this.#currentRow));
14
+ this.#currentRow = null;
51
15
  }
52
- };
53
- };
54
- BT.group = function Group(...rows) {
55
- return {
56
- type: 'BT.group',
57
- value: rows
58
- };
59
- };
60
- BT.template = function Template(templateId) {
61
- return {
62
- type: 'ButtonTemplate',
63
- value: templateId
64
- };
65
- };
66
- BT.row = function Row(...buttons) {
67
- return {
68
- type: 'BT.row',
69
- value: buttons
70
- };
71
- };
72
- const Ark = {
73
- list: (...values) => {
74
- return {
75
- type: 'Ark.list',
76
- value: values
77
- };
78
- },
79
- listTip: (options) => {
80
- return {
81
- type: 'Ark.listTip',
82
- value: options
83
- };
84
- },
85
- listContent: (...values) => {
86
- return {
87
- type: 'Ark.listContent',
88
- value: values
89
- };
90
- },
91
- listItem: (value) => {
92
- return {
93
- type: 'Ark.listItem',
94
- value: value
95
- };
96
- },
97
- Card: (value) => {
98
- return {
99
- type: 'Ark.Card',
100
- value: value
101
- };
102
- },
103
- BigCard: (value) => {
104
- return {
105
- type: 'Ark.BigCard',
106
- value
107
- };
108
- }
109
- };
110
- const MD = (...values) => {
111
- return {
112
- type: 'Markdown',
113
- value: values
114
- };
115
- };
116
- MD.template = (templateId, params) => {
117
- return {
118
- type: 'MarkdownTemplate',
119
- value: templateId,
120
- options: {
121
- params
16
+ }
17
+ addRow() {
18
+ this.#flush();
19
+ this.#currentRow = [];
20
+ return this;
21
+ }
22
+ addButton(...args) {
23
+ if (!this.#currentRow) {
24
+ this.#currentRow = [];
122
25
  }
123
- };
124
- };
125
- MD.text = (text) => {
126
- return {
127
- type: 'MD.text',
128
- value: text
129
- };
130
- };
131
- MD.title = (text) => {
132
- return {
133
- type: 'MD.title',
134
- value: text
135
- };
136
- };
137
- MD.subtitle = (text) => {
138
- return {
139
- type: 'MD.subtitle',
140
- value: text
141
- };
142
- };
143
- MD.bold = (text) => {
144
- return {
145
- type: 'MD.bold',
146
- value: text
147
- };
148
- };
149
- MD.italic = (text) => {
150
- return {
151
- type: 'MD.italic',
152
- value: text
153
- };
154
- };
155
- MD.italicStar = (text) => {
156
- return {
157
- type: 'MD.italicStar',
158
- value: text
159
- };
160
- };
161
- MD.strikethrough = (text) => {
162
- return {
163
- type: 'MD.strikethrough',
164
- value: text
165
- };
166
- };
167
- MD.link = (text, url) => {
168
- return {
169
- type: 'MD.link',
170
- value: { text, url }
171
- };
172
- };
173
- MD.image = (url, options) => {
174
- return {
175
- type: 'MD.image',
176
- value: url,
177
- options
178
- };
179
- };
180
- MD.list = (...items) => {
181
- return {
182
- type: 'MD.list',
183
- value: items
184
- };
185
- };
186
- MD.listItem = (indexOrText, text) => {
187
- return {
188
- type: 'MD.listItem',
189
- value: typeof indexOrText === 'number' ? { index: indexOrText, text } : indexOrText
190
- };
191
- };
192
- MD.blockquote = (text) => {
193
- return {
194
- type: 'MD.blockquote',
195
- value: text
196
- };
197
- };
198
- MD.divider = () => {
199
- return {
200
- type: 'MD.divider'
201
- };
202
- };
203
- MD.newline = (value = false) => {
204
- return {
205
- type: 'MD.newline',
206
- value: value
207
- };
208
- };
209
- MD.code = (value, options) => {
210
- return {
211
- type: 'MD.code',
212
- value: value,
213
- options: options
214
- };
215
- };
26
+ this.#currentRow.push(BT(...args));
27
+ return this;
28
+ }
29
+ clear() {
30
+ this.#rows = [];
31
+ this.#currentRow = null;
32
+ return this;
33
+ }
34
+ }
35
+ class FormatMarkDown {
36
+ #data = [];
37
+ get value() {
38
+ return MD(...this.#data);
39
+ }
40
+ addText(...args) {
41
+ this.#data.push(MD.text(...args));
42
+ return this;
43
+ }
44
+ addTitle(...args) {
45
+ this.#data.push(MD.title(...args));
46
+ return this;
47
+ }
48
+ addSubtitle(...args) {
49
+ this.#data.push(MD.subtitle(...args));
50
+ return this;
51
+ }
52
+ addBold(...args) {
53
+ this.#data.push(MD.bold(...args));
54
+ return this;
55
+ }
56
+ addItalic(...args) {
57
+ this.#data.push(MD.italic(...args));
58
+ return this;
59
+ }
60
+ addItalicStar(...args) {
61
+ this.#data.push(MD.italicStar(...args));
62
+ return this;
63
+ }
64
+ addStrikethrough(...args) {
65
+ this.#data.push(MD.strikethrough(...args));
66
+ return this;
67
+ }
68
+ addLink(...args) {
69
+ this.#data.push(MD.link(...args));
70
+ return this;
71
+ }
72
+ addImage(...args) {
73
+ this.#data.push(MD.image(...args));
74
+ return this;
75
+ }
76
+ addList(...args) {
77
+ this.#data.push(MD.list(...args));
78
+ return this;
79
+ }
80
+ addBlockquote(...args) {
81
+ this.#data.push(MD.blockquote(...args));
82
+ return this;
83
+ }
84
+ addDivider() {
85
+ this.#data.push(MD.divider());
86
+ return this;
87
+ }
88
+ addNewline(...args) {
89
+ this.#data.push(MD.newline(...args));
90
+ return this;
91
+ }
92
+ addCode(...args) {
93
+ this.#data.push(MD.code(...args));
94
+ return this;
95
+ }
96
+ addBreak() {
97
+ this.#data.push(MD.newline());
98
+ return this;
99
+ }
100
+ clear() {
101
+ this.#data = [];
102
+ return this;
103
+ }
104
+ }
216
105
  class Format {
217
106
  #data = [];
218
107
  static create() {
219
108
  return new Format();
220
109
  }
110
+ createMarkdown() {
111
+ return new FormatMarkDown();
112
+ }
113
+ createButtonGroup() {
114
+ return new FormatButtonGroup();
115
+ }
221
116
  get value() {
222
117
  return this.#data;
223
118
  }
@@ -250,19 +145,21 @@ class Format {
250
145
  return this;
251
146
  }
252
147
  addButtonGroup(...args) {
253
- this.#data.push(BT.group(...args));
254
- return this;
255
- }
256
- addButtonTemplate(...args) {
257
- this.#data.push(BT.template(...args));
148
+ if (args[0] instanceof FormatButtonGroup) {
149
+ this.#data.push(args[0].value);
150
+ }
151
+ else {
152
+ this.#data.push(BT.group(...args));
153
+ }
258
154
  return this;
259
155
  }
260
156
  addMarkdown(...args) {
261
- this.#data.push(MD(...args));
262
- return this;
263
- }
264
- addMarkdownTemplate(...args) {
265
- this.#data.push(MD.template(...args));
157
+ if (args[0] instanceof FormatMarkDown) {
158
+ this.#data.push(args[0].value);
159
+ }
160
+ else {
161
+ this.#data.push(MD(...args));
162
+ }
266
163
  return this;
267
164
  }
268
165
  clear() {
@@ -295,4 +192,4 @@ function createEvent(options) {
295
192
  return { ...event, ...o };
296
193
  }
297
194
 
298
- export { Ark, BT, Format, Image, ImageFile, ImageURL, Link, MD, Mention, Text, createEvent };
195
+ export { BT, Format, Image, ImageFile, ImageURL, Link, MD, Mention, Text, createEvent };
@@ -0,0 +1,50 @@
1
+ import { DataMention, DataImage, DataText, DataImageURL, DataImageFile, ButtonRow, DataButtonGroup, DataButton, DataArkList, DataArkListTip, DataArkListContent, DataArkListItem, DataArkCard, DataArkBigCard, DataMarkdownTemplate, DataMarkDown, DataMarkdownTitle, DataMarkdownSubtitle, DataMarkdownBold, DataMarkdownItalic, DataMarkdownItalicStar, DataMarkdownStrikethrough, DataMarkdownLink, DataMarkdownImage, DataMarkdownList, DataMarkdownListItem, DataMarkdownBlockquote, DataMarkdownDivider, DataMarkdownNewline, DataLink, DataMarkdownText, DataButtonTemplate, DataMarkdownCode } from '../types';
2
+ export declare const Text: (val: DataText["value"], options?: DataText["options"]) => DataText;
3
+ export declare const Link: (val: DataLink["value"], options?: DataText["options"]) => DataText;
4
+ export declare const ImageURL: (val: DataImageURL["value"]) => DataImageURL;
5
+ export declare const ImageFile: (val: DataImageFile["value"]) => DataImageFile;
6
+ declare const Image: {
7
+ (val: Buffer): DataImage;
8
+ url: (val: DataImageURL["value"]) => DataImageURL;
9
+ file: (val: DataImageFile["value"]) => DataImageFile;
10
+ };
11
+ export { Image };
12
+ export declare const Mention: (UserId?: DataMention["value"], options?: DataMention["options"]) => DataMention;
13
+ declare const BT: {
14
+ (title: string, data: DataButton["options"]["data"], options?: Omit<DataButton["options"], "data">): DataButton;
15
+ group(...rows: ButtonRow[]): DataButtonGroup;
16
+ template(templateId: DataButtonTemplate["value"]): DataButtonTemplate;
17
+ row(...buttons: DataButton[]): ButtonRow;
18
+ };
19
+ export { BT };
20
+ export declare const Ark: {
21
+ list: (values_0: DataArkListTip, values_1: DataArkListContent) => DataArkList;
22
+ listTip: (options: DataArkListTip["value"]) => DataArkListTip;
23
+ listContent: (...values: DataArkListContent["value"]) => DataArkListContent;
24
+ listItem: (value: DataArkListItem["value"]) => DataArkListItem;
25
+ Card: (value: DataArkCard["value"]) => DataArkCard;
26
+ BigCard: (value: DataArkBigCard["value"]) => DataArkBigCard;
27
+ };
28
+ declare const MD: {
29
+ (...values: DataMarkDown["value"]): DataMarkDown;
30
+ template(templateId: DataMarkdownTemplate["value"], params?: DataMarkdownTemplate["options"]["params"]): DataMarkdownTemplate;
31
+ text(text: string): DataMarkdownText;
32
+ title(text: string): DataMarkdownTitle;
33
+ subtitle(text: string): DataMarkdownSubtitle;
34
+ bold(text: string): DataMarkdownBold;
35
+ italic(text: string): DataMarkdownItalic;
36
+ italicStar(text: string): DataMarkdownItalicStar;
37
+ strikethrough(text: string): DataMarkdownStrikethrough;
38
+ link(text: string, url: string): DataMarkdownLink;
39
+ image(url: string, options?: {
40
+ width?: number;
41
+ height?: number;
42
+ }): DataMarkdownImage;
43
+ list(...items: any[]): DataMarkdownList;
44
+ listItem(indexOrText: number | string, text?: string): DataMarkdownListItem;
45
+ blockquote(text: string): DataMarkdownBlockquote;
46
+ divider(): DataMarkdownDivider;
47
+ newline(value?: boolean): DataMarkdownNewline;
48
+ code(value: DataMarkdownCode["value"], options?: DataMarkdownCode["options"]): DataMarkdownCode;
49
+ };
50
+ export { MD };
@@ -0,0 +1,217 @@
1
+ const Text = (val, options) => {
2
+ return {
3
+ type: 'Text',
4
+ value: val,
5
+ options
6
+ };
7
+ };
8
+ const Link = (val, options) => {
9
+ return {
10
+ type: 'Text',
11
+ value: val,
12
+ options
13
+ };
14
+ };
15
+ const ImageURL = (val) => {
16
+ return {
17
+ type: 'ImageURL',
18
+ value: val
19
+ };
20
+ };
21
+ const ImageFile = (val) => {
22
+ return {
23
+ type: 'ImageFile',
24
+ value: val
25
+ };
26
+ };
27
+ const Image = (val) => {
28
+ return {
29
+ type: 'Image',
30
+ value: val.toString('base64')
31
+ };
32
+ };
33
+ Image.url = ImageURL;
34
+ Image.file = ImageFile;
35
+ const Mention = (UserId, options) => {
36
+ return {
37
+ type: 'Mention',
38
+ value: UserId,
39
+ options: options ?? {
40
+ belong: 'user'
41
+ }
42
+ };
43
+ };
44
+ const BT = (title, data, options) => {
45
+ return {
46
+ type: 'Button',
47
+ value: title,
48
+ options: {
49
+ data,
50
+ ...options
51
+ }
52
+ };
53
+ };
54
+ BT.group = function Group(...rows) {
55
+ return {
56
+ type: 'BT.group',
57
+ value: rows
58
+ };
59
+ };
60
+ BT.template = function Template(templateId) {
61
+ return {
62
+ type: 'ButtonTemplate',
63
+ value: templateId
64
+ };
65
+ };
66
+ BT.row = function Row(...buttons) {
67
+ return {
68
+ type: 'BT.row',
69
+ value: buttons
70
+ };
71
+ };
72
+ const Ark = {
73
+ list: (...values) => {
74
+ return {
75
+ type: 'Ark.list',
76
+ value: values
77
+ };
78
+ },
79
+ listTip: (options) => {
80
+ return {
81
+ type: 'Ark.listTip',
82
+ value: options
83
+ };
84
+ },
85
+ listContent: (...values) => {
86
+ return {
87
+ type: 'Ark.listContent',
88
+ value: values
89
+ };
90
+ },
91
+ listItem: (value) => {
92
+ return {
93
+ type: 'Ark.listItem',
94
+ value: value
95
+ };
96
+ },
97
+ Card: (value) => {
98
+ return {
99
+ type: 'Ark.Card',
100
+ value: value
101
+ };
102
+ },
103
+ BigCard: (value) => {
104
+ return {
105
+ type: 'Ark.BigCard',
106
+ value
107
+ };
108
+ }
109
+ };
110
+ const MD = (...values) => {
111
+ return {
112
+ type: 'Markdown',
113
+ value: values
114
+ };
115
+ };
116
+ MD.template = (templateId, params) => {
117
+ return {
118
+ type: 'MarkdownTemplate',
119
+ value: templateId,
120
+ options: {
121
+ params
122
+ }
123
+ };
124
+ };
125
+ MD.text = (text) => {
126
+ return {
127
+ type: 'MD.text',
128
+ value: text
129
+ };
130
+ };
131
+ MD.title = (text) => {
132
+ return {
133
+ type: 'MD.title',
134
+ value: text
135
+ };
136
+ };
137
+ MD.subtitle = (text) => {
138
+ return {
139
+ type: 'MD.subtitle',
140
+ value: text
141
+ };
142
+ };
143
+ MD.bold = (text) => {
144
+ return {
145
+ type: 'MD.bold',
146
+ value: text
147
+ };
148
+ };
149
+ MD.italic = (text) => {
150
+ return {
151
+ type: 'MD.italic',
152
+ value: text
153
+ };
154
+ };
155
+ MD.italicStar = (text) => {
156
+ return {
157
+ type: 'MD.italicStar',
158
+ value: text
159
+ };
160
+ };
161
+ MD.strikethrough = (text) => {
162
+ return {
163
+ type: 'MD.strikethrough',
164
+ value: text
165
+ };
166
+ };
167
+ MD.link = (text, url) => {
168
+ return {
169
+ type: 'MD.link',
170
+ value: { text, url }
171
+ };
172
+ };
173
+ MD.image = (url, options) => {
174
+ return {
175
+ type: 'MD.image',
176
+ value: url,
177
+ options
178
+ };
179
+ };
180
+ MD.list = (...items) => {
181
+ return {
182
+ type: 'MD.list',
183
+ value: items
184
+ };
185
+ };
186
+ MD.listItem = (indexOrText, text) => {
187
+ return {
188
+ type: 'MD.listItem',
189
+ value: typeof indexOrText === 'number' ? { index: indexOrText, text } : indexOrText
190
+ };
191
+ };
192
+ MD.blockquote = (text) => {
193
+ return {
194
+ type: 'MD.blockquote',
195
+ value: text
196
+ };
197
+ };
198
+ MD.divider = () => {
199
+ return {
200
+ type: 'MD.divider'
201
+ };
202
+ };
203
+ MD.newline = (value = false) => {
204
+ return {
205
+ type: 'MD.newline',
206
+ value: value
207
+ };
208
+ };
209
+ MD.code = (value, options) => {
210
+ return {
211
+ type: 'MD.code',
212
+ value: value,
213
+ options: options
214
+ };
215
+ };
216
+
217
+ export { Ark, BT, Image, ImageFile, ImageURL, Link, MD, Mention, Text };
@@ -15,7 +15,7 @@ import '../../app/event-response.js';
15
15
  import { createResult } from '../../core/utils.js';
16
16
  import '../../app/hook-use-api.js';
17
17
  import '../../app/message-api.js';
18
- import '../../app/message-format.js';
18
+ import '../../app/message-format-old.js';
19
19
  import { apiResolves, apiTimeouts, actionResolves, actionTimeouts, FULL_RECEIVE_HEADER } from '../processor/config.js';
20
20
  import { createWSConnector } from './base.js';
21
21
 
package/lib/client.js CHANGED
@@ -25,7 +25,7 @@ import './app/event-processor.js';
25
25
  import './app/event-response.js';
26
26
  import './app/hook-use-api.js';
27
27
  import './app/message-api.js';
28
- import './app/message-format.js';
28
+ import './app/message-format-old.js';
29
29
  import './process/platform.js';
30
30
  import './process/module.js';
31
31
  import { createServer } from './server/main.js';
package/lib/index.js CHANGED
@@ -25,5 +25,6 @@ export { createSelects, onSelects, unChildren, useChannel, useClient, useMe, use
25
25
  export { onState, unState, useState } from './app/hook-use-state.js';
26
26
  export { useObserver, useSubscribe } from './app/hook-use-subscribe.js';
27
27
  export { createDataFormat, createEventValue, format, getMessageIntent, sendToChannel, sendToUser } from './app/message-api.js';
28
- export { Ark, BT, Format, Image, ImageFile, ImageURL, Link, MD, Mention, Text, createEvent } from './app/message-format.js';
28
+ export { Format, createEvent } from './app/message-format.js';
29
29
  export { start } from './main.js';
30
+ export { Ark, BT, Image, ImageFile, ImageURL, Link, MD, Mention, Text } from './app/message-format-old.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "alemonjs",
3
- "version": "2.1.19",
3
+ "version": "2.1.21",
4
4
  "description": "bot script",
5
5
  "author": "lemonade",
6
6
  "license": "MIT",