alemonjs 2.1.57 → 2.1.59

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.
@@ -7,7 +7,6 @@ import 'path';
7
7
  import 'yaml';
8
8
  import '../../cbp/processor/config.js';
9
9
  import { sendAPI } from '../../cbp/processor/api.js';
10
- import '../message-format-old.js';
11
10
  import { getCurrentEvent } from '../hook-event-context.js';
12
11
 
13
12
  const createDeepProxy = (event, path = []) => {
@@ -7,7 +7,6 @@ import 'path';
7
7
  import 'yaml';
8
8
  import '../../cbp/processor/config.js';
9
9
  import 'flatted';
10
- import '../message-format-old.js';
11
10
  import '../hook-event-context.js';
12
11
 
13
12
  const useMe = () => {
@@ -7,7 +7,6 @@ import 'path';
7
7
  import 'yaml';
8
8
  import '../../cbp/processor/config.js';
9
9
  import 'flatted';
10
- import '../message-format-old.js';
11
10
  import '../hook-event-context.js';
12
11
 
13
12
  const useRequest = () => {
@@ -7,7 +7,6 @@ import 'path';
7
7
  import 'yaml';
8
8
  import '../../cbp/processor/config.js';
9
9
  import 'flatted';
10
- import '../message-format-old.js';
11
10
  import '../hook-event-context.js';
12
11
 
13
12
  const useUser = () => {
package/lib/app/index.js CHANGED
@@ -38,5 +38,4 @@ export { getCurrentEvent, getCurrentNext, withEventContext } from './hook-event-
38
38
  export { registerAppDir, scheduleCancel, scheduleCancelAll, scheduleCancelByApp, scheduleCron, scheduleInterval, scheduleList, schedulePause, scheduleResume, scheduleTimeout, unregisterAppDir } from './schedule-store.js';
39
39
  export { createEventValue, createSelects, onSelects, onState, unChildren, unState, useState } from './event-utils.js';
40
40
  export { MessageDirect, createDataFormat, format, getMessageIntent, sendToChannel, sendToUser } from './message-api.js';
41
- export { Format, FormatButtonGroup, FormatMarkDown } from './message-format.js';
42
- export { Attachment, Audio, BT, Button, Image, ImageFile, ImageURL, Link, MD, Markdown, MarkdownOriginal, Mention, Text, Video } from './message-format-old.js';
41
+ export { Format, FormatButtonGroup, FormatMarkDown, FormatModal, FormatSelect } from './message-format.js';
@@ -1,4 +1,5 @@
1
1
  import { DataMention, DataImage, DataText, DataImageURL, DataImageFile, DataButtonRow, DataButtonGroup, DataButton, DataMarkDown, DataMarkdownTitle, DataMarkdownSubtitle, DataMarkdownBold, DataMarkdownItalic, DataMarkdownItalicStar, DataMarkdownStrikethrough, DataMarkdownLink, DataMarkdownImage, DataMarkdownList, DataMarkdownListItem, DataMarkdownBlockquote, DataMarkdownDivider, DataMarkdownNewline, DataLink, DataMarkdownText, DataMarkdownCode, DataMarkdownOriginal, DataAttachment, DataAudio, DataVideo, DataMarkdownMention, DataMarkdownContent, DataMarkdownButton } from '../types';
2
+ import { Format, FormatMarkDown, FormatButtonGroup } from './message-format.js';
2
3
  export declare const Text: (val: DataText["value"], options?: DataText["options"]) => DataText;
3
4
  export declare const Link: (val: DataLink["value"], options?: DataText["options"]) => DataText;
4
5
  export declare const ImageURL: (val: DataImageURL["value"]) => DataImageURL;
@@ -73,3 +74,4 @@ export declare const MarkdownOriginal: (val: string) => DataMarkdownOriginal;
73
74
  export declare const Attachment: (val: string, options?: DataAttachment["options"]) => DataAttachment;
74
75
  export declare const Audio: (val: string) => DataAudio;
75
76
  export declare const Video: (val: string) => DataVideo;
77
+ export { Format, FormatMarkDown, FormatButtonGroup };
@@ -1,61 +1,32 @@
1
+ import { Format } from './message-format.js';
2
+ export { FormatButtonGroup, FormatMarkDown } from './message-format.js';
3
+
1
4
  const Text = (val, options) => {
2
- return {
3
- type: 'Text',
4
- value: val,
5
- options
6
- };
5
+ return Format.create().addText(val, options).value[0];
7
6
  };
8
7
  const Link = (val, options) => {
9
- return {
10
- type: 'Text',
11
- value: val,
12
- options
13
- };
8
+ return Format.create().addLink(val, options).value[0];
14
9
  };
15
10
  const ImageURL = (val) => {
16
- return {
17
- type: 'ImageURL',
18
- value: val
19
- };
11
+ return Format.create().addImageURL(val).value[0];
20
12
  };
21
13
  const ImageFile = (val) => {
22
- return {
23
- type: 'ImageFile',
24
- value: val
25
- };
14
+ return Format.create().addImageFile(val).value[0];
26
15
  };
27
16
  const Image = (val) => {
28
- return {
29
- type: 'Image',
30
- value: typeof val === 'string' ? val : `base64://${val.toString('base64')}`
31
- };
17
+ return Format.create().addImage(val).value[0];
32
18
  };
33
19
  Image.url = ImageURL;
34
20
  Image.file = ImageFile;
35
21
  const Mention = (UserId, options) => {
36
- return {
37
- type: 'Mention',
38
- value: UserId,
39
- options: options ?? {
40
- belong: 'user'
41
- }
42
- };
22
+ return Format.create().addMention(UserId, options).value[0];
43
23
  };
44
24
  const Button = (title, data, options) => {
45
- return {
46
- type: 'Button',
47
- value: title,
48
- options: {
49
- data,
50
- ...options
51
- }
52
- };
25
+ const group = Format.createButtonGroup().addButton(title, data, options).value;
26
+ return group.value[0].value[0];
53
27
  };
54
28
  const ButtonGroup = (...rows) => {
55
- return {
56
- type: 'BT.group',
57
- value: rows
58
- };
29
+ return Format.create().addButtonGroup(...rows).value[0];
59
30
  };
60
31
  const ButtonRow = (...buttons) => {
61
32
  return {
@@ -67,93 +38,46 @@ Button.group = ButtonGroup;
67
38
  Button.row = ButtonRow;
68
39
  const BT = Button;
69
40
  const Markdown = (...values) => {
70
- return {
71
- type: 'Markdown',
72
- value: values
73
- };
41
+ return Format.create().addMarkdown(...values).value[0];
74
42
  };
75
43
  Markdown.text = (text) => {
76
- return {
77
- type: 'MD.text',
78
- value: text
79
- };
44
+ return Format.createMarkdown().addText(text).value.value[0];
80
45
  };
81
46
  Markdown.mention = (uid, options) => {
82
- return {
83
- type: 'MD.mention',
84
- value: uid || 'everyone',
85
- options: options ?? {
86
- belong: 'user'
87
- }
88
- };
47
+ return Format.createMarkdown().addMention(uid, options).value.value[0];
89
48
  };
90
49
  Markdown.button = (title, data) => {
91
- return {
92
- type: 'MD.button',
93
- value: title,
94
- options: data
95
- };
50
+ return Format.createMarkdown().addButton(title, data).value.value[0];
96
51
  };
97
52
  Markdown.content = (text) => {
98
- return {
99
- type: 'MD.content',
100
- value: text
101
- };
53
+ return Format.createMarkdown().addContent(text).value.value[0];
102
54
  };
103
55
  Markdown.title = (text) => {
104
- return {
105
- type: 'MD.title',
106
- value: text
107
- };
56
+ return Format.createMarkdown().addTitle(text).value.value[0];
108
57
  };
109
58
  Markdown.subtitle = (text) => {
110
- return {
111
- type: 'MD.subtitle',
112
- value: text
113
- };
59
+ return Format.createMarkdown().addSubtitle(text).value.value[0];
114
60
  };
115
61
  Markdown.bold = (text) => {
116
- return {
117
- type: 'MD.bold',
118
- value: text
119
- };
62
+ return Format.createMarkdown().addBold(text).value.value[0];
120
63
  };
121
64
  Markdown.italic = (text) => {
122
- return {
123
- type: 'MD.italic',
124
- value: text
125
- };
65
+ return Format.createMarkdown().addItalic(text).value.value[0];
126
66
  };
127
67
  Markdown.italicStar = (text) => {
128
- return {
129
- type: 'MD.italicStar',
130
- value: text
131
- };
68
+ return Format.createMarkdown().addItalicStar(text).value.value[0];
132
69
  };
133
70
  Markdown.strikethrough = (text) => {
134
- return {
135
- type: 'MD.strikethrough',
136
- value: text
137
- };
71
+ return Format.createMarkdown().addStrikethrough(text).value.value[0];
138
72
  };
139
73
  Markdown.link = (text, url) => {
140
- return {
141
- type: 'MD.link',
142
- value: { text, url }
143
- };
74
+ return Format.createMarkdown().addLink(text, url).value.value[0];
144
75
  };
145
76
  Markdown.image = (url, options) => {
146
- return {
147
- type: 'MD.image',
148
- value: url,
149
- options
150
- };
77
+ return Format.createMarkdown().addImage(url, options).value.value[0];
151
78
  };
152
79
  Markdown.list = (...items) => {
153
- return {
154
- type: 'MD.list',
155
- value: items
156
- };
80
+ return Format.createMarkdown().addList(...items).value.value[0];
157
81
  };
158
82
  Markdown.listItem = (indexOrText, text) => {
159
83
  return {
@@ -162,54 +86,29 @@ Markdown.listItem = (indexOrText, text) => {
162
86
  };
163
87
  };
164
88
  Markdown.blockquote = (text) => {
165
- return {
166
- type: 'MD.blockquote',
167
- value: text
168
- };
89
+ return Format.createMarkdown().addBlockquote(text).value.value[0];
169
90
  };
170
91
  Markdown.divider = () => {
171
- return {
172
- type: 'MD.divider'
173
- };
92
+ return Format.createMarkdown().addDivider().value.value[0];
174
93
  };
175
94
  Markdown.newline = (value = false) => {
176
- return {
177
- type: 'MD.newline',
178
- value: value
179
- };
95
+ return Format.createMarkdown().addNewline(value).value.value[0];
180
96
  };
181
97
  Markdown.code = (value, options) => {
182
- return {
183
- type: 'MD.code',
184
- value: value,
185
- options: options
186
- };
98
+ return Format.createMarkdown().addCode(value, options).value.value[0];
187
99
  };
188
100
  const MD = Markdown;
189
101
  const MarkdownOriginal = (val) => {
190
- return {
191
- type: 'MarkdownOriginal',
192
- value: val
193
- };
102
+ return Format.create().addMarkdownOriginal(val).value[0];
194
103
  };
195
104
  const Attachment = (val, options) => {
196
- return {
197
- type: 'Attachment',
198
- value: val,
199
- options
200
- };
105
+ return Format.create().addAttachment(val, options).value[0];
201
106
  };
202
107
  const Audio = (val) => {
203
- return {
204
- type: 'Audio',
205
- value: val
206
- };
108
+ return Format.create().addAudio(val).value[0];
207
109
  };
208
110
  const Video = (val) => {
209
- return {
210
- type: 'Video',
211
- value: val
212
- };
111
+ return Format.create().addVideo(val).value[0];
213
112
  };
214
113
 
215
- export { Attachment, Audio, BT, Button, Image, ImageFile, ImageURL, Link, MD, Markdown, MarkdownOriginal, Mention, Text, Video };
114
+ export { Attachment, Audio, BT, Button, Format, Image, ImageFile, ImageURL, Link, MD, Markdown, MarkdownOriginal, Mention, Text, Video };
@@ -1,36 +1,56 @@
1
- import { DataButtonGroup, DataMarkDown, DataEnums } from '../types';
2
- import { Text, Image, Link, ImageFile, ImageURL, Mention, BT, MD, MarkdownOriginal, Attachment, Audio, Video } from './message-format-old.js';
3
- export * from './message-format-old.js';
1
+ import { DataMention, DataText, DataImageURL, DataImageFile, DataButtonRow, DataButtonGroup, DataButton, DataMarkDown, DataLink, DataMarkdownCode, DataAttachment, DataMarkdownMention, DataMarkdownButton, DataEnums, DataSelect, DataSelectOption, DataModal, DataTextInput, DataEmbed } from '../types';
4
2
  export declare class FormatButtonGroup {
5
3
  #private;
6
4
  get value(): DataButtonGroup;
7
5
  absorb(group: FormatButtonGroup): this;
8
6
  addRow(): this;
9
- addButton(...args: Parameters<typeof BT>): this;
7
+ addButton(title: string, data: DataButton['options']['data'], options?: Omit<DataButton['options'], 'data'>): this;
10
8
  clear(): this;
11
9
  }
12
10
  export declare class FormatMarkDown {
13
11
  #private;
14
12
  get value(): DataMarkDown;
15
13
  absorb(md: FormatMarkDown): this;
16
- addContent(...args: Parameters<typeof MD.content>): this;
17
- addText(...args: Parameters<typeof MD.text>): this;
18
- addTitle(...args: Parameters<typeof MD.title>): this;
19
- addSubtitle(...args: Parameters<typeof MD.subtitle>): this;
20
- addBold(...args: Parameters<typeof MD.bold>): this;
21
- addItalic(...args: Parameters<typeof MD.italic>): this;
22
- addItalicStar(...args: Parameters<typeof MD.italicStar>): this;
23
- addStrikethrough(...args: Parameters<typeof MD.strikethrough>): this;
24
- addLink(...args: Parameters<typeof MD.link>): this;
25
- addImage(...args: Parameters<typeof MD.image>): this;
26
- addList(...args: Parameters<typeof MD.list>): this;
27
- addBlockquote(...args: Parameters<typeof MD.blockquote>): this;
14
+ addContent(text: string): this;
15
+ addText(text: string): this;
16
+ addTitle(text: string): this;
17
+ addSubtitle(text: string): this;
18
+ addBold(text: string): this;
19
+ addItalic(text: string): this;
20
+ addItalicStar(text: string): this;
21
+ addStrikethrough(text: string): this;
22
+ addLink(text: string, url?: string): this;
23
+ addImage(url: string, options?: {
24
+ width?: number;
25
+ height?: number;
26
+ }): this;
27
+ addList(...items: any[]): this;
28
+ addBlockquote(text: string): this;
28
29
  addDivider(): this;
29
- addNewline(...args: Parameters<typeof MD.newline>): this;
30
- addCode(...args: Parameters<typeof MD.code>): this;
30
+ addNewline(value?: boolean): this;
31
+ addCode(value: DataMarkdownCode['value'], options?: DataMarkdownCode['options']): this;
31
32
  addBreak(): this;
32
- addMention(...args: Parameters<typeof MD.mention>): this;
33
- addButton(...args: Parameters<typeof MD.button>): this;
33
+ addMention(uid?: string, options?: DataMarkdownMention['options']): this;
34
+ addButton(title: string, data: DataMarkdownButton['options']): this;
35
+ clear(): this;
36
+ }
37
+ export declare class FormatSelect {
38
+ #private;
39
+ get value(): DataSelect;
40
+ setCustomId(customId: string): this;
41
+ setPlaceholder(placeholder: string): this;
42
+ setRange(min?: number, max?: number): this;
43
+ setKind(kind: DataSelect['options']['kind']): this;
44
+ setDisabled(disabled?: boolean): this;
45
+ addOption(label: string, value: string, extra?: Omit<DataSelectOption, 'label' | 'value'>): this;
46
+ clear(): this;
47
+ }
48
+ export declare class FormatModal {
49
+ #private;
50
+ get value(): DataModal;
51
+ setCustomId(customId: string): this;
52
+ setTitle(title: string): this;
53
+ addInput(label: string, options: DataTextInput['options']): this;
34
54
  clear(): this;
35
55
  }
36
56
  export declare class Format {
@@ -38,21 +58,28 @@ export declare class Format {
38
58
  static create(): Format;
39
59
  static createMarkdown(): FormatMarkDown;
40
60
  static createButtonGroup(): FormatButtonGroup;
61
+ static createSelect(): FormatSelect;
62
+ static createModal(): FormatModal;
41
63
  get value(): DataEnums[];
42
64
  absorb(format: Format): this;
43
- addText(...args: Parameters<typeof Text>): this;
44
- addImage(...args: Parameters<typeof Image>): this;
45
- addMention(...args: Parameters<typeof Mention>): this;
65
+ addText(val: DataText['value'], options?: DataText['options']): this;
66
+ addImage(val: Buffer | string): this;
67
+ addMention(UserId?: DataMention['value'], options?: DataMention['options']): this;
46
68
  addButtonGroup(bt: FormatButtonGroup): this;
47
- addButtonGroup(...args: Parameters<typeof BT.group>): this;
69
+ addButtonGroup(...rows: DataButtonRow[]): this;
48
70
  addMarkdown(md: FormatMarkDown): this;
49
- addMarkdown(...args: Parameters<typeof MD>): this;
50
- addMarkdownOriginal(...args: Parameters<typeof MarkdownOriginal>): this;
51
- addAttachment(...args: Parameters<typeof Attachment>): this;
52
- addAudio(...args: Parameters<typeof Audio>): this;
53
- addVideo(...args: Parameters<typeof Video>): this;
54
- addLink(...args: Parameters<typeof Link>): this;
55
- addImageFile(...args: Parameters<typeof ImageFile>): this;
56
- addImageURL(...args: Parameters<typeof ImageURL>): this;
71
+ addMarkdown(...values: DataMarkDown['value']): this;
72
+ addMarkdownOriginal(val: string): this;
73
+ addAttachment(val: string, options?: DataAttachment['options']): this;
74
+ addAudio(val: string): this;
75
+ addVideo(val: string): this;
76
+ addLink(val: DataLink['value'], options?: DataText['options']): this;
77
+ addImageFile(val: DataImageFile['value']): this;
78
+ addImageURL(val: DataImageURL['value']): this;
79
+ addSelect(select: FormatSelect): this;
80
+ addSelect(options: DataSelectOption[], meta?: DataSelect['options']): this;
81
+ addModal(modal: FormatModal): this;
82
+ addModal(inputs: DataTextInput[], meta: DataModal['options']): this;
83
+ addEmbed(embed: DataEmbed['value']): this;
57
84
  clear(): this;
58
85
  }
@@ -1,16 +1,19 @@
1
- import { Text, Image, Mention, BT, MD, MarkdownOriginal, Attachment, Audio, Video, Link, ImageFile, ImageURL } from './message-format-old.js';
2
- export { Button, Markdown } from './message-format-old.js';
3
-
4
1
  class FormatButtonGroup {
5
2
  #rows = [];
6
3
  #currentRow = null;
7
4
  get value() {
8
5
  this.#flush();
9
- return BT.group(...this.#rows);
6
+ return {
7
+ type: 'BT.group',
8
+ value: this.#rows
9
+ };
10
10
  }
11
11
  #flush() {
12
12
  if (this.#currentRow && this.#currentRow.length > 0) {
13
- this.#rows.push(BT.row(...this.#currentRow));
13
+ this.#rows.push({
14
+ type: 'BT.row',
15
+ value: this.#currentRow
16
+ });
14
17
  this.#currentRow = null;
15
18
  }
16
19
  }
@@ -26,11 +29,18 @@ class FormatButtonGroup {
26
29
  this.#currentRow = [];
27
30
  return this;
28
31
  }
29
- addButton(...args) {
32
+ addButton(title, data, options) {
30
33
  if (!this.#currentRow) {
31
34
  this.#currentRow = [];
32
35
  }
33
- this.#currentRow.push(BT(...args));
36
+ this.#currentRow.push({
37
+ type: 'Button',
38
+ value: title,
39
+ options: {
40
+ data,
41
+ ...options
42
+ }
43
+ });
34
44
  return this;
35
45
  }
36
46
  clear() {
@@ -42,82 +52,138 @@ class FormatButtonGroup {
42
52
  class FormatMarkDown {
43
53
  #data = [];
44
54
  get value() {
45
- return MD(...this.#data);
55
+ return {
56
+ type: 'Markdown',
57
+ value: this.#data
58
+ };
46
59
  }
47
60
  absorb(md) {
48
61
  this.#data.push(...md.value.value);
49
62
  return this;
50
63
  }
51
- addContent(...args) {
52
- this.#data.push(MD.content(...args));
64
+ addContent(text) {
65
+ this.#data.push({
66
+ type: 'MD.content',
67
+ value: text
68
+ });
53
69
  return this;
54
70
  }
55
- addText(...args) {
56
- this.#data.push(MD.text(...args));
71
+ addText(text) {
72
+ this.#data.push({
73
+ type: 'MD.text',
74
+ value: text
75
+ });
57
76
  return this;
58
77
  }
59
- addTitle(...args) {
60
- this.#data.push(MD.title(...args));
78
+ addTitle(text) {
79
+ this.#data.push({
80
+ type: 'MD.title',
81
+ value: text
82
+ });
61
83
  return this;
62
84
  }
63
- addSubtitle(...args) {
64
- this.#data.push(MD.subtitle(...args));
85
+ addSubtitle(text) {
86
+ this.#data.push({
87
+ type: 'MD.subtitle',
88
+ value: text
89
+ });
65
90
  return this;
66
91
  }
67
- addBold(...args) {
68
- this.#data.push(MD.bold(...args));
92
+ addBold(text) {
93
+ this.#data.push({
94
+ type: 'MD.bold',
95
+ value: text
96
+ });
69
97
  return this;
70
98
  }
71
- addItalic(...args) {
72
- this.#data.push(MD.italic(...args));
99
+ addItalic(text) {
100
+ this.#data.push({
101
+ type: 'MD.italic',
102
+ value: text
103
+ });
73
104
  return this;
74
105
  }
75
- addItalicStar(...args) {
76
- this.#data.push(MD.italicStar(...args));
106
+ addItalicStar(text) {
107
+ this.#data.push({
108
+ type: 'MD.italicStar',
109
+ value: text
110
+ });
77
111
  return this;
78
112
  }
79
- addStrikethrough(...args) {
80
- this.#data.push(MD.strikethrough(...args));
113
+ addStrikethrough(text) {
114
+ this.#data.push({
115
+ type: 'MD.strikethrough',
116
+ value: text
117
+ });
81
118
  return this;
82
119
  }
83
- addLink(...args) {
84
- this.#data.push(MD.link(...args));
120
+ addLink(text, url) {
121
+ this.#data.push({
122
+ type: 'MD.link',
123
+ value: { text, url }
124
+ });
85
125
  return this;
86
126
  }
87
- addImage(...args) {
88
- this.#data.push(MD.image(...args));
127
+ addImage(url, options) {
128
+ this.#data.push({
129
+ type: 'MD.image',
130
+ value: url,
131
+ options
132
+ });
89
133
  return this;
90
134
  }
