alemonjs 1.0.57 → 1.1.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 (128) hide show
  1. package/lib/api.js +48 -0
  2. package/lib/core/dealmsg.js +5 -5
  3. package/lib/core/ip.js +1 -1
  4. package/lib/core/typings.js +40 -17
  5. package/lib/define/main.js +4 -4
  6. package/lib/koa/back.js +66 -0
  7. package/lib/koa/client.js +11 -7
  8. package/lib/koa/config.js +7 -3
  9. package/lib/koa/file.js +80 -0
  10. package/lib/koa/index.js +1 -1
  11. package/lib/kook/alemon/controller.js +156 -0
  12. package/lib/kook/alemon/conversation.js +82 -10
  13. package/lib/kook/alemon/direct.js +224 -0
  14. package/lib/kook/alemon/message/DIRECT_MESSAGE.js +73 -0
  15. package/lib/kook/alemon/message/GUILD_MESSAGE_REACTIONS.js +82 -0
  16. package/lib/kook/alemon/message/PUBLIC_GUILD_MESSAGES.js +37 -149
  17. package/lib/kook/alemon/reply.js +95 -0
  18. package/lib/kook/alemon/segment.js +3 -30
  19. package/lib/kook/index.js +6 -6
  20. package/lib/kook/sdk/api.js +157 -11
  21. package/lib/ntqq/alemon/controller.js +98 -0
  22. package/lib/ntqq/alemon/direct.js +195 -0
  23. package/lib/ntqq/alemon/message/C2C_MESSAGE_CREATE.js +27 -77
  24. package/lib/ntqq/alemon/message/GROUP_AT_MESSAGE_CREATE.js +33 -78
  25. package/lib/ntqq/alemon/reply.js +73 -0
  26. package/lib/ntqq/alemon/segment.js +0 -17
  27. package/lib/ntqq/sdk/api.js +25 -2
  28. package/lib/one/alemon/controller.js +111 -0
  29. package/lib/one/alemon/direct.js +150 -0
  30. package/lib/one/alemon/message/DIRECT_MESSAGE.js +32 -183
  31. package/lib/one/alemon/message/MESSAGES.js +34 -178
  32. package/lib/one/alemon/reply.js +166 -0
  33. package/lib/one/alemon/segment.js +0 -22
  34. package/lib/qq/alemon/controller.js +203 -0
  35. package/lib/qq/alemon/conversation.js +10 -2
  36. package/lib/qq/alemon/direct.js +209 -0
  37. package/lib/qq/alemon/message/AUDIO_ACTION.js +51 -22
  38. package/lib/qq/alemon/message/CHANNEL.js +99 -0
  39. package/lib/qq/alemon/message/DIRECT_MESSAGE.js +35 -134
  40. package/lib/qq/alemon/message/FORUMS_EVENT.js +62 -35
  41. package/lib/qq/alemon/message/GUILDS.js +61 -98
  42. package/lib/qq/alemon/message/GUILD_MEMBERS.js +61 -25
  43. package/lib/qq/alemon/message/GUILD_MESSAGES.js +104 -25
  44. package/lib/qq/alemon/message/GUILD_MESSAGE_REACTIONS.js +51 -13
  45. package/lib/qq/alemon/message/INTERACTION.js +48 -13
  46. package/lib/qq/alemon/message/MESSAGE_AUDIT.js +46 -13
  47. package/lib/qq/alemon/message/OPEN_FORUMS_EVENT.js +50 -13
  48. package/lib/qq/alemon/message/PUBLIC_GUILD_MESSAGES.js +105 -22
  49. package/lib/qq/alemon/reply.js +87 -0
  50. package/lib/qq/alemon/segment.js +0 -21
  51. package/lib/villa/alemon/controller.js +231 -0
  52. package/lib/villa/alemon/conversation.js +16 -11
  53. package/lib/villa/alemon/message/GUILD_BOT.js +89 -0
  54. package/lib/villa/alemon/message/GUILD_MEMBERS.js +50 -18
  55. package/lib/villa/alemon/message/GUILD_MESSAGE_REACTIONS.js +42 -18
  56. package/lib/villa/alemon/message/MESSAGES.js +42 -117
  57. package/lib/villa/alemon/message/MESSAGE_AUDIT.js +43 -18
  58. package/lib/villa/alemon/message/MESSAGE_BUTTON.js +90 -0
  59. package/lib/villa/alemon/reply.js +108 -0
  60. package/lib/villa/alemon/segment.js +0 -27
  61. package/lib/villa/sdk/api.js +77 -27
  62. package/lib/villa/sdk/client.js +3 -3
  63. package/lib/villa/sdk/reply.js +145 -57
  64. package/lib/villa/sdk/types.js +4 -0
  65. package/lib/villa/sdk/wss.js +44 -0
  66. package/logs.d.ts +1 -1
  67. package/logs.js +16 -16
  68. package/package.json +13 -2
  69. package/run.d.ts +5 -1
  70. package/run.js +22 -22
  71. package/types/api.d.ts +11 -0
  72. package/types/core/ip.d.ts +1 -1
  73. package/types/core/typings.d.ts +184 -63
  74. package/types/koa/back.d.ts +12 -0
  75. package/types/koa/file.d.ts +24 -0
  76. package/types/koa/index.d.ts +1 -1
  77. package/types/koa/types.d.ts +7 -3
  78. package/types/kook/alemon/controller.d.ts +186 -0
  79. package/types/kook/alemon/direct.d.ts +81 -0
  80. package/types/kook/alemon/message/DIRECT_MESSAGE.d.ts +6 -0
  81. package/types/kook/alemon/message/GUILD_MESSAGE_REACTIONS.d.ts +7 -0
  82. package/types/kook/alemon/reply.d.ts +9 -0
  83. package/types/kook/alemon/segment.d.ts +1 -28
  84. package/types/kook/sdk/api.d.ts +197 -10
  85. package/types/kook/sdk/typings.d.ts +19 -17
  86. package/types/ntqq/alemon/controller.d.ts +86 -0
  87. package/types/ntqq/alemon/direct.d.ts +81 -0
  88. package/types/ntqq/alemon/reply.d.ts +9 -0
  89. package/types/ntqq/alemon/segment.d.ts +0 -16
  90. package/types/ntqq/sdk/api.d.ts +13 -2
  91. package/types/one/alemon/controller.d.ts +130 -0
  92. package/types/one/alemon/direct.d.ts +9 -0
  93. package/types/one/alemon/message/DIRECT_MESSAGE.d.ts +1 -1
  94. package/types/one/alemon/reply.d.ts +9 -0
  95. package/types/one/alemon/segment.d.ts +0 -22
  96. package/types/qq/alemon/controller.d.ts +153 -0
  97. package/types/qq/alemon/direct.d.ts +85 -0
  98. package/types/qq/alemon/message/CHANNEL.d.ts +36 -0
  99. package/types/qq/alemon/message/GUILDS.d.ts +28 -1
  100. package/types/qq/alemon/message/PUBLIC_GUILD_MESSAGES.d.ts +2 -2
  101. package/types/qq/alemon/reply.d.ts +12 -0
  102. package/types/qq/alemon/segment.d.ts +0 -21
  103. package/types/villa/alemon/controller.d.ts +247 -0
  104. package/types/villa/alemon/message/{GUILDS.d.ts → GUILD_BOT.d.ts} +4 -2
  105. package/types/villa/alemon/message/GUILD_MEMBERS.d.ts +1 -2
  106. package/types/villa/alemon/message/GUILD_MESSAGE_REACTIONS.d.ts +1 -2
  107. package/types/villa/alemon/message/MESSAGES.d.ts +1 -2
  108. package/types/villa/alemon/message/MESSAGE_AUDIT.d.ts +1 -2
  109. package/types/villa/alemon/message/MESSAGE_BUTTON.d.ts +34 -0
  110. package/types/villa/alemon/reply.d.ts +12 -0
  111. package/types/villa/alemon/segment.d.ts +0 -27
  112. package/types/villa/sdk/api.d.ts +50 -20
  113. package/types/villa/sdk/reply.d.ts +6 -6
  114. package/types/villa/sdk/types.d.ts +3 -1
  115. package/types/villa/sdk/wss.d.ts +1 -0
  116. package/lib/client/types.js +0 -1
  117. package/lib/client/typing.js +0 -1
  118. package/lib/koa/img.js +0 -79
  119. package/lib/logs.js +0 -23
  120. package/lib/qq/alemon/message/MESSAGE.js +0 -262
  121. package/lib/run.js +0 -29
  122. package/lib/villa/alemon/message/GUILDS.js +0 -63
  123. package/types/client/types.d.ts +0 -154
  124. package/types/client/typing.d.ts +0 -72
  125. package/types/koa/img.d.ts +0 -20
  126. package/types/logs.d.ts +0 -6
  127. package/types/qq/alemon/message/MESSAGE.d.ts +0 -55
  128. package/types/run.d.ts +0 -5
