alemonjs 1.3.2 → 2.0.0-rc.0

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 (178) hide show
  1. package/lib/app/event-files.js +64 -0
  2. package/lib/app/event-processor.d.ts +11 -0
  3. package/lib/app/event-processor.js +107 -0
  4. package/lib/app/event-utlis.d.ts +49 -0
  5. package/lib/app/event-utlis.js +30 -0
  6. package/lib/config.d.ts +33 -0
  7. package/lib/config.js +187 -0
  8. package/lib/hook/message-format.d.ts +110 -0
  9. package/lib/hook/message-format.js +120 -0
  10. package/lib/hook/use-api.d.ts +44 -0
  11. package/lib/hook/use-api.js +41 -0
  12. package/lib/index.d.ts +26 -0
  13. package/lib/index.js +40 -0
  14. package/lib/typing.d.ts +78 -0
  15. package/package.json +11 -62
  16. package/{config/tsconfig.json → tsconfig.json} +10 -21
  17. package/LICENSE +0 -21
  18. package/README.md +0 -110
  19. package/dist/api/index.d.ts +0 -31
  20. package/dist/bot.d.ts +0 -2
  21. package/dist/config/index.d.ts +0 -2
  22. package/dist/config/login.d.ts +0 -9
  23. package/dist/config/types.d.ts +0 -15
  24. package/dist/core/config.d.ts +0 -8
  25. package/dist/core/func.d.ts +0 -47
  26. package/dist/core/global.d.ts +0 -15
  27. package/dist/core/index.d.ts +0 -11
  28. package/dist/core/koa/config.d.ts +0 -5
  29. package/dist/core/koa/index.d.ts +0 -4
  30. package/dist/core/koa/main.d.ts +0 -2
  31. package/dist/core/koa/middleware.d.ts +0 -8
  32. package/dist/core/koa/server.d.ts +0 -11
  33. package/dist/core/koa/types.d.ts +0 -4
  34. package/dist/core/main.d.ts +0 -13
  35. package/dist/core/processor/alemon.d.ts +0 -36
  36. package/dist/core/processor/application.d.ts +0 -14
  37. package/dist/core/processor/configs.d.ts +0 -20
  38. package/dist/core/processor/data.d.ts +0 -2
  39. package/dist/core/processor/help.d.ts +0 -6
  40. package/dist/core/processor/listdouble.d.ts +0 -21
  41. package/dist/core/processor/log.d.ts +0 -1
  42. package/dist/core/processor/path.d.ts +0 -5
  43. package/dist/core/processor/plugin.d.ts +0 -37
  44. package/dist/core/processor/read.d.ts +0 -1
  45. package/dist/core/processor/subscribe.d.ts +0 -11
  46. package/dist/core/processor/types.d.ts +0 -33
  47. package/dist/core/restart.d.ts +0 -10
  48. package/dist/core/types.d.ts +0 -72
  49. package/dist/core/typings.d.ts +0 -91
  50. package/dist/core/utils/buffer.d.ts +0 -9
  51. package/dist/core/utils/counter.d.ts +0 -7
  52. package/dist/core/utils/from.d.ts +0 -6
  53. package/dist/core/utils/hash.d.ts +0 -1
  54. package/dist/core/utils/index.d.ts +0 -5
  55. package/dist/core/utils/ip.d.ts +0 -8
  56. package/dist/default/index.d.ts +0 -1
  57. package/dist/default/types.d.ts +0 -29
  58. package/dist/define/index.d.ts +0 -2
  59. package/dist/define/login.d.ts +0 -8
  60. package/dist/define/types.d.ts +0 -26
  61. package/dist/email/default.d.ts +0 -2
  62. package/dist/email/email.d.ts +0 -7
  63. package/dist/email/index.d.ts +0 -2
  64. package/dist/email/types.d.ts +0 -10
  65. package/dist/export.d.ts +0 -9
  66. package/dist/file/back.d.ts +0 -1
  67. package/dist/file/client.d.ts +0 -7
  68. package/dist/file/config.d.ts +0 -3
  69. package/dist/file/default.d.ts +0 -2
  70. package/dist/file/file.d.ts +0 -7
  71. package/dist/file/image.d.ts +0 -5
  72. package/dist/file/index.d.ts +0 -5
  73. package/dist/file/main.d.ts +0 -4
  74. package/dist/file/types.d.ts +0 -8
  75. package/dist/index.d.ts +0 -2
  76. package/dist/index.js +0 -8776
  77. package/dist/log.d.ts +0 -8
  78. package/dist/main.d.ts +0 -3
  79. package/dist/platform/discord/alemon/bot.d.ts +0 -6
  80. package/dist/platform/discord/alemon/controller.d.ts +0 -39
  81. package/dist/platform/discord/alemon/conversation.d.ts +0 -1
  82. package/dist/platform/discord/alemon/message/CHANNEL_TOPIC_UPDATE.d.ts +0 -5
  83. package/dist/platform/discord/alemon/message/CHANNEL_UPDATE.d.ts +0 -42
  84. package/dist/platform/discord/alemon/message/GUILD_MEMBER_ADD.d.ts +0 -23
  85. package/dist/platform/discord/alemon/message/GUILD_MEMBER_REMOVE.d.ts +0 -12
  86. package/dist/platform/discord/alemon/message/GUILD_MEMBER_UPDATE.d.ts +0 -27
  87. package/dist/platform/discord/alemon/message/MESSAGE_CREATE.d.ts +0 -53
  88. package/dist/platform/discord/alemon/message/MESSAGE_DELETE.d.ts +0 -5
  89. package/dist/platform/discord/alemon/message/MESSAGE_REACTION_ADD.d.ts +0 -36
  90. package/dist/platform/discord/alemon/message/MESSAGE_UPDATE.d.ts +0 -50
  91. package/dist/platform/discord/alemon/message/PRESENCE_UPDATE.d.ts +0 -57
  92. package/dist/platform/discord/alemon/message/TYPING_START.d.ts +0 -29
  93. package/dist/platform/discord/alemon/message/VOICE_CHANNEL_STATUS_UPDATE.d.ts +0 -5
  94. package/dist/platform/discord/alemon/message/VOICE_STATE_UPDATE.d.ts +0 -36
  95. package/dist/platform/discord/alemon/reply.d.ts +0 -8
  96. package/dist/platform/discord/alemon/segment.d.ts +0 -2
  97. package/dist/platform/discord/index.d.ts +0 -2
  98. package/dist/platform/discord/sdk/api.d.ts +0 -155
  99. package/dist/platform/discord/sdk/config.d.ts +0 -7
  100. package/dist/platform/discord/sdk/index.d.ts +0 -6
  101. package/dist/platform/discord/sdk/intents.d.ts +0 -2
  102. package/dist/platform/discord/sdk/log.d.ts +0 -2
  103. package/dist/platform/discord/sdk/types.d.ts +0 -21
  104. package/dist/platform/discord/sdk/wss.d.ts +0 -8
  105. package/dist/platform/discord/sdk/wss.types.d.ts +0 -8
  106. package/dist/platform/index.d.ts +0 -4
  107. package/dist/platform/kook/alemon/bot.d.ts +0 -6
  108. package/dist/platform/kook/alemon/controller.d.ts +0 -91
  109. package/dist/platform/kook/alemon/conversation.d.ts +0 -2
  110. package/dist/platform/kook/alemon/direct.d.ts +0 -42
  111. package/dist/platform/kook/alemon/message/GUILD_MEMBER_ADD.d.ts +0 -2
  112. package/dist/platform/kook/alemon/message/GUILD_MEMBER_REMOVE.d.ts +0 -2
  113. package/dist/platform/kook/alemon/message/INTERACTION.d.ts +0 -2
  114. package/dist/platform/kook/alemon/message/MESSAGES.d.ts +0 -2
  115. package/dist/platform/kook/alemon/message/PUBLIC_GUILD_MESSAGES.d.ts +0 -2
  116. package/dist/platform/kook/alemon/message/REACTIONS.d.ts +0 -2
  117. package/dist/platform/kook/alemon/reply.d.ts +0 -5
  118. package/dist/platform/kook/alemon/segment.d.ts +0 -2
  119. package/dist/platform/kook/index.d.ts +0 -2
  120. package/dist/platform/kook/sdk/api.d.ts +0 -161
  121. package/dist/platform/kook/sdk/config.d.ts +0 -5
  122. package/dist/platform/kook/sdk/index.d.ts +0 -5
  123. package/dist/platform/kook/sdk/log.d.ts +0 -2
  124. package/dist/platform/kook/sdk/typings.d.ts +0 -258
  125. package/dist/platform/kook/sdk/wss.d.ts +0 -8
  126. package/dist/platform/kook/sdk/wss.types.d.ts +0 -5
  127. package/dist/platform/ntqq/alemon/bot.d.ts +0 -6
  128. package/dist/platform/ntqq/alemon/controller.d.ts +0 -49
  129. package/dist/platform/ntqq/alemon/conversation.d.ts +0 -1
  130. package/dist/platform/ntqq/alemon/direct.d.ts +0 -5
  131. package/dist/platform/ntqq/alemon/message/C2C_MESSAGE_CREATE.d.ts +0 -2
  132. package/dist/platform/ntqq/alemon/message/GROUP_AT_MESSAGE_CREATE.d.ts +0 -2
  133. package/dist/platform/ntqq/alemon/reply.d.ts +0 -5
  134. package/dist/platform/ntqq/alemon/segment.d.ts +0 -2
  135. package/dist/platform/ntqq/alemon/types.d.ts +0 -20
  136. package/dist/platform/ntqq/alemon/utils.d.ts +0 -6
  137. package/dist/platform/ntqq/index.d.ts +0 -2
  138. package/dist/platform/ntqq/sdk/api.d.ts +0 -123
  139. package/dist/platform/ntqq/sdk/config.d.ts +0 -11
  140. package/dist/platform/ntqq/sdk/index.d.ts +0 -6
  141. package/dist/platform/ntqq/sdk/intents.d.ts +0 -3
  142. package/dist/platform/ntqq/sdk/log.d.ts +0 -2
  143. package/dist/platform/ntqq/sdk/typings.d.ts +0 -2
  144. package/dist/platform/ntqq/sdk/wss.d.ts +0 -8
  145. package/dist/platform/ntqq/sdk/wss.types.d.ts +0 -12
  146. package/dist/platform/qq/alemon/bot.d.ts +0 -6
  147. package/dist/platform/qq/alemon/controller.d.ts +0 -39
  148. package/dist/platform/qq/alemon/conversation.d.ts +0 -1
  149. package/dist/platform/qq/alemon/direct.d.ts +0 -6
  150. package/dist/platform/qq/alemon/message/AT_MESSAGE_CREATE.d.ts +0 -35
  151. package/dist/platform/qq/alemon/message/CHANNEL_CREATE.d.ts +0 -15
  152. package/dist/platform/qq/alemon/message/CHANNEL_DELETE.d.ts +0 -15
  153. package/dist/platform/qq/alemon/message/CHANNEL_UPDATE.d.ts +0 -15
  154. package/dist/platform/qq/alemon/message/DIRECT_MESSAGE_CREATE.d.ts +0 -29
  155. package/dist/platform/qq/alemon/message/DIRECT_MESSAGE_DELETE.d.ts +0 -17
  156. package/dist/platform/qq/alemon/message/GUILD_CREATE.d.ts +0 -15
  157. package/dist/platform/qq/alemon/message/GUILD_DELETE.d.ts +0 -15
  158. package/dist/platform/qq/alemon/message/GUILD_MEMBER_ADD.d.ts +0 -14
  159. package/dist/platform/qq/alemon/message/GUILD_MEMBER_REMOVE.d.ts +0 -14
  160. package/dist/platform/qq/alemon/message/GUILD_MEMBER_UPDATE.d.ts +0 -14
  161. package/dist/platform/qq/alemon/message/GUILD_UPDATE.d.ts +0 -15
  162. package/dist/platform/qq/alemon/message/INTERACTION_CREATE.d.ts +0 -1
  163. package/dist/platform/qq/alemon/message/MESSAGE_CREATE.d.ts +0 -1
  164. package/dist/platform/qq/alemon/message/MESSAGE_DELETE.d.ts +0 -1
  165. package/dist/platform/qq/alemon/message/MESSAGE_REACTION_ADD.d.ts +0 -13
  166. package/dist/platform/qq/alemon/message/MESSAGE_REACTION_REMOVE.d.ts +0 -13
  167. package/dist/platform/qq/alemon/message/PUBLIC_MESSAGE_DELETE.d.ts +0 -15
  168. package/dist/platform/qq/alemon/reply.d.ts +0 -8
  169. package/dist/platform/qq/alemon/segment.d.ts +0 -2
  170. package/dist/platform/qq/index.d.ts +0 -2
  171. package/dist/platform/qq/sdk/api.d.ts +0 -177
  172. package/dist/platform/qq/sdk/config.d.ts +0 -11
  173. package/dist/platform/qq/sdk/index.d.ts +0 -5
  174. package/dist/platform/qq/sdk/intents.d.ts +0 -2
  175. package/dist/platform/qq/sdk/log.d.ts +0 -2
  176. package/dist/platform/qq/sdk/typings.d.ts +0 -2
  177. package/dist/platform/qq/sdk/wss.d.ts +0 -8
  178. package/dist/platform/qq/sdk/wss.types.d.ts +0 -12