91
- addList(...args) {
92
- this.#data.push(MD.list(...args));
135
+ addList(...items) {
136
+ this.#data.push({
137
+ type: 'MD.list',
138
+ value: items
139
+ });
93
140
  return this;
94
141
  }
95
- addBlockquote(...args) {
96
- this.#data.push(MD.blockquote(...args));
142
+ addBlockquote(text) {
143
+ this.#data.push({
144
+ type: 'MD.blockquote',
145
+ value: text
146
+ });
97
147
  return this;
98
148
  }
99
149
  addDivider() {
100
- this.#data.push(MD.divider());
150
+ this.#data.push({
151
+ type: 'MD.divider'
152
+ });
101
153
  return this;
102
154
  }
103
- addNewline(...args) {
104
- this.#data.push(MD.newline(...args));
155
+ addNewline(value = false) {
156
+ this.#data.push({
157
+ type: 'MD.newline',
158
+ value
159
+ });
105
160
  return this;
106
161
  }
107
- addCode(...args) {
108
- this.#data.push(MD.code(...args));
162
+ addCode(value, options) {
163
+ this.#data.push({
164
+ type: 'MD.code',
165
+ value,
166
+ options
167
+ });
109
168
  return this;
110
169
  }
111
170
  addBreak() {
112
- this.#data.push(MD.newline());
113
- return this;
171
+ return this.addNewline();
114
172
  }
