alemonjs 2.1.56 → 2.1.58

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.
@@ -0,0 +1,17 @@
1
+ import { ScheduleCallback, CronExpression } from '../../types/schedule';
2
+ export declare const setInterval: (callback: ScheduleCallback, ms: number) => string;
3
+ export declare const setTimeout: (callback: ScheduleCallback, ms: number) => string;
4
+ export declare const setCron: (expression: CronExpression, callback: ScheduleCallback) => string;
5
+ export declare const clearInterval: (id: import("../..").ScheduleId) => boolean;
6
+ export declare const clearTimeout: (id: import("../..").ScheduleId) => boolean;
7
+ export declare const pauseSchedule: (id: import("../..").ScheduleId) => boolean;
8
+ export declare const resumeSchedule: (id: import("../..").ScheduleId) => boolean;
9
+ export declare const listSchedule: (appName?: string) => Array<{
10
+ id: import("../..").ScheduleId;
11
+ type: import("../..").ScheduleItem["type"];
12
+ status: import("../..").ScheduleStatus;
13
+ ms?: number;
14
+ cron?: string;
15
+ appName?: string;
16
+ createdAt: number;
17
+ }>;
@@ -0,0 +1,12 @@
1
+ import { scheduleCancel, scheduleList, schedulePause, scheduleResume, scheduleCron, scheduleInterval, scheduleTimeout } from '../schedule-store.js';
2
+
3
+ const setInterval = (callback, ms) => scheduleInterval(callback, ms);
4
+ const setTimeout = (callback, ms) => scheduleTimeout(callback, ms);
5
+ const setCron = (expression, callback) => scheduleCron(expression, callback);
6
+ const clearInterval = scheduleCancel;
7
+ const clearTimeout = scheduleCancel;
8
+ const pauseSchedule = schedulePause;
9
+ const resumeSchedule = scheduleResume;
10
+ const listSchedule = scheduleList;
11
+
12
+ export { clearInterval, clearTimeout, listSchedule, pauseSchedule, resumeSchedule, setCron, setInterval, setTimeout };
@@ -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 = []) => {
@@ -1,6 +1,7 @@
1
1
  import { GuildInfo, Result, User } from './common';
2
2
  export declare const useMe: () => readonly [{
3
3
  info: () => Promise<Result<User | null>>;
4
+ isMentionMe: () => Result<boolean>;
4
5
  guilds: () => Promise<Result<GuildInfo[]>>;
5
6
  threads: () => Promise<Result<User | null>>;
6
7
  friends: () => Promise<Result<User | null>>;
@@ -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 = () => {
@@ -28,6 +27,14 @@ const useMe = () => {
28
27
  return createResult(ResultCode.Fail, 'Failed to get bot information', null);
29
28
  }
30
29
  };
30
+ const isMentionMe = () => {
31
+ try {
32
+ return createResult(ResultCode.Warn, 'No bot information found', false);
33
+ }
34
+ catch {
35
+ return createResult(ResultCode.Fail, 'Failed to get bot information', false);
36
+ }
37
+ };
31
38
  const guilds = async () => {
32
39
  try {
33
40
  const results = await sendAction({
@@ -80,6 +87,7 @@ const useMe = () => {
80
87
  };
81
88
  const control = {
82
89
  info,
90
+ isMentionMe,
83
91
  guilds,
84
92
  threads,
85
93
  friends
@@ -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 = () => {
@@ -16,7 +16,9 @@ export * from './event-processor-event.js';
16
16
  export * from './event-processor-middleware.js';
17
17
  export * from './event-processor-subscribe.js';
18
18
  export * from './hook-use/index.js';
19
+ export * from './api/schedule.js';
19
20
  export * from './hook-event-context.js';
21
+ export * from './schedule-store.js';
20
22
  export * from './event-utils.js';
21
23
  export * from './message-api.js';
22
24
  export * from './message-format.js';
package/lib/app/index.js CHANGED
@@ -33,8 +33,9 @@ export { useRole } from './hook-use/role.js';
33
33
  export { useUser } from './hook-use/user.js';
34
34
  export { useObserver, useSubscribe } from './hook-use/subscribe.js';
35
35
  export { createEvent, useEvent } from './hook-use/event.js';
36
+ export { clearInterval, clearTimeout, listSchedule, pauseSchedule, resumeSchedule, setCron, setInterval, setTimeout } from './api/schedule.js';
36
37
  export { getCurrentEvent, getCurrentNext, withEventContext } from './hook-event-context.js';
38
+ export { registerAppDir, scheduleCancel, scheduleCancelAll, scheduleCancelByApp, scheduleCron, scheduleInterval, scheduleList, schedulePause, scheduleResume, scheduleTimeout, unregisterAppDir } from './schedule-store.js';
37
39
  export { createEventValue, createSelects, onSelects, onState, unChildren, unState, useState } from './event-utils.js';
38
40
  export { MessageDirect, createDataFormat, format, getMessageIntent, sendToChannel, sendToUser } from './message-api.js';
39
- export { Format, FormatButtonGroup, FormatMarkDown } from './message-format.js';
40
- 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';
@@ -4,6 +4,7 @@ import { showErrorModule, getRecursiveDirFiles, createEventName } from '../../co
4
4
  import { ChildrenApp } from '../store.js';
5
5
  import { registerExpose } from '../expose.js';
6
6
  import { ResultCode, fileSuffixMiddleware } from '../../core/variable.js';
7
+ import { registerAppDir, scheduleCancelByApp, unregisterAppDir } from '../schedule-store.js';
7
8
  import module$1 from 'module';
8
9
 
9
10
  const initRequire = () => { };
@@ -20,6 +21,7 @@ const loadChildren = async (mainPath, appName) => {
20
21
  }
21
22
  const mainDir = dirname(mainPath);
22
23
  const App = new ChildrenApp(appName);
24
+ registerAppDir(appName, mainDir);
23
25
  try {
24
26
  const moduleApp = await import(`file://${mainPath}`);
25
27
  if (!moduleApp?.default) {
@@ -44,6 +46,8 @@ const loadChildren = async (mainPath, appName) => {
44
46
  App.pushCycle(app);
45
47
  const unMounted = async (e) => {
46
48
  showErrorModule(e);
49
+ scheduleCancelByApp(appName);
50
+ unregisterAppDir(appName);
47
51
  App.un();
48
52
  try {
49
53
  if (app?.unMounted) {
@@ -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
  }