alemonjs 2.1.49 → 2.1.52

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.
Files changed (47) hide show
  1. package/LICENSE +21 -0
  2. package/lib/app/event-format.d.ts +19 -0
  3. package/lib/app/event-format.js +128 -0
  4. package/lib/app/event-processor-callHandler.js +3 -2
  5. package/lib/app/event-utils.js +1 -1
  6. package/lib/app/hook-event-context.d.ts +2 -1
  7. package/lib/app/hook-event-context.js +7 -4
  8. package/lib/app/hook-use/client.js +21 -17
  9. package/lib/app/hook-use/common.d.ts +2 -2
  10. package/lib/app/hook-use/common.js +1 -0
  11. package/lib/app/hook-use/event.d.ts +33 -0
  12. package/lib/app/hook-use/event.js +51 -0
  13. package/lib/app/hook-use/index.d.ts +2 -0
  14. package/lib/app/hook-use/index.js +2 -0
  15. package/lib/app/hook-use/subscribe.d.ts +73 -0
  16. package/lib/app/hook-use/subscribe.js +112 -0
  17. package/lib/app/index.d.ts +1 -1
  18. package/lib/app/index.js +5 -3
  19. package/lib/app/load_modules/load.js +1 -1
  20. package/lib/app/load_modules/loadChild.js +3 -3
  21. package/lib/app/message-api.d.ts +2 -2
  22. package/lib/app/message-api.js +6 -38
  23. package/lib/app/message-format.d.ts +1 -13
  24. package/lib/app/message-format.js +1 -25
  25. package/lib/cbp/connects/platform.js +3 -3
  26. package/lib/cbp/server/main.js +6 -6
  27. package/lib/core/utils.js +5 -5
  28. package/lib/index.js +5 -3
  29. package/lib/process/module.js +3 -3
  30. package/lib/process/platform.js +3 -3
  31. package/lib/server/routers/router.js +59 -10
  32. package/lib/server/routers/utils.d.ts +2 -0
  33. package/lib/server/routers/utils.js +12 -1
  34. package/lib/types/event/base/platform.d.ts +1 -1
  35. package/lib/types/event/builder.d.ts +36 -0
  36. package/lib/types/event/builder.js +1 -0
  37. package/lib/types/event/channel/index.d.ts +4 -4
  38. package/lib/types/event/guild/index.d.ts +4 -4
  39. package/lib/types/event/interaction/index.d.ts +3 -3
  40. package/lib/types/event/member/index.d.ts +6 -6
  41. package/lib/types/event/message/message.d.ts +7 -7
  42. package/lib/types/event/message/private.message.d.ts +4 -4
  43. package/lib/types/event/notice/index.d.ts +3 -3
  44. package/lib/types/event/request/index.d.ts +4 -4
  45. package/lib/types/index.d.ts +1 -0
  46. package/lib/utils.js +1 -1
  47. package/package.json +3 -3
@@ -36,7 +36,7 @@ class MessageDirect {
36
36
  payload: {
37
37
  ChannelId: params.SpaceId,
38
38
  params: {
39
- format: params.format.value,
39
+ format: Array.isArray(params.format) ? params.format : params.format.value,
40
40
  replyId: params?.replyId
41
41
  }
42
42
  }
@@ -56,49 +56,17 @@ class MessageDirect {
56
56
  payload: {
57
57
  UserId: params.OpenID,
58
58
  params: {
59
- format: params.format.value
59
+ format: Array.isArray(params.format) ? params.format : params.format.value
60
60
  }
61
61
  }
62
62
  });
63
63
  }
64
64
  }