115
- addMention(...args) {
116
- this.#data.push(MD.mention(...args));
173
+ addMention(uid, options) {
174
+ this.#data.push({
175
+ type: 'MD.mention',
176
+ value: uid || 'everyone',
177
+ options: options ?? { belong: 'user' }
178
+ });
117
179
  return this;
118
180
  }
119
- addButton(...args) {
120
- this.#data.push(MD.button(...args));
181
+ addButton(title, data) {
182
+ this.#data.push({
183
+ type: 'MD.button',
184
+ value: title,
185
+ options: data
186
+ });
121
187
  return this;
122
188
  }
123
189
  clear() {
@@ -125,6 +191,83 @@ class FormatMarkDown {
125
191
  return this;
126
192
  }
127
193
  }
194
+ class FormatSelect {
195
+ #options = [];
196
+ #meta = {};
197
+ get value() {
198
+ return {
199
+ type: 'Select',
200
+ value: this.#options,
201
+ options: this.#meta
202
+ };
203
+ }
204
+ setCustomId(customId) {
205
+ this.#meta.customId = customId;
206
+ return this;
207
+ }
208
+ setPlaceholder(placeholder) {
209
+ this.#meta.placeholder = placeholder;
210
+ return this;
211
+ }
212
+ setRange(min, max) {
213
+ if (min !== undefined) {
214
+ this.#meta.minValues = min;
215
+ }
216
+ if (max !== undefined) {
217
+ this.#meta.maxValues = max;
218
+ }
219
+ return this;
220
+ }
221
+ setKind(kind) {
222
+ this.#meta.kind = kind;
223
+ return this;
224
+ }
225
+ setDisabled(disabled = true) {
226
+ this.#meta.disabled = disabled;
227
+ return this;
228
+ }
229
+ addOption(label, value, extra) {
230
+ this.#options.push({ label, value, ...extra });
231
+ return this;
232
+ }
233
+ clear() {
234
+ this.#options = [];
235
+ this.#meta = {};
236
+ return this;
237
+ }
238
+ }
239
+ class FormatModal {
240
+ #inputs = [];
241
+ #meta = { customId: '', title: '' };
242
+ get value() {
243
+ return {
244
+ type: 'Modal',
245
+ value: this.#inputs,
246
+ options: this.#meta
247
+ };
248
+ }
249
+ setCustomId(customId) {
250
+ this.#meta.customId = customId;
251
+ return this;
252
+ }
253
+ setTitle(title) {
254
+ this.#meta.title = title;
255
+ return this;
256
+ }
257
+ addInput(label, options) {
258
+ this.#inputs.push({
259
+ type: 'TextInput',
260
+ value: label,
261
+ options
262
+ });
263
+ return this;
264
+ }
265
+ clear() {
266
+ this.#inputs = [];
267
+ this.#meta = { customId: '', title: '' };
268
+ return this;
269
+ }
270
+ }
128
271
  class Format {
129
272
  #data = [];
130
273
  static create() {
@@ -136,6 +279,12 @@ class Format {
136
279
  static createButtonGroup() {
137
280
  return new FormatButtonGroup();
138
281
  }
282
+ static createSelect() {
283
+ return new FormatSelect();
284
+ }
285
+ static createModal() {
286
+ return new FormatModal();
287
+ }
139
288
  get value() {
140
289
  return this.#data;
141
290
  }
@@ -143,16 +292,27 @@ class Format {
143
292
  this.#data.push(...format.value);
144
293
  return this;
145
294
  }
146
- addText(...args) {
147
- this.#data.push(Text(...args));
295
+ addText(val, options) {
296
+ this.#data.push({
297
+ type: 'Text',
298
+ value: val,
299
+ options
300
+ });
148
301
  return this;
149
302
  }
150
- addImage(...args) {
151
- this.#data.push(Image(...args));
303
+ addImage(val) {
304
+ this.#data.push({
305
+ type: 'Image',
306
+ value: typeof val === 'string' ? val : `base64://${val.toString('base64')}`
307
+ });
152
308
  return this;
153
309
  }
154
- addMention(...args) {
155
- this.#data.push(Mention(...args));
310
+ addMention(UserId, options) {
311
+ this.#data.push({
312
+ type: 'Mention',
313
+ value: UserId,
314
+ options: options ?? { belong: 'user' }
315
+ });
156
316
  return this;
157
317
  }
