alemonjs 2.1.47 → 2.1.49

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 (61) hide show
  1. package/lib/app/event-processor-callHandler.js +3 -2
  2. package/lib/app/event-processor-cycleFiles.js +1 -1
  3. package/lib/app/event-processor.js +13 -13
  4. package/lib/app/event-utils.d.ts +14 -0
  5. package/lib/app/event-utils.js +86 -0
  6. package/lib/app/hook-event-context.d.ts +3 -0
  7. package/lib/app/hook-event-context.js +11 -0
  8. package/lib/app/hook-use/announce.d.ts +12 -0
  9. package/lib/app/hook-use/announce.js +49 -0
  10. package/lib/app/hook-use/channel.d.ts +24 -0
  11. package/lib/app/hook-use/channel.js +109 -0
  12. package/lib/app/hook-use/client.d.ts +2 -0
  13. package/lib/app/hook-use/client.js +49 -0
  14. package/lib/app/hook-use/common.d.ts +18 -0
  15. package/lib/app/hook-use/common.js +22 -0
  16. package/lib/app/hook-use/guild.d.ts +19 -0
  17. package/lib/app/hook-use/guild.js +102 -0
  18. package/lib/app/hook-use/history.d.ts +9 -0
  19. package/lib/app/hook-use/history.js +31 -0
  20. package/lib/app/hook-use/index.d.ts +15 -0
  21. package/lib/app/hook-use/index.js +15 -0
  22. package/lib/app/hook-use/me.d.ts +7 -0
  23. package/lib/app/hook-use/me.js +90 -0
  24. package/lib/app/hook-use/media.d.ts +23 -0
  25. package/lib/app/hook-use/media.js +62 -0
  26. package/lib/app/hook-use/member.d.ts +54 -0
  27. package/lib/app/hook-use/member.js +200 -0
  28. package/lib/app/hook-use/mention.d.ts +9 -0
  29. package/lib/app/hook-use/mention.js +88 -0
  30. package/lib/app/hook-use/message.d.ts +28 -0
  31. package/lib/app/hook-use/message.js +142 -0
  32. package/lib/app/hook-use/permission.d.ts +13 -0
  33. package/lib/app/hook-use/permission.js +49 -0
  34. package/lib/app/hook-use/reaction.d.ts +16 -0
  35. package/lib/app/hook-use/reaction.js +70 -0
  36. package/lib/app/hook-use/request.d.ts +14 -0
  37. package/lib/app/hook-use/request.js +53 -0
  38. package/lib/app/hook-use/role.d.ts +33 -0
  39. package/lib/app/hook-use/role.js +125 -0
  40. package/lib/app/hook-use/user.d.ts +6 -0
  41. package/lib/app/hook-use/user.js +39 -0
  42. package/lib/app/hook-use-api.d.ts +3 -3
  43. package/lib/app/hook-use-api.js +16 -13
  44. package/lib/app/hook-use-subscribe.d.ts +61 -20
  45. package/lib/app/hook-use-subscribe.js +21 -7
  46. package/lib/app/index.d.ts +3 -2
  47. package/lib/app/index.js +18 -3
  48. package/lib/app/message-api.d.ts +0 -6
  49. package/lib/app/message-api.js +1 -4
  50. package/lib/app/message-format-old.d.ts +2 -2
  51. package/lib/app/message-format.js +1 -1
  52. package/lib/cbp/connects/client.js +5 -4
  53. package/lib/client.js +3 -2
  54. package/lib/core/config.d.ts +37 -0
  55. package/lib/core/index.js +1 -1
  56. package/lib/core/utils.d.ts +2 -1
  57. package/lib/core/utils.js +12 -9
  58. package/lib/global.d.ts +3 -1
  59. package/lib/index.js +19 -4
  60. package/lib/types/message/markdown.d.ts +1 -1
  61. package/package.json +1 -1
@@ -4,6 +4,7 @@ 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
6
  import { Format } from './message-format.js';
7
+ import { getCurrentEvent } from './hook-event-context.js';
7
8
 