65
- const sendToChannel = async (SpaceId, data) => {
66
- if (!SpaceId || typeof SpaceId !== 'string') {
67
- logger.error({
68
- code: ResultCode.FailParams,
69
- message: 'Invalid SpaceId: SpaceId must be a string',
70
- data: null
71
- });
72
- throw new Error('Invalid SpaceId: SpaceId must be a string');
73
- }
74
- return await sendAction({
75
- action: 'message.send.channel',
76
- payload: {
77
- ChannelId: SpaceId,
78
- params: {
79
- format: data
80
- }
81
- }
82
- });
65
+ const sendToChannel = (SpaceId, data) => {
66
+ return MessageDirect.create().sendToChannel({ SpaceId, format: data, replyId: undefined });
83
67
  };
84
- const sendToUser = async (OpenID, data) => {
85
- if (!OpenID || typeof OpenID !== 'string') {
86
- logger.error({
87
- code: ResultCode.FailParams,
88
- message: 'Invalid OpenID: OpenID must be a string',
89
- data: null
90
- });
91
- throw new Error('Invalid OpenID: OpenID must be a string');
92
- }
93
- return await sendAction({
94
- action: 'message.send.user',
95
- payload: {
96
- UserId: OpenID,
97
- params: {
98
- format: data
99
- }
100
- }
101
- });
68
+ const sendToUser = (OpenID, data) => {
69
+ return MessageDirect.create().sendToUser({ OpenID, format: data });
102
70
  };
103
71
  const getMessageIntent = async () => {
104
72
  const results = await sendAction({
@@ -1,4 +1,4 @@
1
- import { DataButtonGroup, DataMarkDown, DataEnums, EventKeys, Events } from '../types';
1
+ import { DataButtonGroup, DataMarkDown, DataEnums } from '../types';
2
2
  import { Text, Image, Link, ImageFile, ImageURL, Mention, BT, MD, MarkdownOriginal, Attachment, Audio, Video } from './message-format-old.js';
3
3
  export * from './message-format-old.js';
4
4
  export declare class FormatButtonGroup {
@@ -56,15 +56,3 @@ export declare class Format {
56
56
  addImageURL(...args: Parameters<typeof ImageURL>): this;
57
57
  clear(): this;
58
58
  }
59
- export declare function createEvent<T extends EventKeys>(options: {
60
- event: any;
61
- selects: T | T[];
62
- regular?: RegExp;
63
- prefix?: string;
64
- exact?: string;
65
- }): Events[T] & {
66
- selects: boolean;
67
- regular: boolean;
68
- prefix: boolean;
69
- exact: boolean;
70
- };
@@ -206,29 +206,5 @@ class Format {
206
206
  return this;
207
207
  }
208
208
  }
209
- function createEvent(options) {
210
- const { event, selects, regular, prefix, exact } = options;
211
- const { name, MessageText } = event || {};
212
- const selectsArr = Array.isArray(selects) ? selects : [selects];
213
- const o = {
214
- selects: false,
215
- regular: false,
216
- prefix: false,
217
- exact: false
218
- };
219
- if (selectsArr.includes(name)) {
220
- o.selects = true;
221
- }
222
- if (exact && MessageText && MessageText === exact) {
223
- o.exact = true;
224
- }
225
- if (prefix && MessageText?.startsWith(prefix)) {
226
- o.prefix = true;
227
- }
228
- if (regular && MessageText && new RegExp(regular).test(MessageText)) {
229
- o.regular = true;
230
- }
231
- return { ...event, ...o };
232
- }
233
209
 
234
- export { Attachment, Audio, BT, Format, FormatButtonGroup, FormatMarkDown, Image, ImageFile, ImageURL, Link, MD, MarkdownOriginal, Mention, Text, Video, createEvent };
210
+ export { Attachment, Audio, BT, Format, FormatButtonGroup, FormatMarkDown, Image, ImageFile, ImageURL, Link, MD, MarkdownOriginal, Mention, Text, Video };
@@ -185,7 +185,7 @@ const cbpPlatform = (url, options = {
185
185
  };
186
186
  const currentURL = createCurrentURL() || `ws://localhost:${process.env.port || 17117}`;
187
187
  const send = (data) => {
188
- if (global.chatbotPlatform && global.chatbotPlatform.readyState === WebSocket.OPEN) {
188
+ if (global.chatbotPlatform?.readyState === WebSocket.OPEN) {
189
189
  data.DeviceId = deviceId;
190
190
  data.CreateAt = Date.now();
191
191
  global.chatbotPlatform.send(flattedJSON.stringify(sanitizeForSerialization(data)));
@@ -194,7 +194,7 @@ const cbpPlatform = (url, options = {
194
194
  const actionReplys = [];
195
195
  const apiReplys = [];
196
196
  const replyAction = (data, payload) => {
197
- if (global.chatbotPlatform && global.chatbotPlatform.readyState === WebSocket.OPEN) {
197
+ if (global.chatbotPlatform?.readyState === WebSocket.OPEN) {
198
198
  global.chatbotPlatform.send(flattedJSON.stringify({
199
199
  action: data.action,
200
200
  payload: payload,
@@ -204,7 +204,7 @@ const cbpPlatform = (url, options = {
204
204
  }
205
205
  };
206
206
  const replyApi = (data, payload) => {
207
- if (global.chatbotPlatform && global.chatbotPlatform.readyState === WebSocket.OPEN) {
207
+ if (global.chatbotPlatform?.readyState === WebSocket.OPEN) {
208
208
  global.chatbotPlatform.send(flattedJSON.stringify({
209
209
  action: data.action,
210
210
  apiId: data.apiId,
@@ -15,7 +15,7 @@ import { getClientChild } from '../../process/ipc-bridge.js';
15
15
  const routeMessageToDevice = (DeviceId, message) => {
16
16
  if (childrenClient.has(DeviceId)) {
17
17
  const clientWs = childrenClient.get(DeviceId);
18
- if (clientWs && clientWs.readyState === WebSocket.OPEN) {
18
+ if (clientWs?.readyState === WebSocket.OPEN) {
19
19
  clientWs.send(message);
20
20
  }
21
21
  else {
@@ -24,7 +24,7 @@ const routeMessageToDevice = (DeviceId, message) => {
24
24
  }
25
25
  else if (fullClient.has(DeviceId)) {
26
26
  const clientWs = fullClient.get(DeviceId);
27
- if (clientWs && clientWs.readyState === WebSocket.OPEN) {
27
+ if (clientWs?.readyState === WebSocket.OPEN) {
28
28
  clientWs.send(message);
29
29
  }
30
30
  else {
@@ -90,7 +90,7 @@ const handleEvent = (message, ID) => {
90
90
  });
91
91
  if (bindId) {
92
92
  const clientWs = childrenClient.get(bindId);
93
- if (clientWs && clientWs.readyState === WebSocket.OPEN) {
93
+ if (clientWs?.readyState === WebSocket.OPEN) {
94
94
  bindChannelToClient(ID, bindId);
95
95
  clientWs.send(message);
96
96
  }
@@ -118,7 +118,7 @@ const handleEvent = (message, ID) => {
118
118
  return;
119
119
  }
120
120
  const clientWs = childrenClient.get(bindId);
121
- if (!clientWs || clientWs.readyState !== WebSocket.OPEN) {
121
+ if (clientWs?.readyState !== WebSocket.OPEN) {
122
122
  childrenClient.delete(bindId);
123
123
  reBind();
124
124
  return;
@@ -129,7 +129,7 @@ const setChildrenClient = (originId, ws) => {
129
129
  childrenClient.set(originId, ws);
130
130
  ws.on('message', (message) => {
131
131
  if (global.__sandbox) {
132
- if (global.testoneClient && global.testoneClient.readyState === WebSocket.OPEN) {
132
+ if (global.testoneClient?.readyState === WebSocket.OPEN) {
133
133
  global.testoneClient.send(message.toString());
134
134
  }
135
135
  return;
@@ -166,7 +166,7 @@ const setFullClient = (originId, ws) => {
166
166
  fullClient.set(originId, ws);
167
167
  ws.on('message', (message) => {
168
168
  if (global.__sandbox) {
169
- if (global.testoneClient && global.testoneClient.readyState === WebSocket.OPEN) {
169
+ if (global.testoneClient?.readyState === WebSocket.OPEN) {
170
170
  global.testoneClient.send(message.toString());
171
171
  }
172
172
  return;
package/lib/core/utils.js CHANGED
@@ -1,13 +1,13 @@
1
1
  import { createHash as createHash$1 } from 'node:crypto';
2
2
  import fs__default, { existsSync, readdirSync } from 'fs';
3
3
  import path__default, { join } from 'path';
4
- import { fileSuffixResponse, ResultCode } from './variable.js';
5
- import module from 'module';
4
+ import { ResultCode, fileSuffixResponse } from './variable.js';
5
+ import module$1 from 'module';
6
6
  import { getConfigValue } from './config.js';
7
7
 
8
8
  const initRequire = () => { };
9
9
  initRequire.resolve = () => '';
10
- const require = module?.createRequire?.(import.meta.url) ?? initRequire;
10
+ const require$1 = module$1?.createRequire?.(import.meta.url) ?? initRequire;
11
11
  const createHash = (str, options = {}) => {
12
12
  const { length = 11, algorithm = 'sha256' } = options;
13
13
  const hash = createHash$1(algorithm).update(str).digest('hex');
@@ -117,7 +117,7 @@ const showErrorModule = (e) => {
117
117
  });
118
118
  };
119
119
  const sanitizeForSerialization = (data) => {
120
- const flatted = require('flatted');
120
+ const flatted = require$1('flatted');
121
121
  return flatted.parse(flatted.stringify(data));
122
122
  };
123
123
  const createExports = (packageJson) => {
@@ -133,7 +133,7 @@ const createExports = (packageJson) => {
133
133
  const getInputExportPath = (input) => {
134
134
  const packageJsonPath = path__default.join(input ?? process.cwd(), 'package.json');
135
135
  if (fs__default.existsSync(packageJsonPath)) {
136
- const packageJson = require(packageJsonPath);
136
+ const packageJson = require$1(packageJsonPath);
137
137
  const main = packageJson?.main || createExports(packageJson);
138
138
  if (main) {
139
139
  return main;
package/lib/index.js CHANGED
@@ -13,6 +13,7 @@ export { definePlatform } from './app/define-platform.js';
13
13
  export { defineResponse } from './app/define-response.js';
14
14
  export { defineMiddleware } from './app/define-middleware.js';
15
15
  export { defineRouter, lazy } from './app/define-router.js';
16
+ export { FormatEvent, wrapEvent } from './app/event-format.js';
16
17
  export { onGroup } from './app/event-group.js';
17
18
  export { OnMiddleware, onMiddleware } from './app/event-middleware.js';
18
19
  export { OnProcessor, onProcessor } from './app/event-processor.js';
@@ -36,10 +37,11 @@ export { useReaction } from './app/hook-use/reaction.js';
36
37
  export { useRequest } from './app/hook-use/request.js';
37
38
  export { useRole } from './app/hook-use/role.js';
38
39
  export { useUser } from './app/hook-use/user.js';
39
- export { getCurrentEvent, withEventContext } from './app/hook-event-context.js';
40
+ export { useObserver, useSubscribe } from './app/hook-use/subscribe.js';
41
+ export { createEvent, useEvent } from './app/hook-use/event.js';
42
+ export { getCurrentEvent, getCurrentNext, withEventContext } from './app/hook-event-context.js';
40
43
  export { createEventValue, createSelects, onSelects, onState, unChildren, unState, useState } from './app/event-utils.js';
41
- export { useObserver, useSubscribe } from './app/hook-use-subscribe.js';
42
44
  export { MessageDirect, createDataFormat, format, getMessageIntent, sendToChannel, sendToUser } from './app/message-api.js';
43
- export { Format, FormatButtonGroup, FormatMarkDown, createEvent } from './app/message-format.js';
45
+ export { Format, FormatButtonGroup, FormatMarkDown } from './app/message-format.js';
44
46
  export { start } from './main.js';
45
47
  export { Attachment, Audio, BT, Button, Image, ImageFile, ImageURL, Link, MD, Markdown, MarkdownOriginal, Mention, Text, Video } from './app/message-format-old.js';
@@ -2,12 +2,12 @@ import childProcess from 'child_process';
2
2
  import { ResultCode } from '../core/variable.js';
3
3
  import { getConfigValue } from '../core/config.js';
4
4
  import '../core/utils.js';
5
- import module from 'module';
5
+ import module$1 from 'module';
6
6
  import { setClientChild, forwardFromClient } from './ipc-bridge.js';
7
7
 
8
8
  const initRequire = () => { };
9
9
  initRequire.resolve = () => '';
10
- const require = module?.createRequire?.(import.meta.url) ?? initRequire;
10
+ const require$1 = module$1?.createRequire?.(import.meta.url) ?? initRequire;
11
11
  function startModuleAdapter() {
12
12
  const values = getConfigValue();
13
13
  const pro = values?.process ?? {};
@@ -17,7 +17,7 @@ function startModuleAdapter() {
17
17
  FORK_TIMEOUT: pro?.fork_timeout ?? 6000
18
18
  };
19
19
  try {
20
- modulePath = require.resolve('../client.js');
20
+ modulePath = require$1.resolve('../client.js');
21
21
  }
22
22
  catch (error) {
23
23
  logger?.warn?.({
@@ -2,12 +2,12 @@ import childProcess from 'child_process';
2
2
  import { ResultCode } from '../core/variable.js';
3
3
  import { getConfigValue } from '../core/config.js';
4
4
  import '../core/utils.js';
5
- import module from 'module';
5
+ import module$1 from 'module';
6
6
  import { setPlatformChild, forwardFromPlatform } from './ipc-bridge.js';
7
7
 
8
8
  const initRequire = () => { };
9
9
  initRequire.resolve = () => '';
10
- const require = module?.createRequire?.(import.meta.url) ?? initRequire;
10
+ const require$1 = module$1?.createRequire?.(import.meta.url) ?? initRequire;
11
11
  function startPlatformAdapterWithFallback() {
12
12
  const values = getConfigValue();
13
13
  const pro = values?.process ?? {};
@@ -29,7 +29,7 @@ function startPlatformAdapterWithFallback() {
29
29
  let isForkFailed = false;
30
30
  let imported = false;
31
31
  try {
32
- modulePath = require.resolve(platformPath);
32
+ modulePath = require$1.resolve(platformPath);
33
33
  }
34
34
  catch {
35
35
  logger?.warn?.({
@@ -3,16 +3,16 @@ import fs__default, { existsSync } from 'fs';
3
3
  import path__default, { join, dirname } from 'path';
4
4
  import mime from 'mime-types';
5
5
  import hello from './hello.html.js';
6
- import { getModuelFile, formatPath } from './utils.js';
6
+ import { safePath, getModuelFile, formatPath, isValidPackageName } from './utils.js';
7
7
  import { collectMiddlewares, runMiddlewares } from './middleware.js';
8
8
  import { ResultCode } from '../../core/variable.js';
9
9
  import 'yaml';
10
10
  import '../../core/utils.js';
11
- import module from 'module';
11
+ import module$1 from 'module';
12
12
 
13
13
  const initRequire = () => { };
14
14
  initRequire.resolve = () => '';
15
- const require = module?.createRequire?.(import.meta.url) ?? initRequire;
15
+ const require$1 = module$1?.createRequire?.(import.meta.url) ?? initRequire;
16
16
  const mainDirMap = new Map();
17
17
  const router = new KoaRouter({
18
18
  prefix: '/'
@@ -55,7 +55,17 @@ router.all('app/{*path}', async (ctx) => {
55
55
  }
56
56
  const mainDir = dirname(mainPath);
57
57
  try {
58
- const dir = join(mainDir, 'route', ctx.path?.replace(apiPath, '/api') || '');
58
+ const routeBase = join(mainDir, 'route');
59
+ const dir = safePath(routeBase, ctx.path?.replace(apiPath, '/api') || '');
60
+ if (!dir) {
61
+ ctx.status = 403;
62
+ ctx.body = {
63
+ code: 403,
64
+ message: '非法路径',
65
+ data: null
66
+ };
67
+ return;
68
+ }
59
69
  if (existsSync(dir) && fs__default.statSync(dir).isFile()) {
60
70
  ctx.status = 404;
61
71
  ctx.body = {
@@ -102,7 +112,7 @@ router.all('app/{*path}', async (ctx) => {
102
112
  let root = '';
103
113
  const resourcePath = formatPath(ctx.params?.path);
104
114
  try {
105
- const pkg = require(path__default.join(rootPath, 'package.json')) ?? {};
115
+ const pkg = require$1(path__default.join(rootPath, 'package.json')) ?? {};
106
116
  root = pkg.alemonjs?.web?.root ?? '';
107
117
  }
108
118
  catch (err) {
@@ -114,7 +124,17 @@ router.all('app/{*path}', async (ctx) => {
114
124
  };
115
125
  return;
116
126
  }
117
- const fullPath = root ? path__default.join(rootPath, root, resourcePath) : path__default.join(rootPath, resourcePath);
127
+ const webRoot = root ? path__default.join(rootPath, root) : rootPath;
128
+ const fullPath = safePath(webRoot, resourcePath);
129
+ if (!fullPath) {
130
+ ctx.status = 403;
131
+ ctx.body = {
132
+ code: 403,
133
+ message: '非法路径',
134
+ data: null
135
+ };
136
+ return;
137
+ }
118
138
  try {
119
139
  const file = await fs__default.promises.readFile(fullPath);
120
140
  const mimeType = mime.lookup(fullPath) || 'application/octet-stream';
@@ -146,11 +166,20 @@ router.all('app', ctx => {
146
166
  });
147
167
  router.all('apps/:app/{*path}', async (ctx) => {
148
168
  const appName = ctx.params.app;
169
+ if (!isValidPackageName(appName)) {
170
+ ctx.status = 400;
171
+ ctx.body = {
172
+ code: 400,
173
+ message: '无效的应用名称',
174
+ data: null
175
+ };
176
+ return;
177
+ }
149
178
  const apiPath = `/apps/${appName}/api`;
150
179
  if (ctx.path.startsWith(apiPath)) {
151
180
  try {
152
181
  if (!mainDirMap.has(appName)) {
153
- const mainPath = require.resolve(appName);
182
+ const mainPath = require$1.resolve(appName);
154
183
  if (!existsSync(mainPath)) {
155
184
  ctx.status = 400;
156
185
  ctx.body = {
@@ -163,7 +192,17 @@ router.all('apps/:app/{*path}', async (ctx) => {
163
192
  const mainDir = dirname(mainPath);
164
193
  mainDirMap.set(appName, mainDir);
165
194
  }
166
- const dir = join(mainDirMap.get(appName), 'route', ctx.path?.replace(apiPath, '/api') || '');
195
+ const routeBase = join(mainDirMap.get(appName), 'route');
196
+ const dir = safePath(routeBase, ctx.path?.replace(apiPath, '/api') || '');
197
+ if (!dir) {
198
+ ctx.status = 403;
199
+ ctx.body = {
200
+ code: 403,
201
+ message: '非法路径',
202
+ data: null
203
+ };
204
+ return;
205
+ }
167
206
  if (existsSync(dir) && fs__default.statSync(dir).isFile()) {
168
207
  ctx.status = 404;
169
208
  ctx.body = {
@@ -215,7 +254,7 @@ router.all('apps/:app/{*path}', async (ctx) => {
215
254
  const resourcePath = formatPath(ctx.params?.path);
216
255
  let root = '';
217
256
  try {
218
- const pkg = require(`${appName}/package`) ?? {};
257
+ const pkg = require$1(`${appName}/package`) ?? {};
219
258
  root = pkg?.alemonjs?.web?.root ?? '';
220
259
  }
221
260
  catch (err) {
@@ -227,7 +266,17 @@ router.all('apps/:app/{*path}', async (ctx) => {
227
266
  };
228
267
  return;
229
268
  }
230
- const fullPath = root ? path__default.join(rootPath, root, resourcePath) : path__default.join(rootPath, resourcePath);
269
+ const webRoot = root ? path__default.join(rootPath, root) : rootPath;
270
+ const fullPath = safePath(webRoot, resourcePath);
271
+ if (!fullPath) {
272
+ ctx.status = 403;
273
+ ctx.body = {
274
+ code: 403,
275
+ message: '非法路径',
276
+ data: null
277
+ };
278
+ return;
279
+ }
231
280
  try {
232
281
  const file = await fs__default.promises.readFile(fullPath);
233
282
  const mimeType = mime.lookup(fullPath) || 'application/octet-stream';
@@ -1,2 +1,4 @@
1
+ export declare const safePath: (root: string, untrusted: string) => string | null;
2
+ export declare const isValidPackageName: (name: string) => boolean;
1
3
  export declare const getModuelFile: (dir: string) => string;
2
4
  export declare const formatPath: (path: string) => string;
@@ -1,5 +1,16 @@
1
1
  import fs__default, { existsSync } from 'fs';
2
+ import path__default from 'path';
2
3
 
4
+ const safePath = (root, untrusted) => {
5
+ const resolved = path__default.resolve(root, untrusted);
6
+ if (resolved !== root && !resolved.startsWith(root + path__default.sep)) {
7
+ return null;
8
+ }
9
+ return resolved;
10
+ };
11
+ const isValidPackageName = (name) => {
12
+ return /^(?:@[a-z0-9\-~][a-z0-9\-._~]*\/)?[a-z0-9\-~][a-z0-9\-._~]*$/.test(name);
13
+ };
3
14
  const getModuelFile = (dir) => {
4
15
  const dirMap = {
5
16
  '.js': `${dir}.js`,
@@ -36,4 +47,4 @@ const formatPath = (path) => {
36
47
  return path;
37
48
  };
38
49
 
39
- export { formatPath, getModuelFile };
50
+ export { formatPath, getModuelFile, isValidPackageName, safePath };
@@ -1,4 +1,4 @@
1
- export type platform = {
1
+ export type Platform = {
2
2
  Platform: string;
3
3
  value: any;
4
4
  BotId?: string;
@@ -0,0 +1,36 @@
1
+ import { Guild, Channel } from './base/guild';
2
+ import { Message, MessageText, MessageMedia, MessageOpen } from './base/message';
3
+ import { Platform } from './base/platform';
4
+ import { User } from './base/user';
5
+ import { AutoFields } from './base/auto';
6
+ import { EventKeys, Events } from './map';
7
+ export type ReservedEventKeys = keyof Guild | keyof Channel | keyof User | keyof Message | keyof MessageText | keyof MessageMedia | keyof MessageOpen | keyof Platform | keyof AutoFields | 'name' | 'Timestamp';
8
+ type GuildMethods<T extends EventKeys> = Events[T] extends Guild ? {
9
+ addGuild(params: Guild): EventBuilder<T>;
10
+ } : Record<string, never>;
11
+ type ChannelMethods<T extends EventKeys> = Events[T] extends Channel ? {
12
+ addChannel(params: Channel): EventBuilder<T>;
13
+ } : Record<string, never>;
14
+ type UserMethods<T extends EventKeys> = Events[T] extends User ? {
15
+ addUser(params: User): EventBuilder<T>;
16
+ } : Record<string, never>;
17
+ type MessageMethods<T extends EventKeys> = Events[T] extends Message ? {
18
+ addMessage(params: Message): EventBuilder<T>;
19
+ } : Record<string, never>;
20
+ type TextMethods<T extends EventKeys> = Events[T] extends MessageText ? {
21
+ addText(params: MessageText): EventBuilder<T>;
22
+ } : Record<string, never>;
23
+ type MediaMethods<T extends EventKeys> = Events[T] extends MessageMedia ? {
24
+ addMedia(params: MessageMedia): EventBuilder<T>;
25
+ } : Record<string, never>;
26
+ type OpenMethods<T extends EventKeys> = Events[T] extends MessageOpen ? {
27
+ addOpen(params: MessageOpen): EventBuilder<T>;
28
+ } : Record<string, never>;
29
+ export type EventBuilder<T extends EventKeys> = {
30
+ addPlatform(params: Platform): EventBuilder<T>;
31
+ add<E extends Record<string, unknown>>(fields: {
32
+ [K in keyof E]: K extends ReservedEventKeys ? never : E[K];
33
+ }): EventBuilder<T>;
34
+ readonly value: Events[T];
35
+ } & GuildMethods<T> & ChannelMethods<T> & UserMethods<T> & MessageMethods<T> & TextMethods<T> & MediaMethods<T> & OpenMethods<T>;
36
+ export {};
@@ -0,0 +1 @@
1
+
@@ -1,13 +1,13 @@
1
1
  import { Guild, Channel } from '../base/guild';
2
- import { platform } from '../base/platform';
2
+ import { Platform } from '../base/platform';
3
3
  import { Message } from '../base/message';
4
4
  import { Expansion } from '../base/expansion';
5
- export type PublicEventChannelCreate = platform & Guild & Channel & Message & {
5
+ export type PublicEventChannelCreate = Platform & Guild & Channel & Message & {
6
6
  name: 'channel.create';
7
7
  } & Expansion;
8
- export type PublicEventChannelDelete = platform & Guild & Channel & Message & {
8
+ export type PublicEventChannelDelete = Platform & Guild & Channel & Message & {
9
9
  name: 'channel.delete';
10
10
  } & Expansion;
11
- export type PublicEventChannelUpdate = platform & Guild & Channel & Message & {
11
+ export type PublicEventChannelUpdate = Platform & Guild & Channel & Message & {
12
12
  name: 'channel.update';
13
13
  } & Expansion;
@@ -1,14 +1,14 @@
1
1
  import { Expansion } from '../base/expansion';
2
2
  import { Channel, Guild } from '../base/guild';
3
3
  import { Message } from '../base/message';
4
- import { platform } from '../base/platform';
4
+ import { Platform } from '../base/platform';
5
5
  import { User } from '../base/user';
6
- export type PublicEventGuildJoin = platform & Guild & Channel & Message & User & {
6
+ export type PublicEventGuildJoin = Platform & Guild & Channel & Message & User & {
7
7
  name: 'guild.join';
8
8
  } & Expansion;
9
- export type PublicEventGuildExit = platform & Guild & Channel & Message & User & {
9
+ export type PublicEventGuildExit = Platform & Guild & Channel & Message & User & {
10
10
  name: 'guild.exit';
11
11
  } & Expansion;
12
- export type PublicEventGuildUpdate = platform & Guild & Channel & Message & {
12
+ export type PublicEventGuildUpdate = Platform & Guild & Channel & Message & {
13
13
  name: 'guild.update';
14
14
  } & Expansion;
@@ -1,11 +1,11 @@
1
1
  import { Guild, Channel } from '../base/guild';
2
2
  import { Message, MessageOpen, MessageText } from '../base/message';
3
3
  import { User } from '../base/user';
4
- import { platform } from '../base/platform';
4
+ import { Platform } from '../base/platform';
5
5
  import { Expansion } from '../base/expansion';
6
- export type PrivateEventInteractionCreate = MessageText & MessageOpen & platform & Message & User & {
6
+ export type PrivateEventInteractionCreate = MessageText & MessageOpen & Platform & Message & User & {
7
7
  name: 'private.interaction.create';
8
8
  } & Expansion;
9
- export type PublicEventInteractionCreate = MessageText & MessageOpen & platform & Guild & Channel & Message & User & {
9
+ export type PublicEventInteractionCreate = MessageText & MessageOpen & Platform & Guild & Channel & Message & User & {
10
10
  name: 'interaction.create';
11
11
  } & Expansion;
@@ -1,20 +1,20 @@
1
1
  import { Guild, Channel } from '../base/guild';
2
2
  import { Message } from '../base/message';
3
3
  import { User } from '../base/user';
4
- import { platform } from '../base/platform';
4
+ import { Platform } from '../base/platform';
5
5
  import { Expansion } from '../base/expansion';
6
- export type PublicEventMemberAdd = platform & Guild & Channel & Message & User & {
6
+ export type PublicEventMemberAdd = Platform & Guild & Channel & Message & User & {
7
7
  name: 'member.add';
8
8
  } & Expansion;
9
- export type PublicEventMemberRemove = platform & Guild & Channel & Message & User & {
9
+ export type PublicEventMemberRemove = Platform & Guild & Channel & Message & User & {
10
10
  name: 'member.remove';
11
11
  } & Expansion;
12
- export type PublicEventMemberBan = platform & Guild & Channel & Message & User & {
12
+ export type PublicEventMemberBan = Platform & Guild & Channel & Message & User & {
13
13
  name: 'member.ban';
14
14
  } & Expansion;
15
- export type PublicEventMemberUnban = platform & Guild & Channel & Message & User & {
15
+ export type PublicEventMemberUnban = Platform & Guild & Channel & Message & User & {
16
16
  name: 'member.unban';
17
17
  } & Expansion;
18
- export type PublicEventMemberUpdate = platform & Guild & Channel & Message & User & {
18
+ export type PublicEventMemberUpdate = Platform & Guild & Channel & Message & User & {
19
19
  name: 'member.update';
20
20
  } & Expansion;
@@ -1,23 +1,23 @@
1
1
  import { Guild, Channel } from '../base/guild';
2
2
  import { Message, MessageMedia, MessageOpen, MessageText } from '../base/message';
3
3
  import { User } from '../base/user';
4
- import { platform } from '../base/platform';
4
+ import { Platform } from '../base/platform';
5
5
  import { Expansion } from '../base/expansion';
6
- export type PublicEventMessageCreate = MessageText & MessageMedia & MessageOpen & platform & Guild & Channel & Message & User & {
6
+ export type PublicEventMessageCreate = MessageText & MessageMedia & MessageOpen & Platform & Guild & Channel & Message & User & {
7
7
  name: 'message.create';
8
8
  } & Expansion;
9
- export type PublicEventMessageUpdate = platform & Guild & Channel & Message & User & {
9
+ export type PublicEventMessageUpdate = Platform & Guild & Channel & Message & User & {
10
10
  name: 'message.update';
11
11
  } & Expansion;
12
- export type PublicEventMessageDelete = platform & Guild & Channel & Message & {
12
+ export type PublicEventMessageDelete = Platform & Guild & Channel & Message & {
13
13
  name: 'message.delete';
14
14
  } & Expansion;
15
- export type PublicEventMessageReactionAdd = platform & Guild & Channel & Message & {
15
+ export type PublicEventMessageReactionAdd = Platform & Guild & Channel & Message & {
16
16
  name: 'message.reaction.add';
17
17
  } & Expansion;
18
- export type PublicEventMessageReactionRemove = platform & Guild & Channel & Message & {
18
+ export type PublicEventMessageReactionRemove = Platform & Guild & Channel & Message & {
19
19
  name: 'message.reaction.remove';
20
20
  } & Expansion;
21
- export type PublicEventMessagePin = platform & Guild & Channel & Message & {
21
+ export type PublicEventMessagePin = Platform & Guild & Channel & Message & {
22
22
  name: 'message.pin';
23
23
  } & Expansion;
@@ -1,13 +1,13 @@
1
1
  import { Expansion } from '../base/expansion';
2
2
  import { Message, MessageMedia, MessageOpen, MessageText } from '../base/message';
3
- import { platform } from '../base/platform';
3
+ import { Platform } from '../base/platform';
4
4
  import { User } from '../base/user';
5
- export type PrivateEventMessageCreate = MessageText & MessageMedia & MessageOpen & platform & Message & User & {
5
+ export type PrivateEventMessageCreate = MessageText & MessageMedia & MessageOpen & Platform & Message & User & {
6
6
  name: 'private.message.create';
7
7
  } & Expansion;
8
- export type PrivateEventMessageUpdate = platform & Message & User & {
8
+ export type PrivateEventMessageUpdate = Platform & Message & User & {
9
9
  name: 'private.message.update';
10
10
  } & Expansion;
11
- export type PrivateEventMessageDelete = platform & Message & {
11
+ export type PrivateEventMessageDelete = Platform & Message & {
12
12
  name: 'private.message.delete';
13
13
  } & Expansion;