158
318
  addButtonGroup(...args) {
@@ -160,7 +320,10 @@ class Format {
160
320
  this.#data.push(args[0].value);
161
321
  }
162
322
  else {
163
- this.#data.push(BT.group(...args));
323
+ this.#data.push({
324
+ type: 'BT.group',
325
+ value: args
326
+ });
164
327
  }
165
328
  return this;
166
329
  }
@@ -169,36 +332,95 @@ class Format {
169
332
  this.#data.push(args[0].value);
170
333
  }
171
334
  else {
172
- this.#data.push(MD(...args));
335
+ this.#data.push({
336
+ type: 'Markdown',
337
+ value: args
338
+ });
173
339
  }
174
340
  return this;
175
341
  }
176
- addMarkdownOriginal(...args) {
177
- this.#data.push(MarkdownOriginal(...args));
342
+ addMarkdownOriginal(val) {
343
+ this.#data.push({
344
+ type: 'MarkdownOriginal',
345
+ value: val
346
+ });
347
+ return this;
348
+ }
349
+ addAttachment(val, options) {
350
+ this.#data.push({
351
+ type: 'Attachment',
352
+ value: val,
353
+ options
354
+ });
178
355
  return this;
179
356
  }
180
- addAttachment(...args) {
181
- this.#data.push(Attachment(...args));
357
+ addAudio(val) {
358
+ this.#data.push({
359
+ type: 'Audio',
360
+ value: val
361
+ });
182
362
  return this;
