alemonjs 2.1.0-alpha.23 → 2.1.0-alpha.25

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.
@@ -29,7 +29,7 @@ const showLog = (event, select) => {
29
29
  });
30
30
  }
31
31
  else {
32
- let baseLog = `[Name: ${select}]`;
32
+ let baseLog = `[${ResultCode.Ok}][Name: ${select}]`;
33
33
  if (typeof event['ChannelId'] === 'string' && event['ChannelId'] !== '') {
34
34
  baseLog += `[ChannelId: ${event['ChannelId']}]`;
35
35
  }
@@ -1,28 +1,24 @@
1
1
  import { EventKeys, Events } from '../typing/event/map.js';
2
+ import { User } from '../typing/event/base/user.js';
2
3
  import { Result } from '../core/utils.js';
3
4
  import '../global.js';
4
5
  import { DataEnums } from '../typing/message/index.js';
5
6
 
7
+ type Options = {
8
+ UserId?: string;
9
+ UserKey?: string;
10
+ UserName?: string;
11
+ IsMaster?: boolean;
12
+ IsBot?: boolean;
13
+ };
6
14
  /**
7
15
  * 使用提及。
8
16
  * @param {Object} event - 事件对象,包含触发提及的相关信息。
9
17
  * @throws {Error} - 如果 event 无效,抛出错误。
10
18
  */
11
- declare const useMention: <T extends EventKeys>(event: Events[T]) => readonly [{
12
- find: (options: {
13
- UserId?: string;
14
- UserKey?: string;
15
- UserName?: string;
16
- IsMaster?: boolean;
17
- IsBot?: boolean;
18
- }) => Promise<Result>;
19
- findOne: (options?: {
20
- UserId?: string;
21
- UserKey?: string;
22
- UserName?: string;
23
- IsMaster?: boolean;
24
- IsBot?: boolean;
25
- }) => Promise<Result>;
19
+ declare const useMention: <T extends EventKeys>(event: Events[T]) => [{
20
+ find: (options: Options) => Promise<Result<User[]>>;
21
+ findOne: (options?: Options) => Promise<Result<User | null>>;
26
22
  }];
27
23
  /**
28
24
  * 消息处理
@@ -39,7 +39,7 @@ const useMention = (event) => {
39
39
  return createResult(ResultCode.Fail, err?.message || 'Failed to get mention data', null);
40
40
  }
41
41
  if (!Array.isArray(res)) {
42
- return createResult(ResultCode.Fail, 'No mention data found', null);
42
+ return createResult(ResultCode.Warn, 'No mention data found', null);
43
43
  }
44
44
  // 过滤出符合条件的数据
45
45
  const data = res.filter(item => {
@@ -83,7 +83,7 @@ const useMention = (event) => {
83
83
  return createResult(ResultCode.Fail, err?.message || 'Failed to get mention data', null);
84
84
  }
85
85
  if (!Array.isArray(res)) {
86
- return createResult(ResultCode.Fail, 'No mention data found', null);
86
+ return createResult(ResultCode.Warn, 'No mention data found', null);
87
87
  }
88
88
  // 根据条件查找
89
89
  const data = res.find(item => {
@@ -105,7 +105,7 @@ const useMention = (event) => {
105
105
  return true;
106
106
  });
107
107
  if (!data) {
108
- return createResult(ResultCode.Fail, 'No mention data found', null);
108
+ return createResult(ResultCode.Warn, 'No mention data found', null);
109
109
  }
110
110
  return createResult(ResultCode.Ok, 'Successfully retrieved mention data', data);
111
111
  }
package/lib/app/store.js CHANGED
@@ -17,13 +17,28 @@ const createLogger = () => {
17
17
  mkdirSync(logDir, { recursive: true });
18
18
  // 当环境被设置为 development 时。被视为 trace
19
19
  const level = process.env.NODE_ENV === 'development' ? 'trace' : 'info';
20
+ const hideTime = process.env.LOGGER_TIME === 'false' ? true : false;
21
+ const hideLevel = process.env.LOGGER_LEVEL === 'false' ? true : false;
22
+ let pattern = '';
23
+ if (hideTime && hideLevel) {
24
+ pattern = `%m`;
25
+ }
26
+ else if (hideTime && !hideLevel) {
27
+ pattern = `[%p] %m`;
28
+ }
29
+ else if (!hideTime && hideLevel) {
30
+ pattern = `[%d{yyyy-MM-dd hh:mm:ss}] %m`;
31
+ }
32
+ else {
33
+ pattern = `[%d{yyyy-MM-dd hh:mm:ss}][%p] %m`;
34
+ }
20
35
  log4js.configure({
21
36
  appenders: {
22
37
  console: {
23
38
  type: 'console',
24
39
  layout: {
25
40
  type: 'pattern',
26
- pattern: `%[[%d{yyyy-MM-dd hh:mm:ss}][%5.5p]%] %m`
41
+ pattern: pattern
27
42
  }
28
43
  },
29
44
  command: {
@@ -34,7 +49,7 @@ const createLogger = () => {
34
49
  alwaysIncludePattern: true,
35
50
  layout: {
36
51
  type: 'pattern',
37
- pattern: `%[[%d{yyyy-MM-dd hh:mm:ss}][%5.5p]%] %m`
52
+ pattern: pattern
38
53
  }
39
54
  },
40
55
  error: {
@@ -45,7 +60,7 @@ const createLogger = () => {
45
60
  alwaysIncludePattern: true,
46
61
  layout: {
47
62
  type: 'pattern',
48
- pattern: `%[[%d{yyyy-MM-dd hh:mm:ss}][%5.5p]%] %m`
63
+ pattern: pattern
49
64
  }
50
65
  }
51
66
  },
@@ -59,10 +59,10 @@ declare const getInputExportPath: (input?: string) => any;
59
59
  * 异步方法。且需要读取返回值的进行判断的,
60
60
  * 都要以 Result 作为返回值
61
61
  */
62
- type Result = {
62
+ type Result<T = any> = {
63
63
  code: ResultCode;
64
64
  message: string | Object;
65
- data: any;
65
+ data: T;
66
66
  };
67
67
  /**
68
68
  * 创建结果
@@ -70,7 +70,7 @@ type Result = {
70
70
  * @param message
71
71
  * @returns
72
72
  */
73
- declare const createResult: (code: ResultCode, message: string | Object, data?: any) => Result;
73
+ declare const createResult: <T>(code: ResultCode, message: string | Object, data?: T) => Result<T>;
74
74
 
75
75
  export { createEventName, createHash, createResult, getInputExportPath, getRecursiveDirFiles, showErrorModule, stringToNumber, useUserHashKey };
76
76
  export type { Result };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "alemonjs",
3
- "version": "2.1.0-alpha.23",
3
+ "version": "2.1.0-alpha.25",
4
4
  "description": "bot script",
5
5
  "author": "lemonade",
6
6
  "license": "MIT",