@@ -0,0 +1,64 @@
1
+ import { join, dirname } from 'node:path';
2
+ import fs from 'node:fs';
3
+
4
+ const _dir = './src/apps';
5
+ /**
6
+ *
7
+ */
8
+ const values = [];
9
+ /**
10
+ *
11
+ * @returns
12
+ */
13
+ const getFilesValues = () => values;
14
+ /**
15
+ * 递归获取所有文件名以 res 开头的文件
16
+ * @param dir 目录路径
17
+ * @returns 文件路径数组
18
+ */
19
+ const getFiles = (dir) => {
20
+ let results = [];
21
+ const list = fs.readdirSync(dir, { withFileTypes: true });
22
+ list.forEach(item => {
23
+ const fullPath = join(dir, item.name);
24
+ if (item.isDirectory()) {
25
+ results = results.concat(getFiles(fullPath));
26
+ }
27
+ else if (item.isFile() && item.name.startsWith('res')) {
28
+ if (item.name.endsWith('.ts') ||
29
+ item.name.endsWith('.js') ||
30
+ item.name.endsWith('.jsx') ||
31
+ item.name.endsWith('.tsx')) {
32
+ results.push(fullPath);
33
+ }
34
+ }
35
+ });
36
+ return results;
37
+ };
38
+ /**
39
+ * 加载文件
40
+ */
41
+ const loadFiles = async () => {
42
+ const dir = join(process.cwd(), _dir);
43
+ const files = getFiles(dir);
44
+ // 读取config ,根据config对目录进行分类
45
+ for (const item of files) {
46
+ const dir = dirname(item);
47
+ let v = {};
48
+ try {
49
+ const obj = await import(`file://${dir}/config.js`);
50
+ v = obj?.default;
51
+ }
52
+ catch (e) {
53
+ // console.error(e)
54
+ }
55
+ // 保存目录地址和文件地址
56
+ values.push({
57
+ ...v,
58
+ dir: dirname(item),
59
+ path: item
60
+ });
61
+ }
62
+ };
63
+
64
+ export { getFilesValues, loadFiles };
@@ -0,0 +1,11 @@
1
+ import { AEvents } from '../typing.js';
2
+
3
+ /**
4
+ * 消息处理器
5
+ * @param value
6
+ * @param event
7
+ * @returns
8
+ */
9
+ declare const OnProcessor: <T extends keyof AEvents>(value: AEvents[T], event: T) => void;
10
+
11
+ export { OnProcessor };
@@ -0,0 +1,107 @@
1
+ import { useParse } from '../hook/use-api.js';
2
+ import { getFilesValues } from './event-files.js';
3
+
4
+ const values = {
5
+ 'message.create': [],
6
+ 'message.delete': [],
7
+ 'message.update': []
8
+ };
9
+ /**
10
+ *
11
+ * @param message
12
+ */
13
+ const onMessageCreate = async (e) => {
14
+ // 如何才能能正确消息调用。
15
+ // 获取所有文件
16
+ const files = getFilesValues();
17
+ // 事件处理
18
+ const next = () => {
19
+ // i 结束了
20
+ if (i >= files.length) {
21
+ // j 结束了
22
+ if (j >= filesMessageCreate.length)
23
+ return;
24
+ // 开始调用j
25
+ callj();
26
+ return;
27
+ }
28
+ calli();
29
+ };
30
+ let i = 0;
31
+ let j = 0;
32
+ const calli = async () => {
33
+ // 调用完了
34
+ if (i >= files.length) {
35
+ // 开始调用j
36
+ callj();
37
+ return;
38
+ }
39
+ i++;
40
+ const file = files[i];
41
+ if (!file?.path) {
42
+ // 继续
43
+ calli();
44
+ return;
45
+ }
46
+ const obj = await import(`file://${file.path}`);
47
+ const d = obj?.default;
48
+ console.log(obj);
49
+ if (d?.event !== 'message.create') {
50
+ // 继续
51
+ calli();
52
+ return;
53
+ }
54
+ // 确保数据转移到 message.create存储位置
55
+ // 确保下次直接流向 message.create ,不再从头开始
56
+ const msg = useParse('Text', e.Megs) ?? '';
57
+ if (d?.reg && !d?.reg.test(msg)) {
58
+ // 继续
59
+ calli();
60
+ return;
61
+ }
62
+ // 这里是否继续时 next 说了算
63
+ d?.callback(e, { next, reg: d.reg });
64
+ };
65
+ // 这里必然都是 message.create
66
+ const filesMessageCreate = values['message.create'];
67
+ const callj = async () => {
68
+ // 调用完了
69
+ if (j >= filesMessageCreate.length) {
70
+ // 结束
71
+ return;
72
+ }
73
+ j++;
74
+ const file = filesMessageCreate[j];
75
+ if (!file?.path) {
76
+ callj();
77
+ return;
78
+ }
79
+ const obj = await import(`file://${file.path}`);
80
+ const d = obj?.default;
81
+ console.log(obj);
82
+ const msg = useParse('Text', e.Megs) ?? '';
83
+ if (d?.reg && !d?.reg.test(msg)) {
84
+ callj();
85
+ return;
86
+ }
87
+ // 这里是否继续时 next 说了算
88
+ d?.callback(e, { next, reg: d.reg });
89
+ };
90
+ // 开始调用,调用完了i,再调用j
91
+ calli();
92
+ };
93
+ /**
94
+ * 消息处理器
95
+ * @param value
96
+ * @param event
97
+ * @returns
98
+ */
99
+ const OnProcessor = (value, event) => {
100
+ // 开始调用对应的存储
101
+ if (event === 'message.create') {
102
+ onMessageCreate(value);
103
+ }
104
+ return;
105
+ };
106
+
107
+ export { OnProcessor };
@@ -0,0 +1,49 @@
1
+ import { AEvents } from '../typing.js';
2
+
3
+ type ControllerType = {
4
+ next: Function;
5
+ reg: RegExp;
6
+ };
7
+ declare global {
8
+ /**
9
+ * 处理响应事件
10
+ */
11
+ var OnResponse: <T extends keyof AEvents>(callback: (event: AEvents[T], controller: ControllerType) => any, event: T, reg?: RegExp) => any;
12
+ /**
13
+ * 处理响应事件配置
14
+ */
15
+ var ResponseConfig: (options?: ResponseType) => ResponseType;
16
+ /**
17
+ * 事件观察着
18
+ */
19
+ var OnObserver: <T extends keyof AEvents>(callback: (event: AEvents[T], controller: ControllerType) => any, event: T, reg?: RegExp) => any;
20
+ }
21
+ /**
22
+ * 处理响应事件
23
+ * @param callback 回调函数,处理事件和 API
24
+ * @param event 事件类型
25
+ * @returns 回调函数的执行结果
26
+ */
27
+ declare const OnResponse: <T extends keyof AEvents>(callback: (event: AEvents[T], controller: ControllerType) => any, event: T, reg?: RegExp) => any;
28
+ /**
29
+ *
30
+ * @param callback
31
+ * @param event
32
+ * @param reg
33
+ * @returns
34
+ */
35
+ declare const OnObserver: <T extends keyof AEvents>(callback: (event: AEvents[T], controller: ControllerType) => any, event: T, reg?: RegExp) => any;
36
+ type ResponseType = {
37
+ platform?: string;
38
+ priority?: number;
39
+ enable?: boolean;
40
+ reg?: RegExp;
41
+ };
42
+ /**
43
+ *
44
+ * @param options
45
+ * @returns
46
+ */
47
+ declare const ResponseConfig: (options?: ResponseType) => ResponseType;
48
+
49
+ export { OnObserver, OnResponse, ResponseConfig };
@@ -0,0 +1,30 @@
1
+ /**
2
+ * 处理响应事件
3
+ * @param callback 回调函数,处理事件和 API
4
+ * @param event 事件类型
5
+ * @returns 回调函数的执行结果
6
+ */
7
+ const OnResponse = (callback, event, reg) => {
8
+ return { callback, event, reg: reg ?? /(.*)/ };
9
+ };
10
+ global.OnResponse = OnResponse;
11
+ /**
12
+ *
13
+ * @param callback
14
+ * @param event
15
+ * @param reg
16
+ * @returns
17
+ */
18
+ const OnObserver = (callback, event, reg) => {
19
+ return { callback, event, reg: reg ?? /(.*)/ };
20
+ };
21
+ global.OnObserver = OnObserver;
22
+ /**
23
+ *
24
+ * @param options
25
+ * @returns
26
+ */
27
+ const ResponseConfig = (options) => options;
28
+ global.ResponseConfig = ResponseConfig;
29
+
30
+ export { OnObserver, OnResponse, ResponseConfig };
@@ -0,0 +1,33 @@
1
+ declare const argv: string[];
2
+ /**
3
+ * @param key 参数
4
+ * @returns 参数值
5
+ */
6
+ declare const getArgvValue: (key: string) => string;
7
+ type ConfigType = {
8
+ login: string | undefined;
9
+ app_id: string | undefined;
10
+ token: string | undefined;
11
+ intent: string | undefined;
12
+ secret: string | undefined;
13
+ shard: number[] | undefined;
14
+ intents: string[] | undefined;
15
+ master_id: string[] | undefined;
16
+ };
17
+ /**
18
+ * 配置类
19
+ */
20
+ declare class Config {
21
+ #private;
22
+ /**
23
+ *
24
+ * @param dir
25
+ */
26
+ constructor(dir: string);
27
+ /**
28
+ * 得到置
29
+ */
30
+ get values(): ConfigType;
31
+ }
32
+
33
+ export { Config, type ConfigType, argv, getArgvValue };
package/lib/config.js ADDED
@@ -0,0 +1,187 @@
1
+ import { existsSync, readFileSync, watch } from 'fs';
2
+ import { join } from 'path';
3
+ import { parse } from 'yaml';
4
+
5
+ // 尝试从参数中,得到更高优先级的配置
6
+ const argv = [...process.argv].slice(2);
7
+ /**
8
+ * @param key 参数
9
+ * @returns 参数值
10
+ */
11
+ const getArgvValue = (key) => {
12
+ const v = argv.indexOf(key);
13
+ if (v === -1)
14
+ return null;
15
+ const next = argv[v + 1];
16
+ if (typeof next == 'string') {
17
+ // 如果是参数
18
+ if (next.startsWith('-'))
19
+ return null;
20
+ // 如果是值
21
+ return next;
22
+ }
23
+ return null;
24
+ };
25
+ /**
26
+ * 配置类
27
+ */
28
+ class Config {
29
+ //
30
+ #dir = null;
31
+ //
32
+ #values = null;
33
+ /**
34
+ *
35
+ * @param dir
36
+ */
37
+ constructor(dir) {
38
+ this.#dir = dir;
39
+ }
40
+ /**
41
+ * 初始化参数
42
+ */
43
+ #initArgs() {
44
+ const app_id = getArgvValue('--app_id');
45
+ if (typeof app_id == 'string') {
46
+ this.#values.app_id = app_id;
47
+ }
48
+ const token = getArgvValue('--token');
49
+ if (typeof token == 'string') {
50
+ this.#values.token = token;
51
+ }
52
+ const intent = getArgvValue('--intent');
53
+ if (typeof intent == 'string') {
54
+ this.#values.intent = intent;
55
+ }
56
+ const secret = getArgvValue('--secret');
57
+ if (typeof secret == 'string') {
58
+ this.#values.secret = secret;
59
+ }
60
+ const shard = getArgvValue('--shard');
61
+ if (typeof shard == 'string') {
62
+ this.#values.shard = JSON.parse(shard);
63
+ }
64
+ const intents = getArgvValue('--intents');
65
+ if (typeof intents == 'string') {
66
+ this.#values.intents = JSON.parse(intents);
67
+ }
68
+ const master_id = getArgvValue('--master_id');
69
+ if (typeof master_id == 'string') {
70
+ this.#values.master_id = JSON.parse(master_id);
71
+ }
72
+ }
73
+ /**
74
+ *
75
+ * @param data
76
+ */
77
+ #initData = (data) => {
78
+ // 尝试读取执行参数
79
+ let login = getArgvValue('--login');
80
+ if (!login) {
81
+ if (data.login) {
82
+ login = data.login;
83
+ }
84
+ }
85
+ else {
86
+ this.#values.login = login;
87
+ }
88
+ try {
89
+ const d = data[login];
90
+ if (!d) {
91
+ return this.#values;
92
+ }
93
+ if (d?.app_id) {
94
+ this.#values.app_id = d.app_id;
95
+ }
96
+ if (d?.token) {
97
+ this.#values.token = d.token;
98
+ }
99
+ if (d?.intent) {
100
+ this.#values.intent = d.intent;
101
+ }
102
+ if (d?.secret) {
103
+ this.#values.secret = d.secret;
104
+ }
105
+ if (d?.shard) {
106
+ this.#values.shard = d.shard;
107
+ }
108
+ if (d?.intents) {
109
+ this.#values.intents = d.intents;
110
+ }
111
+ if (d?.master_id) {
112
+ this.#values.master_id = d.master_id;
113
+ }
114
+ }
115
+ catch {
116
+ //
117
+ }
118
+ return this.#values;
119
+ };
120
+ /**
121
+ *
122
+ * @returns
123
+ */
124
+ #update() {
125
+ // 读取配置文件
126
+ const dir = join(process.cwd(), this.#dir);
127
+ console.log(dir);
128
+ // 如果文件不存在
129
+ if (!existsSync(dir)) {
130
+ console.warn('alemon.config.yaml not found');
131
+ // 尝试读取执行参数
132
+ const login = getArgvValue('--login');
133
+ if (login) {
134
+ this.#values.login = login;
135
+ }
136
+ // 根据参数设置成配置
137
+ this.#initArgs();
138
+ return this.#values;
139
+ }
140
+ const data = readFileSync(dir, 'utf-8');
141
+ try {
142
+ const d = parse(data);
143
+ this.#initData(d);
144
+ // 确保参数优先级最高
145
+ this.#initArgs();
146
+ }
147
+ catch (err) {
148
+ console.log(err);
149
+ process.cwd();
150
+ }
151
+ // 存在配置文件 , 开始监听文件
152
+ watch(dir, () => {
153
+ const data = readFileSync(dir, 'utf-8');
154
+ try {
155
+ const d = parse(data);
156
+ this.#initData(d);
157
+ // 确保参数优先级最高
158
+ this.#initArgs();
159
+ }
160
+ catch (err) {
161
+ console.log(err);
162
+ }
163
+ });
164
+ return this.#values;
165
+ }
166
+ /**
167
+ * 得到置
168
+ */
169
+ get values() {
170
+ if (!this.#values) {
171
+ this.#values = {
172
+ login: undefined,
173
+ app_id: undefined,
174
+ token: undefined,
175
+ intent: undefined,
176
+ secret: undefined,
177
+ shard: undefined,
178
+ intents: undefined,
179
+ master_id: undefined
180
+ };
181
+ return this.#update();
182
+ }
183
+ return this.#values;
184
+ }
185
+ }
186
+
187
+ export { Config, argv, getArgvValue };
@@ -0,0 +1,110 @@
1
+ /**
2
+ * 发送文本
3
+ */
4
+ declare const Text: (val: any, typing?: "none" | "bold" | "block" | "strikethrough" | "boldItalic" | "italic") => {
5
+ type: string;
6
+ value: any;
7
+ typing: "bold" | "none" | "block" | "strikethrough" | "boldItalic" | "italic";
8
+ };
9
+ /**
10
+ *
11
+ * @param val
12
+ */
13
+ declare const At: (user_id?: string, typing?: "user" | "guild" | "channel") => {
14
+ type: string;
15
+ value: string;
16
+ typing: "user" | "guild" | "channel";
17
+ };
18
+ /**
19
+ *
20
+ * @param title
21
+ * @param url
22
+ */
23
+ declare const Button: (title: string, options: {
24
+ send?: string;
25
+ enter?: boolean;
26
+ reply?: boolean;
27
+ tip?: string;
28
+ color?: "blue" | "slate";
29
+ permission?: "user" | "admin";
30
+ }) => {
31
+ type: string;
32
+ value: string;
33
+ options: {
34
+ send?: string;
35
+ enter?: boolean;
36
+ reply?: boolean;
37
+ tip?: string;
38
+ color?: "blue" | "slate";
39
+ permission?: "user" | "admin";
40
+ };
41
+ };
42
+ declare const BtBox: (flex: "Col" | "Row", ...arg: any) => {
43
+ type: string;
44
+ value: any;
45
+ flex: "Col" | "Row";
46
+ };
47
+ /**
48
+ * 发送文件
49
+ */
50
+ declare const Files: (val: string) => {
51
+ type: string;
52
+ value: string;
53
+ };
54
+ /**
55
+ *
56
+ * @param val
57
+ * @returns
58
+ */
59
+ declare const Video: (val: string) => {
60
+ type: string;
61
+ value: string;
62
+ };
63
+ /**
64
+ *
65
+ * @param val
66
+ */
67
+ declare const Voice: (val: any) => {
68
+ type: string;
69
+ value: any;
70
+ };
71
+ /**
72
+ *
73
+ * @param val
74
+ */
75
+ declare const Img: (val: Buffer | string, typing?: "buffer" | "file" | "network") => {
76
+ type: string;
77
+ value: string | Buffer;
78
+ typing: "buffer" | "file" | "network";
79
+ };
80
+ declare const Link: (title: string, val: string) => {
81
+ type: string;
82
+ value: string;
83
+ title: string;
84
+ };
85
+ /**
86
+ *
87
+ * @param val
88
+ */
89
+ declare const Ark: (val: any) => {
90
+ type: string;
91
+ value: any;
92
+ };
93
+ /**
94
+ *
95
+ * @param val
96
+ */
97
+ declare const Embed: (val: any) => {
98
+ type: string;
99
+ value: any;
100
+ };
101
+ /**
102
+ * 发送表态
103
+ * @param val
104
+ */
105
+ declare const Emoji: (val: any) => {
106
+ type: string;
107
+ value: any;
108
+ };
109
+
110
+ export { Ark, At, BtBox, Button, Embed, Emoji, Files, Img, Link, Text, Video, Voice };
@@ -0,0 +1,120 @@
1
+ /**
2
+ * 发送文本
3
+ */
4
+ const Text = (val, typing) => {
5
+ return {
6
+ type: 'Text',
7
+ value: val,
8
+ typing: typing ?? 'none'
9
+ };
10
+ };
11
+ /**
12
+ *
13
+ * @param val
14
+ */
15
+ const At = (user_id, typing) => {
16
+ return {
17
+ type: 'At',
18
+ value: user_id,
19
+ typing
20
+ };
21
+ };
22
+ /**
23
+ *
24
+ * @param title
25
+ * @param url
26
+ */
27
+ const Button = (title, options) => {
28
+ return {
29
+ type: 'Button',
30
+ value: title,
31
+ options
32
+ };
33
+ };
34
+ const BtBox = (flex, ...arg) => {
35
+ return {
36
+ type: 'BtBox',
37
+ value: arg,
38
+ flex
39
+ };
40
+ };
41
+ /**
42
+ * 发送文件
43
+ */
44
+ const Files = (val) => {
45
+ return {
46
+ type: 'Files',
47
+ value: val
48
+ };
49
+ };
50
+ /**
51
+ *
52
+ * @param val
53
+ * @returns
54
+ */
55
+ const Video = (val) => {
56
+ return {
57
+ type: 'Video',
58
+ value: val
59
+ };
60
+ };
61
+ /**
62
+ *
63
+ * @param val
64
+ */
65
+ const Voice = (val) => {
66
+ return {
67
+ type: 'Voice',
68
+ value: val
69
+ };
70
+ };
71
+ /**
72
+ *
73
+ * @param val
74
+ */
75
+ const Img = (val, typing) => {
76
+ return {
77
+ type: 'img',
78
+ value: val,
79
+ typing
80
+ };
81
+ };
82
+ const Link = (title, val) => {
83
+ return {
84
+ type: 'Link',
85
+ value: val,
86
+ title
87
+ };
88
+ };
89
+ /**
90
+ *
91
+ * @param val
92
+ */
93
+ const Ark = (val) => {
94
+ return {
95
+ type: 'ark',
96
+ value: val
97
+ };
98
+ };
99
+ /**
100
+ *
101
+ * @param val
102
+ */
103
+ const Embed = (val) => {
104
+ return {
105
+ type: 'Embed',
106
+ value: val
107
+ };
108
+ };
109
+ /**
110
+ * 发送表态
111
+ * @param val
112
+ */
113
+ const Emoji = (val) => {
114
+ return {
115
+ type: 'Emoji',
116
+ value: val
117
+ };
118
+ };
119
+
120
+ export { Ark, At, BtBox, Button, Embed, Emoji, Files, Img, Link, Text, Video, Voice };