183
363
  }
184
- addAudio(...args) {
185
- this.#data.push(Audio(...args));
364
+ addVideo(val) {
365
+ this.#data.push({
366
+ type: 'Video',
367
+ value: val
368
+ });
186
369
  return this;
187
370
  }
188
- addVideo(...args) {
189
- this.#data.push(Video(...args));
371
+ addLink(val, options) {
372
+ this.#data.push({
373
+ type: 'Text',
374
+ value: val,
375
+ options
376
+ });
190
377
  return this;
191
378
  }
192
- addLink(...args) {
193
- this.#data.push(Link(...args));
379
+ addImageFile(val) {
380
+ this.#data.push({
381
+ type: 'ImageFile',
382
+ value: val
383
+ });
194
384
  return this;
195
385
  }
196
- addImageFile(...args) {
197
- this.#data.push(ImageFile(...args));
386
+ addImageURL(val) {
387
+ this.#data.push({
388
+ type: 'ImageURL',
389
+ value: val
390
+ });
391
+ return this;
392
+ }
393
+ addSelect(...args) {
394
+ if (args[0] instanceof FormatSelect) {
395
+ this.#data.push(args[0].value);
396
+ }
397
+ else {
398
+ this.#data.push({
399
+ type: 'Select',
400
+ value: args[0],
401
+ options: (args[1] ?? {})
402
+ });
403
+ }
404
+ return this;
405
+ }
406
+ addModal(...args) {
407
+ if (args[0] instanceof FormatModal) {
408
+ this.#data.push(args[0].value);
409
+ }
410
+ else {
411
+ this.#data.push({
412
+ type: 'Modal',
413
+ value: args[0],
414
+ options: args[1]
415
+ });
416
+ }
198
417
  return this;