package/lib/api.js CHANGED
@@ -24,3 +24,51 @@ export { ClientKOOK } from './kook/index.js';
24
24
  * one客户端
25
25
  */
26
26
  export { ClientONE } from './one/index.js';
27
+ /**
28
+ * 控制器
29
+ */
30
+ import { Controller as villaController } from './villa/alemon/controller.js';
31
+ import { Controller as qqController } from './qq/alemon/controller.js';
32
+ import { Controller as ntqqController } from './ntqq/alemon/controller.js';
33
+ import { Controller as kookController } from './kook/alemon/controller.js';
34
+ import { Controller as oneController } from './one/alemon/controller.js';
35
+ // 当前可用平台
36
+ const PlatformEnum = ['villa', 'qq', 'kook', 'ntqq', 'one'];
37
+ /**
38
+ * 控制器
39
+ * @param platform
40
+ * @returns
41
+ */
42
+ export const Controller = (platform) => {
43
+ /**
44
+ * 选择器
45
+ * @param options
46
+ * @returns
47
+ */
48
+ const fnc = (options) => {
49
+ const map = {
50
+ villa: {
51
+ Message: villaController.Message(options),
52
+ Member: villaController.Member(options)
53
+ },
54
+ qq: {
55
+ Message: qqController.Message(options),
56
+ Member: qqController.Member(options)
57
+ },
58
+ ntqq: {
59
+ Message: ntqqController.Message(options),
60
+ Member: ntqqController.Member()
61
+ },
62
+ kook: {
63
+ Message: kookController.Message(options),
64
+ Member: kookController.Member(options)
65
+ },
66
+ one: {
67
+ Message: oneController.Message(),
68
+ Member: oneController.Member()
69
+ }
70
+ };
71
+ return map[platform];
72
+ };
73
+ return fnc;
74
+ };
@@ -105,10 +105,8 @@ async function synthesis(AppName, AppsObj) {
105
105
  APP: AppsObj[item]
106
106
  };