8
9
  const useMention = (event) => {
9
10
  if (!event || typeof event !== 'object') {
@@ -94,7 +95,8 @@ const useMention = (event) => {
94
95
  return [mention];
95
96
  };
96
97
  const useMessage = (event) => {
97
- if (!event || typeof event !== 'object') {
98
+ const currentEvent = (event ?? getCurrentEvent());
99
+ if (!currentEvent || typeof currentEvent !== 'object') {
98
100
  logger.error({
99
101
  code: ResultCode.FailParams,
100
102
  message: 'Invalid event: event must be an object',
@@ -102,6 +104,7 @@ const useMessage = (event) => {
102
104
  });
103
105
  throw new Error('Invalid event: event must be an object');
104
106
  }
107
+ const valueEvent = currentEvent;
105
108
  const resolveFormat = (params) => {
106
109
  if (params.format instanceof Format) {
107
110
  return params.format.value;
@@ -115,7 +118,7 @@ const useMessage = (event) => {
115
118
  const result = await sendAction({
116
119
  action: 'message.send',
117
120
  payload: {
118
- event,
121
+ event: valueEvent,
119
122
  params: {
120
123
  format: val,
121
124
  replyId
@@ -129,17 +132,17 @@ const useMessage = (event) => {
129
132
  if (Array.isArray(params)) {
130
133
  return sendRaw(params.length > 0 ? params : []);
131
134
  }
132
- return sendRaw(resolveFormat(params), params?.replyId ?? event.MessageId);
135
+ return sendRaw(resolveFormat(params), params?.replyId ?? valueEvent.MessageId);
133
136
  },
134
137
  async delete(params) {
135
- const targetId = params?.messageId || event.MessageId;
138
+ const targetId = params?.messageId || valueEvent.MessageId;
136
139
  if (!targetId) {
137
140
  return createResult(ResultCode.FailParams, 'Missing MessageId', null);
138
141
  }
139
142
  try {
140
143
  const results = await sendAction({
141
144
  action: 'message.delete',
142
- payload: { MessageId: targetId, ChannelId: event.ChannelId, event }
145
+ payload: { MessageId: targetId, ChannelId: valueEvent.ChannelId, event: valueEvent }
143
146
  });
144
147
  const result = results.find(item => item.code === ResultCode.Ok);
145
148
  return result || createResult(ResultCode.Warn, 'Delete not supported or failed', null);
@@ -149,8 +152,8 @@ const useMessage = (event) => {
149
152
  }
150
153
  },
151
154
  async edit(params) {
152
- const targetId = params.messageId || event.MessageId;
153
- const channelId = event.ChannelId;
155
+ const targetId = params.messageId || valueEvent.MessageId;
156
+ const channelId = valueEvent.ChannelId;
154
157
  if (!targetId || !channelId) {
155
158
  return createResult(ResultCode.FailParams, 'Missing MessageId or ChannelId', null);
156
159
  }
@@ -158,7 +161,7 @@ const useMessage = (event) => {
158
161
  const val = params.format instanceof Format ? params.format.value : params.format;
159
162
  const results = await sendAction({
160
163
  action: 'message.edit',
161
- payload: { ChannelId: channelId, MessageId: targetId, params: { format: val }, event }
164
+ payload: { ChannelId: channelId, MessageId: targetId, params: { format: val }, event: valueEvent }
162
165
  });
163
166
  const result = results.find(item => item.code === ResultCode.Ok);
164
167
  return result || createResult(ResultCode.Warn, 'Edit not supported or failed', null);
@@ -168,8 +171,8 @@ const useMessage = (event) => {
168
171
  }
169
172
  },
170
173
  async pin(params) {
171
- const targetId = params?.messageId || event.MessageId;
172
- const channelId = event.ChannelId;
174
+ const targetId = params?.messageId || valueEvent.MessageId;
175
+ const channelId = valueEvent.ChannelId;
173
176
  if (!targetId || !channelId) {
174
177
  return createResult(ResultCode.FailParams, 'Missing MessageId or ChannelId', null);
175
178
  }
@@ -186,8 +189,8 @@ const useMessage = (event) => {
186
189
  }
187
190
  },
188
191
  async unpin(params) {
189
- const targetId = params?.messageId || event.MessageId;
190
- const channelId = event.ChannelId;
192
+ const targetId = params?.messageId || valueEvent.MessageId;
193
+ const channelId = valueEvent.ChannelId;
191
194
  if (!targetId || !channelId) {
192
195
  return createResult(ResultCode.FailParams, 'Missing MessageId or ChannelId', null);
193
196
  }
@@ -204,7 +207,7 @@ const useMessage = (event) => {
204
207
  }
205
208
  },
206
209
  async get(params) {
207
- const targetId = params?.messageId || event.MessageId;
210
+ const targetId = params?.messageId || valueEvent.MessageId;
208
211
  if (!targetId) {
209
212
  return createResult(ResultCode.FailParams, 'Missing MessageId', null);
210
213
  }
@@ -1,32 +1,73 @@
1
1
  import { EventCycleEnum, Current, Events, EventKeys } from '../types';
2
- export declare const useSubscribe: <T extends EventKeys>(event: Events[T], selects: T | T[]) => readonly [{
3
- create: (callback: Current<T>, keys: (keyof Events[T])[]) => {
2
+ export declare function useSubscribe<T extends EventKeys>(selects: T | T[]): readonly [
3
+ {
4
+ create: (callback: Current<T>, keys: (keyof Events[T])[]) => {
5
+ id: string;
6
+ selects: T[];
7
+ choose: EventCycleEnum;
8
+ };
9
+ mount: (callback: Current<T>, keys: (keyof Events[T])[]) => {
10
+ id: string;
11
+ selects: T[];
12
+ choose: EventCycleEnum;
13
+ };
14
+ unmount: (callback: Current<T>, keys: (keyof Events[T])[]) => {
15
+ id: string;
16
+ selects: T[];
17
+ choose: EventCycleEnum;
18
+ };
19
+ cancel: (value: {
20
+ id: string;
21
+ selects: T[];
22
+ choose: EventCycleEnum;
23
+ }) => void;
24
+ }
25
+ ];
26
+ export declare function useSubscribe<T extends EventKeys>(event: Events[T] | undefined, selects: T | T[]): readonly [
27
+ {
28
+ create: (callback: Current<T>, keys: (keyof Events[T])[]) => {
29
+ id: string;
30
+ selects: T[];
31
+ choose: EventCycleEnum;
32
+ };
33
+ mount: (callback: Current<T>, keys: (keyof Events[T])[]) => {
34
+ id: string;
35
+ selects: T[];
36
+ choose: EventCycleEnum;
37
+ };
38
+ unmount: (callback: Current<T>, keys: (keyof Events[T])[]) => {
39
+ id: string;
40
+ selects: T[];
41
+ choose: EventCycleEnum;
42
+ };
43
+ cancel: (value: {
44
+ id: string;
45
+ selects: T[];
46
+ choose: EventCycleEnum;
47
+ }) => void;
48
+ }
49
+ ];
50
+ export declare function useObserver<T extends EventKeys>(selects: T | T[]): readonly [
51
+ (callback: Current<T>, keys: (keyof Events[T])[]) => {
52
+ id: string;
4
53
  selects: T[];
5
54
  choose: EventCycleEnum;
55
+ },
56
+ (value: {
6
57
  id: string;
7
- };
8
- mount: (callback: Current<T>, keys: (keyof Events[T])[]) => {
9
58
  selects: T[];
10
59
  choose: EventCycleEnum;
60
+ }) => void
61
+ ];
62
+ export declare function useObserver<T extends EventKeys>(event: Events[T] | undefined, selects: T | T[]): readonly [
63
+ (callback: Current<T>, keys: (keyof Events[T])[]) => {
11
64
  id: string;
12
- };
13
- unmount: (callback: Current<T>, keys: (keyof Events[T])[]) => {
14
65
  selects: T[];
15
66
  choose: EventCycleEnum;
16
- id: string;
17
- };
18
- cancel: (value: {
67
+ },
68
+ (value: {
19
69
  id: string;
20
70
  selects: T[];
21
71
  choose: EventCycleEnum;
22
- }) => void;
23
- }];
24
- export declare const useObserver: <T extends EventKeys>(event: Events[T], selects: T | T[]) => readonly [(callback: Current<T>, keys: (keyof Events[T])[]) => {
25
- selects: T[];
26
- choose: EventCycleEnum;
27
- id: string;
28
- }, (value: {
29
- id: string;
30
- selects: T[];
31
- choose: EventCycleEnum;
32
- }) => void];
72
+ }) => void
73
+ ];
@@ -1,9 +1,13 @@
1
1
  import { ResultCode } from '../core/variable.js';
2
2
  import { SubscribeList } from './store.js';
3
3
  import { SubscribeStatus } from './config.js';
4
+ import { getCurrentEvent } from './hook-event-context.js';
4
5
 
5
- const useSubscribe = (event, selects) => {
6
- if (typeof event !== 'object') {
6
+ function useSubscribe(eventOrSelects, maybeSelects) {
7
+ const selects = (maybeSelects === undefined ? eventOrSelects : maybeSelects);
8
+ const event = (maybeSelects === undefined ? undefined : eventOrSelects);
9
+ const valueEvent = event ?? getCurrentEvent();
10
+ if (typeof valueEvent !== 'object' || valueEvent === null) {
7
11
  logger.error({
8
12
  code: ResultCode.FailParams,
9
13
  message: 'event is not object',
@@ -34,8 +38,8 @@ const useSubscribe = (event, selects) => {
34
38
  const subList = new SubscribeList(choose, select);
35
39
  const values = {};
36
40
  for (const key of keys) {
37
- if (typeof key === 'string' && (typeof event[key] === 'string' || typeof event[key] === 'number' || typeof event[key] === 'boolean')) {
38
- values[key] = event[key];
41
+ if (typeof key === 'string' && (typeof valueEvent[key] === 'string' || typeof valueEvent[key] === 'number' || typeof valueEvent[key] === 'boolean')) {
42
+ values[key] = valueEvent[key];
39
43
  }
40
44
  else {
41
45
  logger.warn({
@@ -89,10 +93,20 @@ const useSubscribe = (event, selects) => {
89
93
  cancel
90
94
  };
91
95
  return [subscribe];
92
- };
93
- const useObserver = (event, selects) => {
96
+ }
97
+ function useObserver(eventOrSelects, maybeSelects) {
98
+ const selects = (maybeSelects === undefined ? eventOrSelects : maybeSelects);
99
+ const event = (maybeSelects === undefined ? undefined : eventOrSelects);
100
+ if (selects === undefined) {
101
+ logger.error({
102
+ code: ResultCode.FailParams,
103
+ message: 'select is not string or array',
104
+ data: null
105
+ });
106
+ throw new Error('select is not string or array');
107
+ }
94
108
  const [subscribe] = useSubscribe(event, selects);
95
109
  return [subscribe.mount, subscribe.cancel];
96
- };
110
+ }
97
111
 
98
112
  export { useObserver, useSubscribe };
@@ -13,8 +13,9 @@ export * from './event-processor-cycle.js';
13
13
  export * from './event-processor-event.js';
14
14
  export * from './event-processor-middleware.js';
15
15
  export * from './event-processor-subscribe.js';
16
- export * from './hook-use-api.js';
17
- export * from './hook-use-state.js';
16
+ export * from './hook-use/index.js';
17
+ export * from './hook-event-context.js';
18
+ export * from './event-utils.js';
18
19
  export * from './hook-use-subscribe.js';
19
20
  export * from './message-api.js';
20
21
  export * from './message-format.js';
package/lib/app/index.js CHANGED
@@ -14,9 +14,24 @@ export { expendCycle } from './event-processor-cycle.js';
14
14
  export { expendEvent } from './event-processor-event.js';
15
15
  export { expendMiddleware } from './event-processor-middleware.js';
16
16
  export { expendSubscribe, expendSubscribeCreate, expendSubscribeMount, expendSubscribeUnmount } from './event-processor-subscribe.js';
17
- export { createSelects, onSelects, unChildren, useAnnounce, useChannel, useClient, useGuild, useHistory, useMe, useMedia, useMember, useMention, useMessage, usePermission, useReaction, useRequest, useRole, useSend, useSends, useUser } from './hook-use-api.js';
18
- export { onState, unState, useState } from './hook-use-state.js';
17
+ export { useAnnounce } from './hook-use/announce.js';
18
+ export { useChannel } from './hook-use/channel.js';
19
+ export { useClient } from './hook-use/client.js';
20
+ export { useGuild } from './hook-use/guild.js';
21
+ export { useHistory } from './hook-use/history.js';
22
+ export { useMedia } from './hook-use/media.js';
23
+ export { useMe } from './hook-use/me.js';
24
+ export { useMember } from './hook-use/member.js';
25
+ export { useMention } from './hook-use/mention.js';
26
+ export { useMessage, useSend, useSends } from './hook-use/message.js';
27
+ export { usePermission } from './hook-use/permission.js';
28
+ export { useReaction } from './hook-use/reaction.js';
29
+ export { useRequest } from './hook-use/request.js';
30
+ export { useRole } from './hook-use/role.js';
31
+ export { useUser } from './hook-use/user.js';
32
+ export { getCurrentEvent, withEventContext } from './hook-event-context.js';
33
+ export { createEventValue, createSelects, onSelects, onState, unChildren, unState, useState } from './event-utils.js';
19
34
  export { useObserver, useSubscribe } from './hook-use-subscribe.js';
20
- export { MessageDirect, createDataFormat, createEventValue, format, getMessageIntent, sendToChannel, sendToUser } from './message-api.js';
35
+ export { MessageDirect, createDataFormat, format, getMessageIntent, sendToChannel, sendToUser } from './message-api.js';
21
36
  export { Format, FormatButtonGroup, FormatMarkDown, createEvent } from './message-format.js';
22
37
  export { Attachment, Audio, BT, Button, Image, ImageFile, ImageURL, Link, MD, Markdown, MarkdownOriginal, Mention, Text, Video } from './message-format-old.js';
@@ -1,12 +1,6 @@
1
1
  import { DataEnums, OnDataFormatFunc } from '../types';
2
2
  import { Result } from '../core';
3
3
  import { Format } from './message-format';
4
- type BaseMap = {
5
- [key: string]: unknown;
6
- };
7
- export declare const createEventValue: <T extends keyof R, R extends BaseMap>(event: {
8
- value: R[T];
9
- }) => R[T];
10
4
  export declare const format: OnDataFormatFunc;
11
5
  export declare const createDataFormat: OnDataFormatFunc;
12
6
  export declare class MessageDirect {
@@ -5,9 +5,6 @@ import 'path';
5
5
  import 'yaml';
6
6
  import { createResult } from '../core/utils.js';
7
7
 
8
- const createEventValue = (event) => {
9
- return event.value;
10
- };
11
8
  const format = (...data) => {
12
9
  if (!data || data.length === 0) {
13
10
  logger.error({
@@ -111,4 +108,4 @@ const getMessageIntent = async () => {
111
108
  return createResult(ResultCode.Ok, '获取成功', results[0]?.data ?? null);
112
109
  };
113
110
 
114
- export { MessageDirect, createDataFormat, createEventValue, format, getMessageIntent, sendToChannel, sendToUser };
111
+ export { MessageDirect, createDataFormat, format, getMessageIntent, sendToChannel, sendToUser };
@@ -32,7 +32,7 @@ declare const Markdown: {
32
32
  italic(text: string): DataMarkdownItalic;
33
33
  italicStar(text: string): DataMarkdownItalicStar;
34
34
  strikethrough(text: string): DataMarkdownStrikethrough;
35
- link(text: string, url: string): DataMarkdownLink;
35
+ link(text: string, url?: string): DataMarkdownLink;
36
36
  image(url: string, options?: {
37
37
  width?: number;
38
38
  height?: number;
@@ -56,7 +56,7 @@ export declare const MD: {
56
56
  italic(text: string): DataMarkdownItalic;
57
57
  italicStar(text: string): DataMarkdownItalicStar;
58
58
  strikethrough(text: string): DataMarkdownStrikethrough;
59
- link(text: string, url: string): DataMarkdownLink;
59
+ link(text: string, url?: string): DataMarkdownLink;
60
60
  image(url: string, options?: {
61
61
  width?: number;
62
62
  height?: number;
@@ -1,4 +1,4 @@
1
- import { BT, MD, Text, Image, Mention, MarkdownOriginal, Attachment, Audio, Video, Link, ImageFile, ImageURL } from './message-format-old.js';
1
+ import { Text, Image, Mention, BT, MD, MarkdownOriginal, Attachment, Audio, Video, Link, ImageFile, ImageURL } from './message-format-old.js';
2
2
  export { Button, Markdown } from './message-format-old.js';
3
3
 
4
4
  class FormatButtonGroup {
@@ -13,12 +13,13 @@ import '../../app/event-middleware.js';
13
13
  import { onProcessor } from '../../app/event-processor.js';
14
14
  import '../../app/event-response.js';
15
15
  import { createResult } from '../../core/utils.js';
16
- import '../../app/hook-use-api.js';
17
- import '../../app/message-api.js';
18
- import '../../app/message-format-old.js';
16
+ import '../../app/hook-event-context.js';
17
+ import '../../app/event-utils.js';
19
18
  import { apiResolves, apiTimeouts, actionResolves, actionTimeouts, FULL_RECEIVE_HEADER } from '../processor/config.js';
20
- import { createWSConnector } from './base.js';
21
19
  import { setDirectSend } from '../processor/transport.js';
20
+ import '../../app/message-format-old.js';
21
+ import '../../app/message-api.js';
22
+ import { createWSConnector } from './base.js';
22
23
  import { createDirectServer } from '../../process/direct-channel.js';
23
24
 
24
25
  const handleParsedMessage = (parsedMessage) => {
package/lib/client.js CHANGED
@@ -26,9 +26,10 @@ import './app/event-group.js';
26
26
  import './app/event-middleware.js';
27
27
  import './app/event-processor.js';
28
28
  import './app/event-response.js';
29
- import './app/hook-use-api.js';
30
- import './app/message-api.js';
29
+ import './app/hook-event-context.js';
30
+ import './app/event-utils.js';
31
31
  import './app/message-format-old.js';
32
+ import './app/message-api.js';
32
33
  import './process/platform.js';
33
34
  import './process/module.js';
34
35
  import { createServer } from './server/main.js';
@@ -1,6 +1,43 @@
1
1
  import type { Package } from '../types';
2
2
  type ConfigValue = {
3
3
  [key: string]: any;
4
+ master_key?: {
5
+ [key: string]: boolean;
6
+ } | string[];
7
+ master_id?: {
8
+ [key: string]: boolean;
9
+ } | string[];
10
+ bot_key?: {
11
+ [key: string]: boolean;
12
+ } | string[];
13
+ bot_id?: {
14
+ [key: string]: boolean;
15
+ } | string[];
16
+ disabled_text_regular?: string;
17
+ disabled_selects?: {
18
+ [key: string]: boolean;
19
+ };
20
+ disabled_user_id?: {
21
+ [key: string]: boolean;
22
+ } | string[];
23
+ disabled_user_key?: {
24
+ [key: string]: boolean;
25
+ } | string[];
26
+ redirect_regular?: string;
27
+ redirect_target?: string;
28
+ redirect_text_regular?: string;
29
+ redirect_text_target?: string;
30
+ mapping_text?: {
31
+ regular?: string;
32
+ target?: string;
33
+ }[];
34
+ processor?: {
35
+ repeated_event_time?: number;
36
+ repeated_user_time?: number;
37
+ };
38
+ apps?: string[] | {
39
+ [key: string]: boolean;
40
+ };
4
41
  };
5
42
  type ConfigListener<T extends ConfigValue = ConfigValue> = (value: T) => void;
6
43
  declare class ConfigCore<T extends ConfigValue = ConfigValue> {
package/lib/core/index.js CHANGED
@@ -1,3 +1,3 @@
1
1
  export { ResultCode } from './variable.js';
2
2
  export { getConfig, getConfigValue, onWatchConfigValue } from './config.js';
3
- export { createEventName, createHash, createResult, createUserHashKey, fastHash, getCachedRegExp, getInputExportPath, getRecursiveDirFiles, isMaster, sanitizeForSerialization, showErrorModule, stringToNumber, useUserHashKey } from './utils.js';
3
+ export { createEventName, createHash, createResult, createUserHashKey, fastHash, getCachedRegExp, getInputExportPath, getRecursiveDirFiles, isMaster, matchIn, sanitizeForSerialization, showErrorModule, stringToNumber, useUserHashKey } from './utils.js';
@@ -14,7 +14,8 @@ export declare const useUserHashKey: (event: {
14
14
  UserId: string;
15
15
  Platform: string;
16
16
  }) => string;
17
- export declare const isMaster: (UserId: string, platform: string) => any;
17
+ export declare const matchIn: (source: any, key: string) => boolean;
18
+ export declare const isMaster: (UserId: string, platform: string) => boolean;
18
19
  export declare const createEventName: (url: string, appKey: string) => string;
19
20
  export declare const stringToNumber: (str: string, size?: number) => number;
20
21
  export declare const getRecursiveDirFiles: (dir: string, condition?: (func: Dirent) => boolean) => {
package/lib/core/utils.js CHANGED
@@ -37,20 +37,23 @@ const createUserHashKey = (event) => {
37
37
  return fastHash(`${event.Platform}:${event.UserId}`);
38
38
  };
39
39
  const useUserHashKey = createUserHashKey;
40
+ const matchIn = (source, key) => {
41
+ if (Array.isArray(source)) {
42
+ return source.includes(key);
43
+ }
44
+ if (source && typeof source === 'object') {
45
+ return Object.prototype.hasOwnProperty.call(source, key) && !!source[key];
46
+ }
47
+ return false;
48
+ };
40
49
  const isMaster = (UserId, platform) => {
41
50
  const values = getConfigValue() || {};
42
- const mainMasterKey = values.master_key || [];
43
- const mainMasterId = values.master_id || [];
44
- const value = values[platform] || {};
45
- const masterKey = value.master_key || [];
46
- const masterId = value.master_id || [];
51
+ const value = values[platform] && typeof values[platform] === 'object' ? values[platform] : {};
47
52
  const UserKey = createUserHashKey({
48
53
  Platform: platform,
49
54
  UserId: UserId
50
55
  });
51
- const cMaster = mainMasterKey.concat(masterKey);
52
- const cMasterId = mainMasterId.concat(masterId);
53
- return cMaster.includes(UserKey) || cMasterId.includes(UserId);
56
+ return matchIn(values.master_key, UserKey) || matchIn(values.master_id, UserId) || matchIn(value.master_key, UserKey) || matchIn(value.master_id, UserId);
54
57
  };
55
58
  const createEventName = (url, appKey) => {
56
59
  let uri = url;
@@ -152,4 +155,4 @@ const createResult = (code, message, data) => {
152
155
  };
153
156
  };
154
157
 
155
- export { createEventName, createHash, createResult, createUserHashKey, fastHash, getCachedRegExp, getInputExportPath, getRecursiveDirFiles, isMaster, sanitizeForSerialization, showErrorModule, stringToNumber, useUserHashKey };
158
+ export { createEventName, createHash, createResult, createUserHashKey, fastHash, getCachedRegExp, getInputExportPath, getRecursiveDirFiles, isMaster, matchIn, sanitizeForSerialization, showErrorModule, stringToNumber, useUserHashKey };
package/lib/global.d.ts CHANGED
@@ -1,7 +1,9 @@
1
- import type { DefineChildrenFunc, OnResponseReversalFunc, OnMiddlewareReversalFunc, OnSelectsFunc, OnDataFormatFunc, OnResponseReversalFuncBack, OnGroupFunc, OnMiddlewareReversalFuncBack, DefineResponseFunc, defineMiddlewareFunc, StoreChildrenApp, StateSubscribeMap, SubscribeKeysMap, LoggerUtils, ResponseState } from './types';
1
+ import type { DefineChildrenFunc, OnResponseReversalFunc, OnMiddlewareReversalFunc, OnSelectsFunc, OnDataFormatFunc, OnResponseReversalFuncBack, OnGroupFunc, OnMiddlewareReversalFuncBack, DefineResponseFunc, defineMiddlewareFunc, StoreChildrenApp, StateSubscribeMap, SubscribeKeysMap, LoggerUtils, ResponseState, StartOptions } from './types';
2
2
  import WebSocket, { Server } from 'ws';
3
3
  import { IncomingMessage } from 'http';
4
4
  declare global {
5
+ var __config: any;
6
+ var __options: StartOptions;
5
7
  var logger: LoggerUtils;
6
8
  var alemonjsCore: {
7
9
  storeState: ResponseState;
package/lib/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  export { ActionsEventEnum } from './types/event/actions.js';
2
2
  export { ResultCode } from './core/variable.js';
3
3
  export { getConfig, getConfigValue, onWatchConfigValue } from './core/config.js';
4
- export { createEventName, createHash, createResult, createUserHashKey, fastHash, getCachedRegExp, getInputExportPath, getRecursiveDirFiles, isMaster, sanitizeForSerialization, showErrorModule, stringToNumber, useUserHashKey } from './core/utils.js';
4
+ export { createEventName, createHash, createResult, createUserHashKey, fastHash, getCachedRegExp, getInputExportPath, getRecursiveDirFiles, isMaster, matchIn, sanitizeForSerialization, showErrorModule, stringToNumber, useUserHashKey } from './core/utils.js';
5
5
  export { cbpClient } from './cbp/connects/client.js';
6
6
  export { cbpPlatform } from './cbp/connects/platform.js';
7
7
  export { cbpServer } from './cbp/server/main.js';
@@ -21,10 +21,25 @@ export { expendCycle } from './app/event-processor-cycle.js';
21
21
  export { expendEvent } from './app/event-processor-event.js';
22
22
  export { expendMiddleware } from './app/event-processor-middleware.js';
23
23
  export { expendSubscribe, expendSubscribeCreate, expendSubscribeMount, expendSubscribeUnmount } from './app/event-processor-subscribe.js';
24
- export { createSelects, onSelects, unChildren, useAnnounce, useChannel, useClient, useGuild, useHistory, useMe, useMedia, useMember, useMention, useMessage, usePermission, useReaction, useRequest, useRole, useSend, useSends, useUser } from './app/hook-use-api.js';
25
- export { onState, unState, useState } from './app/hook-use-state.js';
24
+ export { useAnnounce } from './app/hook-use/announce.js';
25
+ export { useChannel } from './app/hook-use/channel.js';
26
+ export { useClient } from './app/hook-use/client.js';
27
+ export { useGuild } from './app/hook-use/guild.js';
28
+ export { useHistory } from './app/hook-use/history.js';
29
+ export { useMedia } from './app/hook-use/media.js';
30
+ export { useMe } from './app/hook-use/me.js';
31
+ export { useMember } from './app/hook-use/member.js';
32
+ export { useMention } from './app/hook-use/mention.js';
33
+ export { useMessage, useSend, useSends } from './app/hook-use/message.js';
34
+ export { usePermission } from './app/hook-use/permission.js';
35
+ export { useReaction } from './app/hook-use/reaction.js';
36
+ export { useRequest } from './app/hook-use/request.js';
37
+ export { useRole } from './app/hook-use/role.js';
38
+ export { useUser } from './app/hook-use/user.js';
39
+ export { getCurrentEvent, withEventContext } from './app/hook-event-context.js';
40
+ export { createEventValue, createSelects, onSelects, onState, unChildren, unState, useState } from './app/event-utils.js';
26
41
  export { useObserver, useSubscribe } from './app/hook-use-subscribe.js';
27
- export { MessageDirect, createDataFormat, createEventValue, format, getMessageIntent, sendToChannel, sendToUser } from './app/message-api.js';
42
+ export { MessageDirect, createDataFormat, format, getMessageIntent, sendToChannel, sendToUser } from './app/message-api.js';
28
43
  export { Format, FormatButtonGroup, FormatMarkDown, createEvent } from './app/message-format.js';
29
44
  export { start } from './main.js';
30
45
  export { Attachment, Audio, BT, Button, Image, ImageFile, ImageURL, Link, MD, Markdown, MarkdownOriginal, Mention, Text, Video } from './app/message-format-old.js';
@@ -51,7 +51,7 @@ export type DataMarkdownLink = {
51
51
  type: 'MD.link';
52
52
  value: {
53
53
  text: string;
54
- url: string;
54
+ url?: string;
55
55
  };
56
56
  };
57
57
  export type DataMarkdownImage = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "alemonjs",
3
- "version": "2.1.47",
3
+ "version": "2.1.49",
4
4
  "description": "bot script",
5
5
  "author": "lemonade",
6
6
  "license": "MIT",