199
418
  }
200
- addImageURL(...args) {
201
- this.#data.push(ImageURL(...args));
419
+ addEmbed(embed) {
420
+ this.#data.push({
421
+ type: 'Embed',
422
+ value: embed
423
+ });
202
424
  return this;
203
425
  }
204
426
  clear() {
@@ -207,4 +429,4 @@ class Format {
207
429
  }
208
430
  }
209
431
 
210
- export { Attachment, Audio, BT, Format, FormatButtonGroup, FormatMarkDown, Image, ImageFile, ImageURL, Link, MD, MarkdownOriginal, Mention, Text, Video };
432
+ export { Format, FormatButtonGroup, FormatMarkDown, FormatModal, FormatSelect };
@@ -16,7 +16,6 @@ import { createResult } from '../../core/utils.js';
16
16
  import '../../app/hook-event-context.js';
17
17
  import { apiResolves, apiTimeouts, actionResolves, actionTimeouts, FULL_RECEIVE_HEADER } from '../processor/config.js';
18
18
  import { setDirectSend } from '../processor/transport.js';
19
- import '../../app/message-format-old.js';
20
19
  import 'cron';
21
20
  import '../../app/event-utils.js';
22
21
  import '../../app/message-api.js';
package/lib/client.js CHANGED
@@ -27,7 +27,6 @@ import './app/event-middleware.js';
27
27
  import './app/event-processor.js';