107
107
  for await (const key of keys['rule']) {
108
- if (!key['fnc'] ||
109
- !key['reg'] ||
110
- typeof keys[key['fnc']] !== 'function') {
111
- /// 函数指定不存在,正则不存在 得到的不是函数
108
+ if (!key['fnc'] || typeof keys[key['fnc']] !== 'function') {
109
+ /// 函数指定不存在 得到的不是函数
112
110
  continue;
113
111
  }
114
112
  // 先看指令优先级,没有就看类优先级,再没有则默认优先级
@@ -313,6 +311,8 @@ export async function loadInit() {
313
311
  * @returns 是否处理完成
314
312
  */
315
313
  export async function InstructionMatching(e) {
314
+ // 标记当前函数平台
315
+ global.APlatform = e.platform;
316
316
  /**
317
317
  * 对话机
318
318
  */
@@ -385,7 +385,7 @@ export async function InstructionMatching(e) {
385
385
  /**
386
386
  * 撤回事件 || 匹配不到事件 || 大正则不匹配
387
387
  */
388
- if (e.isRecall || !Command[e.event] || !mergedRegex.test(e.msg))
388
+ if (!Command[e.event] || !mergedRegex.test(e.msg))
389
389
  return true;
390
390
  /**
391
391
  * 循环所有指令
package/lib/core/ip.js CHANGED
@@ -4,7 +4,7 @@ let myIp;
4
4
  * 得到本机IP地址
5
5
  * @returns
6
6
  */
7
- export async function getIP(options = {}) {
7
+ export async function getPublicIP(options = {}) {
8
8
  if (myIp)
9
9
  return myIp;
10
10
  return await publicIp({
@@ -21,17 +21,38 @@ export const EventEnum = [
21
21
  * 频道
22
22
  * **********
23
23
  */
24
+ /**
25
+ * 频道事件
26
+ */
24
27
  'GUILD',
28
+ /**
29
+ * 机器人进出事件
30
+ */
25
31
  'GUILD_BOT',
32
+ /**
33
+ * 子频道事件
34
+ */
26
35
  'CHANNEL',
36
+ /**
37
+ * 成员进出
38
+ */
27
39
  'GUILD_MEMBERS',
28
40
  /**
29
41
  * ***********
30
42
  * 论坛
31
43
  * *********
32
44
  */
45
+ /**
46
+ * 论坛主题
47
+ */
33
48
  'FORUMS_THREAD',
49
+ /**
50
+ * 论坛POST
51
+ */
34
52
  'FORUMS_POST',
53
+ /**
54
+ * 论坛评论
55
+ */
35
56
  'FORUMS_REPLY',
36
57
  /**
37
58
  * *********
@@ -40,9 +61,22 @@ export const EventEnum = [
40
61
  * MESSAGES=message
41
62
  * =MESSAGE+DIRECT+PUBLIC
42
63
  */
64
+ /**
65
+ * 消息
66
+ */
43
67
  'MESSAGES',
68
+ /**
69
+ * 消息
70
+ */
44
71
  'message',
72
+ /**
73
+ * 表态
74
+ */
45
75
  'GUILD_MESSAGE_REACTIONS',
76
+ /**
77
+ * 按钮回调
78
+ */
79
+ 'MESSAGE_BUTTON',
46
80
  /**
47
81
  * 互动事件监听
48
82
  */
@@ -52,7 +86,13 @@ export const EventEnum = [
52
86
  * 音频事件
53
87
  * ***********
54
88
  */
89
+ /**
90
+ * 视频
91
+ */
55
92
  'AUDIO_FREQUENCY',
93
+ /**
94
+ * 麦克风
95
+ */
56
96
  'AUDIO_MICROPHONE',
57
97
  /**
58
98
  * 审核消息
@@ -63,20 +103,3 @@ export const EventEnum = [
63
103
  * 消息判断
64
104
  */
65
105
  export const EventType = ['CREATE', 'UPDATE', 'DELETE'];
66
- /**
67
- * 卡片枚举
68
- */
69
- export const CacrdEnum = [
70
- /**
71
- * qq频道
72
- */
73
- 'qq_embed',
74
- /**
75
- * QQ频道
76
- */
77
- 'qq_ark',
78
- /**
79
- * kook
80
- */
81
- 'kook_card'
82
- ];
@@ -4,10 +4,10 @@ import { nodeScripts } from './child_process.js';
4
4
  import { AvailableIntentsEventsEnum } from 'qq-guild-bot';
5
5
  import { ClientNTQQ } from '../ntqq/sdk/index.js';
6
6
  import { command } from './command.js';
7
- import { createApp, setLanchConfig, loadInit, appsInit, setAppProCoinfg, startChrom, getIP } from '../core/index.js';
7
+ import { createApp, setLanchConfig, loadInit, appsInit, setAppProCoinfg, startChrom, getPublicIP } from '../core/index.js';
8
8
  import { getPupPath, setBotConfigByKey, getBotConfigByKey } from '../config/index.js';
9
9
  import { createWeb } from '../koa/index.js';
10
- import { autoClearImages } from '../koa/img.js';
10
+ import { autoClearFiles } from '../koa/file.js';
11
11
  // 设置ntqq独立鉴权路径
12
12
  export const setAuthenticationByNtqq = ClientNTQQ.setAuthentication;
13
13
  let OptionsCache;
@@ -164,10 +164,10 @@ export async function defineAlemonConfig(Options) {
164
164
  createWeb(Options?.server);
165
165
  if (Options?.server?.clear != false) {
166
166
  // 定时清除
167
- autoClearImages();
167
+ autoClearFiles();
168
168
  }
169
169
  // 缓存ip
170
- getIP();
170
+ getPublicIP();
171
171
  }
172
172
  /**
173
173
  * ***********
@@ -0,0 +1,66 @@
1
+ import { createReadStream, existsSync } from 'fs';
2
+ import { join } from 'path';
3
+ import mime from 'mime-types';
4
+ import { getServerConfig } from './config.js';
5
+ /**
6
+ * 响应指定本地文件
7
+ * @param ctx
8
+ * @returns
9
+ */
10
+ export async function getFileByAddress(ctx) {
11
+ const address = ctx.query.address; // 从请求中获取 address 参数
12
+ if (!address) {
13
+ ctx.status = 400;
14
+ ctx.body = 'No address parameter provided';
15
+ return;
16
+ }
17
+ if (typeof address != 'string') {
18
+ ctx.status = 400;
19
+ ctx.body = 'No address parameter provided';
20
+ return;
21
+ }
22
+ let filePath;
23
+ if (existsSync(address)) {
24
+ filePath = address;
25
+ }
26
+ else {
27
+ filePath = join(process.cwd(), address);
28
+ }
29
+ if (!existsSync(filePath)) {
30
+ ctx.status = 404;
31
+ ctx.body = 'File not found';
32
+ return;
33
+ }
34
+ try {
35
+ const stream = createReadStream(filePath);
36
+ const mimeType = mime.lookup(filePath) || 'application/octet-stream';
37
+ ctx.set('Content-Type', mimeType);
38
+ ctx.body = stream;
39
+ }
40
+ catch (error) {
41
+ ctx.status = 500;
42
+ ctx.body = 'Internal Server Error';
43
+ }
44
+ }
45
+ /**
46
+ * 响应静态文件
47
+ * @param ctx
48
+ */
49
+ export function getLocalFile(ctx) {
50
+ const fileDir = getServerConfig('fileDir');
51
+ const filename = ctx.params.filename;
52
+ const filePath = join(process.cwd(), fileDir, filename);
53
+ try {
54
+ // 读取文件
55
+ const stream = createReadStream(filePath);
56
+ // 根据文件扩展名确定 MIME 类型
57
+ const mimeType = mime.lookup(filename) || 'application/octet-stream';
58
+ // 设置正确的 Content-Type
59
+ ctx.set('Content-Type', mimeType);
60
+ ctx.body = stream;
61
+ }
62
+ catch (error) {
63
+ ctx.status = 404;
64
+ ctx.body = 'Not Found';
65
+ }
66
+ }
package/lib/koa/client.js CHANGED
@@ -1,8 +1,9 @@
1
1
  import Koa from 'koa';
2
2
  import Router from 'koa-router';
3
3
  import bodyParser from 'koa-bodyparser';
4
+ import cors from 'koa2-cors';
4
5
  import { mkdirSync } from 'fs';
5
- import { getLocalImg } from './img.js';
6
+ import { getFileByAddress, getLocalFile } from './back.js';
6
7
  import { getServerConfig, setServerCoinfg } from './config.js';
7
8
  import { join } from 'path';
8
9
  /**
@@ -20,14 +21,18 @@ export function createWeb(val, logFnc) {
20
21
  // 创建 Koa 应用
21
22
  const app = new Koa();
22
23
  const router = new Router();
24
+ // 允许跨域请求
25
+ app.use(cors());
23
26
  // 处理 POST 请求体中的 JSON 数据
24
27
  app.use(bodyParser());
25
28
  // 确保目录存在
26
- const imgDir = getServerConfig('imgDir');
27
- mkdirSync(join(process.cwd(), imgDir), { recursive: true });
29
+ const fileDir = getServerConfig('fileDir');
30
+ mkdirSync(join(process.cwd(), fileDir), { recursive: true });
28
31
  // 处理图片请求
29
- const imgRouter = getServerConfig('imgRouter');
30
- router.get(`${imgRouter}/:filename`, getLocalImg);
32
+ const imgRouter = getServerConfig('fileRouter');
33
+ router.get(`${imgRouter}/:filename`, getLocalFile);
34
+ const addressRouter = getServerConfig('addressRouter');
35
+ router.get(`${addressRouter}`, getFileByAddress);
31
36
  const port = getServerConfig('port');
32
37
  // 将路由注册到应用
33
38
  app.use(router.routes());
@@ -60,13 +65,12 @@ export function createWeb(val, logFnc) {
60
65
  * @param port
61
66
  */
62
67
  function createApp(port) {
63
- // 设置配置
64
- setServerCoinfg('port', port);
65
68
  // 启动应用
66
69
  app
67
70
  .listen(port, async () => {
68
71
  if (logFnc)
69
72
  await logFnc(port);
73
+ setServerCoinfg('port', port);
70
74
  console.info('server', `http://[::]:${port}`);
71
75
  })
72
76
  .on('error', handlePortConflict);
package/lib/koa/config.js CHANGED
@@ -17,15 +17,19 @@ const ServerCfg = {
17
17
  /**
18
18
  * 图片随机度
19
19
  */
20
- imgSize: 9999999,
20
+ fileSize: 9999999,
21
21
  /**
22
22
  * 挂载路由
23
23
  */
24
- imgRouter: '/api/alemonjs/img',
24
+ fileRouter: '/api/alemonjs/file',
25
+ /**
26
+ *
27
+ */
28
+ addressRouter: '/api/alemonjs/local',
25
29
  /**
26
30
  * 本地缓存地址
27
31
  */
28
- imgDir: '/data/alemonjs/img'
32
+ fileDir: '/data/alemonjs/img'
29
33
  };
30
34
  /**
31
35
  * @param key 配置名
@@ -0,0 +1,80 @@
1
+ import { join } from 'path';
2
+ import { writeFileSync, readdirSync, unlinkSync, existsSync } from 'fs';
3
+ import { fileTypeFromBuffer } from 'file-type';
4
+ import { getServerConfig } from './config.js';
5
+ import { getPublicIP } from '../core/index.js';
6
+ /**
7
+ * 得到本地文件请求地址
8
+ * @param address
9
+ * @returns
10
+ */
11
+ export async function getLocalFileUrl(address) {
12
+ // 检查文件是否存在
13
+ let filePath;
14
+ if (existsSync(address)) {
15
+ filePath = address;
16
+ }
17
+ else {
18
+ filePath = join(process.cwd(), address);
19
+ }
20
+ if (!existsSync(filePath))
21
+ return false;
22
+ const addressRouter = getServerConfig('addressRouter');
23
+ const port = getServerConfig('port');
24
+ const http = getServerConfig('http');
25
+ let ip = getServerConfig('ip');
26
+ if (ip == 'localhost') {
27
+ const ipp = await getPublicIP();
28
+ if (ipp)
29
+ ip = ipp;
30
+ }
31
+ const url = `${http}://${ip}:${port}${addressRouter}?address=${address}`;
32
+ console.info('server url', url);
33
+ return url;
34
+ }
35
+ /**
36
+ * 存储文件并得到请求地址
37
+ * @param file
38
+ * @param name
39
+ * @returns
40
+ */
41
+ export async function getFileUrl(file, name) {
42
+ if (!Buffer.isBuffer(file))
43
+ return false;
44
+ const fileDir = getServerConfig('fileDir');
45
+ const fileRouter = getServerConfig('fileRouter');
46
+ const fileSize = getServerConfig('fileSize');
47
+ const port = getServerConfig('port');
48
+ const http = getServerConfig('http');
49
+ let ip = getServerConfig('ip');
50
+ if (ip == 'localhost') {
51
+ const ipp = await getPublicIP();
52
+ if (ipp)
53
+ ip = ipp;
54
+ }
55
+ // 使用 'bin' 作为默认扩展名
56
+ const extension = (await fileTypeFromBuffer(file))?.ext ?? name ?? 'bin';
57
+ const filename = `${Math.floor(Math.random() * fileSize)}.${extension}`;
58
+ const filePath = join(process.cwd(), fileDir, filename);
59
+ console.info('server create', filePath);
60
+ // 保存文件到文件系统
61
+ writeFileSync(filePath, file);
62
+ const url = `${http}://${ip}:${port}${fileRouter}/${filename}`;
63
+ console.info('setLocalFile url', url);
64
+ return url;
65
+ }
66
+ /**
67
+ *
68
+ * 自动清除机制
69
+ * 清除挂载下的所有文件
70
+ * @param options
71
+ */
72
+ export function autoClearFiles(options) {
73
+ const fileDir = options?.dir ?? getServerConfig('fileDir');
74
+ setInterval(() => {
75
+ const files = readdirSync(join(process.cwd(), fileDir));
76
+ for (const file of files) {
77
+ unlinkSync(join(process.cwd(), fileDir, file));
78
+ }
79
+ }, options?.time ?? 300000);
80
+ }
package/lib/koa/index.js CHANGED
@@ -5,5 +5,5 @@
5
5
  */
6
6
  export * from './client.js';
7
7
  export * from './config.js';
8
- export * as ClientKOA from './img.js';
8
+ export * as ClientKOA from './file.js';
9
9
  export * from './types.js';
@@ -0,0 +1,156 @@
1
+ import { ClientKOOK } from '../sdk/index.js';
2
+ import { replyController } from './reply.js';
3
+ import { getBotConfigByKey } from '../../config/index.js';
4
+ export const Controller = {
5
+ Member: ({ guild_id, user_id }) => {
6
+ return {
7
+ information: async () => {
8
+ const data = await ClientKOOK.userView(guild_id, user_id).then(res => res.data);
9
+ if (data) {
10
+ const cfg = getBotConfigByKey('qq');
11
+ const masterID = cfg.masterID;
12
+ return {
13
+ id: data.id,
14
+ name: data.username,
15
+ introduce: '',
16
+ bot: data.bot,
17
+ avatar: data.avatar,
18
+ isMaster: masterID == data.id,
19
+ joined_at: data.joined_at,
20
+ role: data.roles
21
+ };
22
+ }
23
+ return false;
24
+ },
25
+ mute: async (option) => {
26
+ return false;
27
+ },
28
+ remove: async () => {
29
+ return await ClientKOOK.guildKickout(guild_id, user_id);
30
+ },
31
+ operate: async (role_id, add = true) => {
32
+ return false;
33
+ }
34
+ };
35
+ },
36
+ Message: ({ channel_id, user_id, msg_id }) => {
37
+ return {
38
+ reply: async (content) => {
39
+ return await replyController(content, channel_id);
40
+ },
41
+ quote: async (content) => {
42
+ return await replyController(content, channel_id);
43
+ },
44
+ update: async (content) => {
45
+ return await ClientKOOK.messageUpdate({ msg_id, content });
46
+ },
47
+ withdraw: async (hideTip) => {
48
+ return await ClientKOOK.messageDelete(msg_id);
49
+ },
50
+ pinning: async (cancel) => {
51
+ return false;
52
+ },
53
+ forward: async () => {
54
+ return false;
55
+ },
56
+ horn: async (cancel) => {
57
+ return false;
58
+ },
59
+ emoji: async (msg, cancel) => {
60
+ const arr = [];
61
+ if (cancel) {
62
+ for (const item of msg) {
63
+ arr.push(await ClientKOOK.messageDeleteReaction({
64
+ msg_id,
65
+ emoji: item,
66
+ user_id
67
+ }));
68
+ }
69
+ return arr;
70
+ }
71
+ for (const item of msg) {
72
+ arr.push(await ClientKOOK.messageAddReaction({ msg_id, emoji: item }));
73
+ }
74
+ return arr;
75
+ },
76
+ audio: async (file, name) => {
77
+ if (typeof file == 'string') {
78
+ return await ClientKOOK.createMessage({
79
+ type: 3,
80
+ target_id: channel_id,
81
+ content: file
82
+ });
83
+ }
84
+ const ret = await ClientKOOK.postFile(file, name);
85
+ if (!ret)
86
+ return false;
87
+ return await ClientKOOK.createMessage({
88
+ type: 3,
89
+ target_id: channel_id,
90
+ content: ret.data.url
91
+ });
92
+ },
93
+ video: async (file, name) => {
94
+ if (typeof file == 'string') {
95
+ return await ClientKOOK.createMessage({
96
+ type: 3,
97
+ target_id: channel_id,
98
+ content: file
99
+ });
100
+ }
101
+ const ret = await ClientKOOK.postFile(file, name);
102
+ if (!ret)
103
+ return false;
104
+ return await ClientKOOK.createMessage({
105
+ type: 3,
106
+ target_id: channel_id,
107
+ content: ret.data.url
108
+ });
109
+ },
110
+ card: async (msg) => {
111
+ return [
112
+ await ClientKOOK.createMessage({
113
+ type: 10,
114
+ target_id: channel_id,
115
+ content: JSON.stringify(msg)
116
+ })
117
+ ];
118
+ },
119
+ allUsers: async (emoji, options = {
120
+ cookie: '',
121
+ limit: 20
122
+ }) => {
123
+ // 该消息下 指定emoji的所有用户
124
+ return await ClientKOOK.messageReactionList({ msg_id, emoji });
125
+ },
126
+ article: async (msg) => {
127
+ return false;
128
+ }
129
+ };
130
+ }
131
+ };
132
+ /**
133
+ * 客户端控制器
134
+ * @param select
135
+ * @returns
136
+ */
137
+ export const ClientController = (data) => {
138
+ return (select) => {
139
+ const msg_id = select?.msg_id ?? data.msg_id;
140
+ const user_id = select?.user_id ?? data.user_id;
141
+ const channel_id = select?.channel_id ?? data.channel_id;
142
+ return Controller.Message({ msg_id, user_id, channel_id });
143
+ };
144
+ };
145
+ /**
146
+ * 成员控制器
147
+ * @param select
148
+ * @returns
149
+ */
150
+ export const ClientControllerOnMember = (data) => {
151
+ return (select) => {
152
+ const guild_id = select?.guild_id ?? data.guild_id;
153
+ const user_id = select?.guild_id ?? data.user_id;
154
+ return Controller.Member({ guild_id, user_id });
155
+ };
156
+ };