alemonjs 2.1.47 → 2.1.48

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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2013-present, Yuxi (Evan) You
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIdED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -2,7 +2,7 @@ import { getConfigValue } from '../core/config.js';
2
2
  import { processorRepeatedClearTimeMin, processorRepeatedClearTimeMax, processorRepeatedEventTime, processorRepeatedUserTime, processorRepeatedClearSize, processorMaxMapSize } from '../core/variable.js';
3
3
  import { expendCycle } from './event-processor-cycle.js';
4
4
  import { ProcessorEventAutoClearMap, ProcessorEventUserAutoClearMap } from './store.js';
5
- import { getCachedRegExp, fastHash } from '../core/utils.js';
5
+ import { getCachedRegExp, matchIn, fastHash } from '../core/utils.js';
6
6
 
7
7
  const filter = ({ Now, store, INTERVAL }, MessageId) => {
8
8
  if (store.has(MessageId)) {
@@ -69,12 +69,12 @@ const onProcessor = (name, event, data) => {
69
69
  if (disabledSelects[name]) {
70
70
  return;
71
71
  }
72
- const disabledUserId = value?.disabled_user_id ?? {};
73
- if (event['UserId'] && disabledUserId[event['UserId']]) {
72
+ const disabledUserId = value?.disabled_user_id;
73
+ if (event['UserId'] && matchIn(disabledUserId, event['UserId'])) {
74
74
  return;
75
75
  }
76
- const disabledUserKey = value?.disabled_user_key ?? {};
77
- if (event['UserKey'] && disabledUserKey[event['UserKey']]) {
76
+ const disabledUserKey = value?.disabled_user_key;
77
+ if (event['UserKey'] && matchIn(disabledUserKey, event['UserKey'])) {
78
78
  return;
79
79
  }
80
80
  const redirectRegular = value?.redirect_regular ?? value?.redirect_text_regular;
@@ -98,20 +98,20 @@ const onProcessor = (name, event, data) => {
98
98
  }
99
99
  }
100
100
  }
101
- const masterId = value?.master_id ?? {};
102
- const masterKey = value?.master_key ?? {};
103
- if (event['UserId'] && masterId[event['UserId']]) {
101
+ const masterId = value?.master_id;
102
+ const masterKey = value?.master_key;
103
+ if (event['UserId'] && matchIn(masterId, event['UserId'])) {
104
104
  event['isMaster'] = true;
105
105
  }
106
- else if (event['UserKey'] && masterKey[event['UserKey']]) {
106
+ else if (event['UserKey'] && matchIn(masterKey, event['UserKey'])) {
107
107
  event['isMaster'] = true;
108
108
  }
109
- const botId = value?.bot_id ?? {};
110
- const botKey = value?.bot_key ?? {};
111
- if (event['UserId'] && botId[event['UserId']]) {
109
+ const botId = value?.bot_id;
110
+ const botKey = value?.bot_key;
111
+ if (event['UserId'] && matchIn(botId, event['UserId'])) {
112
112
  event['isBot'] = true;
113
113
  }
114
- else if (event['UserKey'] && botKey[event['UserKey']]) {
114
+ else if (event['UserKey'] && matchIn(botKey, event['UserKey'])) {
115
115
  event['isBot'] = true;
116
116
  }
117
117
  const Now = Date.now();
@@ -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,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';
@@ -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.48",
4
4
  "description": "bot script",
5
5
  "author": "lemonade",
6
6
  "license": "MIT",
@@ -69,5 +69,5 @@
69
69
  "type": "git",
70
70
  "url": "https://github.com/lemonade-lab/alemonjs.git"
71
71
  },
72
- "gitHead": "c6aa5616afe091a37610dad22fbb2d2618d943b8"
73
- }
72
+ "gitHead": "e50477125586204c6e56a8ecfe3391136f5fe74b"
73
+ }