28
28
  import './app/event-response.js';
29
29
  import './app/hook-event-context.js';
30
- import './app/message-format-old.js';
31
30
  import 'cron';
32
31
  import './app/event-utils.js';
33
32
  import './app/message-api.js';
package/lib/index.js CHANGED
@@ -45,6 +45,5 @@ export { getCurrentEvent, getCurrentNext, withEventContext } from './app/hook-ev
45
45
  export { registerAppDir, scheduleCancel, scheduleCancelAll, scheduleCancelByApp, scheduleCron, scheduleInterval, scheduleList, schedulePause, scheduleResume, scheduleTimeout, unregisterAppDir } from './app/schedule-store.js';
46
46
  export { createEventValue, createSelects, onSelects, onState, unChildren, unState, useState } from './app/event-utils.js';
47
47
  export { MessageDirect, createDataFormat, format, getMessageIntent, sendToChannel, sendToUser } from './app/message-api.js';
48
- export { Format, FormatButtonGroup, FormatMarkDown } from './app/message-format.js';
48
+ export { Format, FormatButtonGroup, FormatMarkDown, FormatModal, FormatSelect } from './app/message-format.js';
49
49
  export { start } from './main.js';
50
- export { Attachment, Audio, BT, Button, Image, ImageFile, ImageURL, Link, MD, Markdown, MarkdownOriginal, Mention, Text, Video } from './app/message-format-old.js';
@@ -5,10 +5,10 @@ import mime from 'mime-types';
5
5
  import hello from './hello.html.js';
6
6
  import { safePath, getModuelFile, formatPath, isValidPackageName } from './utils.js';
7
7
  import { collectMiddlewares, runMiddlewares } from './middleware.js';
8
+ import module$1 from 'module';
8
9
  import { ResultCode } from '../../core/variable.js';
9
10
  import 'yaml';
10
11
  import '../../core/utils.js';
11
- import module$1 from 'module';
12
12
 
13
13
  const initRequire = () => { };
14
14
  initRequire.resolve = () => '';
@@ -0,0 +1,29 @@
1
+ export type DataEmbedField = {
2
+ name: string;
3
+ value: string;
4
+ inline?: boolean;
5
+ };
6
+ export type DataEmbedAuthor = {
7
+ name: string;
8
+ url?: string;
9
+ iconUrl?: string;
10
+ };
11
+ export type DataEmbedFooter = {
12
+ text: string;
13
+ iconUrl?: string;
14
+ };
15
+ export type DataEmbed = {
16
+ type: 'Embed';
17
+ value: {
18
+ title?: string;
19
+ description?: string;
20
+ url?: string;
21
+ color?: number;
22
+ image?: string;
23
+ thumbnail?: string;
24
+ author?: DataEmbedAuthor;
25
+ footer?: DataEmbedFooter;
26
+ fields?: DataEmbedField[];
27
+ timestamp?: string | number | Date;
28
+ };
29
+ };
@@ -0,0 +1 @@
1
+
@@ -8,6 +8,9 @@ import { DataAttachment } from './attachment';
8
8
  import { DataAudio } from './audio';
9
9
  import { DataVideo } from './video';
10
10
  import { DataMarkdownOriginal } from './markdown-raw';
11
+ import { DataSelect } from './select';
12
+ import { DataModal, DataTextInput } from './modal';
13
+ import { DataEmbed } from './embed';
11
14
  export * from './text';
12
15
  export * from './link';
13
16
  export * from './mention';
@@ -18,5 +21,8 @@ export * from './markdown-raw';
18
21
  export * from './attachment';
19
22
  export * from './audio';
20
23
  export * from './video';
21
- export type DataEnums = DataText | DataLink | DataImage | DataImageURL | DataImageFile | DataMention | DataButtonGroup | DataMarkDown | DataMarkdownOriginal | DataAttachment | DataAudio | DataVideo;
24
+ export * from './select';
25
+ export * from './modal';
26
+ export * from './embed';
27
+ export type DataEnums = DataText | DataLink | DataImage | DataImageURL | DataImageFile | DataMention | DataButtonGroup | DataMarkDown | DataMarkdownOriginal | DataAttachment | DataAudio | DataVideo | DataSelect | DataModal | DataTextInput | DataEmbed;
22
28
  export type MessageDataFormat = DataEnums[];
@@ -0,0 +1,21 @@
1
+ export type DataTextInput = {
2
+ type: 'TextInput';
3
+ value: string;
4
+ options: {
5
+ customId: string;
6
+ style?: 'short' | 'paragraph';
7
+ placeholder?: string;
8
+ minLength?: number;
9
+ maxLength?: number;
10
+ required?: boolean;
11
+ defaultValue?: string;
12
+ };
13
+ };
14
+ export type DataModal = {
15
+ type: 'Modal';
16
+ value: DataTextInput[];
17
+ options: {
18
+ customId: string;
19
+ title: string;
20
+ };
21
+ };
@@ -0,0 +1 @@
1
+
@@ -0,0 +1,19 @@
1
+ export type DataSelectOption = {
2
+ label: string;
3
+ value: string;
4
+ description?: string;
5
+ emoji?: string;
6
+ default?: boolean;
7
+ };
8
+ export type DataSelect = {
9
+ type: 'Select';
10
+ value: DataSelectOption[];
11
+ options?: {
12
+ customId?: string;
13
+ placeholder?: string;
14
+ minValues?: number;
15
+ maxValues?: number;
16
+ kind?: 'string' | 'user' | 'role' | 'channel' | 'mentionable';
17
+ disabled?: boolean;
18
+ };
19
+ };
@@ -0,0 +1 @@
1
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "alemonjs",
3
- "version": "2.1.57",
3
+ "version": "2.1.59",
4
4
  "description": "bot script",
5
5
  "author": "lemonade",
6
6
  "license": "MIT",