alemonjs 1.0.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 (169) hide show
  1. package/LICENSE +340 -0
  2. package/README.md +54 -0
  3. package/lib/alemon/app.js +38 -0
  4. package/lib/alemon/apps.js +121 -0
  5. package/lib/alemon/buffer.js +38 -0
  6. package/lib/alemon/dealmsg.js +423 -0
  7. package/lib/alemon/dialogue.js +61 -0
  8. package/lib/alemon/index.js +40 -0
  9. package/lib/alemon/message.js +27 -0
  10. package/lib/alemon/plugin.js +44 -0
  11. package/lib/alemon/puppeteer.js +226 -0
  12. package/lib/alemon/qrcode.js +66 -0
  13. package/lib/alemon/screenshot.js +126 -0
  14. package/lib/alemon/typings.js +96 -0
  15. package/lib/config.js +25 -0
  16. package/lib/discord/alemon/api.js +44 -0
  17. package/lib/discord/alemon/bot.js +11 -0
  18. package/lib/discord/alemon/conversation.js +7 -0
  19. package/lib/discord/alemon/message/PUBLIC_GUILD_MESSAGES.js +185 -0
  20. package/lib/discord/alemon/segment.js +62 -0
  21. package/lib/discord/index.js +50 -0
  22. package/lib/discord/login.js +99 -0
  23. package/lib/index.js +12 -0
  24. package/lib/kook/alemon/bot.js +11 -0
  25. package/lib/kook/alemon/conversation.js +56 -0
  26. package/lib/kook/alemon/message/PUBLIC_GUILD_MESSAGES.js +195 -0
  27. package/lib/kook/alemon/segment.js +90 -0
  28. package/lib/kook/index.js +39 -0
  29. package/lib/kook/login.js +53 -0
  30. package/lib/login.js +112 -0
  31. package/lib/main.js +106 -0
  32. package/lib/ntqq/alemon/bot.js +11 -0
  33. package/lib/ntqq/alemon/conversation.js +18 -0
  34. package/lib/ntqq/alemon/message/C2C_MESSAGE_CREATE.js +142 -0
  35. package/lib/ntqq/alemon/message/GROUP_AT_MESSAGE_CREATE.js +218 -0
  36. package/lib/ntqq/alemon/segment.js +29 -0
  37. package/lib/ntqq/alemon/types.js +1 -0
  38. package/lib/ntqq/index.js +77 -0
  39. package/lib/ntqq/login.js +74 -0
  40. package/lib/ntqq/sdk/api.js +158 -0
  41. package/lib/ntqq/sdk/config.js +46 -0
  42. package/lib/ntqq/sdk/index.js +5 -0
  43. package/lib/ntqq/sdk/intents.js +69 -0
  44. package/lib/ntqq/sdk/types.js +1 -0
  45. package/lib/ntqq/sdk/typings.js +9 -0
  46. package/lib/ntqq/sdk/web/client.js +89 -0
  47. package/lib/ntqq/sdk/web/img.js +76 -0
  48. package/lib/ntqq/sdk/web/index.js +4 -0
  49. package/lib/ntqq/sdk/web/ip.js +24 -0
  50. package/lib/ntqq/sdk/wss.js +178 -0
  51. package/lib/qq/alemon/apidoc.js +216 -0
  52. package/lib/qq/alemon/bot.js +11 -0
  53. package/lib/qq/alemon/console.js +13 -0
  54. package/lib/qq/alemon/conversation.js +139 -0
  55. package/lib/qq/alemon/doc.js +93 -0
  56. package/lib/qq/alemon/e.js +41 -0
  57. package/lib/qq/alemon/message/AUDIO_ACTION.js +57 -0
  58. package/lib/qq/alemon/message/DIRECT_MESSAGE.js +202 -0
  59. package/lib/qq/alemon/message/FORUMS_EVENT.js +66 -0
  60. package/lib/qq/alemon/message/GUILDS.js +65 -0
  61. package/lib/qq/alemon/message/GUILD_MEMBERS.js +153 -0
  62. package/lib/qq/alemon/message/GUILD_MESSAGES.js +50 -0
  63. package/lib/qq/alemon/message/GUILD_MESSAGE_REACTIONS.js +37 -0
  64. package/lib/qq/alemon/message/INTERACTION.js +36 -0
  65. package/lib/qq/alemon/message/MESSAGE.js +303 -0
  66. package/lib/qq/alemon/message/MESSAGE_AUDIT.js +41 -0
  67. package/lib/qq/alemon/message/OPEN_FORUMS_EVENT.js +74 -0
  68. package/lib/qq/alemon/message/PUBLIC_GUILD_MESSAGES.js +52 -0
  69. package/lib/qq/alemon/permissions.js +43 -0
  70. package/lib/qq/alemon/privatechat.js +78 -0
  71. package/lib/qq/alemon/segment.js +25 -0
  72. package/lib/qq/alemon/types.js +25 -0
  73. package/lib/qq/index.js +44 -0
  74. package/lib/qq/login.js +151 -0
  75. package/lib/types.js +5 -0
  76. package/lib/villa/alemon/conversation.js +48 -0
  77. package/lib/villa/alemon/message/GUILDS.js +124 -0
  78. package/lib/villa/alemon/message/GUILD_MEMBERS.js +128 -0
  79. package/lib/villa/alemon/message/GUILD_MESSAGE_REACTIONS.js +127 -0
  80. package/lib/villa/alemon/message/MESSAGES.js +334 -0
  81. package/lib/villa/alemon/message/MESSAGE_AUDIT.js +128 -0
  82. package/lib/villa/alemon/message/e.js +41 -0
  83. package/lib/villa/alemon/segment.js +34 -0
  84. package/lib/villa/index.js +46 -0
  85. package/lib/villa/login.js +62 -0
  86. package/package.json +63 -0
  87. package/types/alemon/app.d.ts +22 -0
  88. package/types/alemon/apps.d.ts +41 -0
  89. package/types/alemon/buffer.d.ts +13 -0
  90. package/types/alemon/dealmsg.d.ts +41 -0
  91. package/types/alemon/dialogue.d.ts +55 -0
  92. package/types/alemon/index.d.ts +40 -0
  93. package/types/alemon/message.d.ts +17 -0
  94. package/types/alemon/plugin.d.ts +69 -0
  95. package/types/alemon/puppeteer.d.ts +53 -0
  96. package/types/alemon/qrcode.d.ts +20 -0
  97. package/types/alemon/screenshot.d.ts +23 -0
  98. package/types/alemon/typings.d.ts +525 -0
  99. package/types/config.d.ts +12 -0
  100. package/types/discord/alemon/api.d.ts +11 -0
  101. package/types/discord/alemon/bot.d.ts +6 -0
  102. package/types/discord/alemon/conversation.d.ts +6 -0
  103. package/types/discord/alemon/message/PUBLIC_GUILD_MESSAGES.d.ts +7 -0
  104. package/types/discord/alemon/segment.d.ts +46 -0
  105. package/types/discord/index.d.ts +1 -0
  106. package/types/discord/login.d.ts +7 -0
  107. package/types/index.d.ts +6 -0
  108. package/types/kook/alemon/bot.d.ts +8 -0
  109. package/types/kook/alemon/conversation.d.ts +7 -0
  110. package/types/kook/alemon/message/PUBLIC_GUILD_MESSAGES.d.ts +6 -0
  111. package/types/kook/alemon/segment.d.ts +66 -0
  112. package/types/kook/index.d.ts +5 -0
  113. package/types/kook/login.d.ts +7 -0
  114. package/types/login.d.ts +18 -0
  115. package/types/main.d.ts +15 -0
  116. package/types/ntqq/alemon/bot.d.ts +8 -0
  117. package/types/ntqq/alemon/conversation.d.ts +8 -0
  118. package/types/ntqq/alemon/message/C2C_MESSAGE_CREATE.d.ts +2 -0
  119. package/types/ntqq/alemon/message/GROUP_AT_MESSAGE_CREATE.d.ts +8 -0
  120. package/types/ntqq/alemon/segment.d.ts +20 -0
  121. package/types/ntqq/alemon/types.d.ts +11 -0
  122. package/types/ntqq/index.d.ts +1 -0
  123. package/types/ntqq/login.d.ts +6 -0
  124. package/types/ntqq/sdk/api.d.ts +44 -0
  125. package/types/ntqq/sdk/config.d.ts +23 -0
  126. package/types/ntqq/sdk/index.d.ts +5 -0
  127. package/types/ntqq/sdk/intents.d.ts +2 -0
  128. package/types/ntqq/sdk/types.d.ts +11 -0
  129. package/types/ntqq/sdk/typings.d.ts +17 -0
  130. package/types/ntqq/sdk/web/client.d.ts +8 -0
  131. package/types/ntqq/sdk/web/img.d.ts +20 -0
  132. package/types/ntqq/sdk/web/index.d.ts +4 -0
  133. package/types/ntqq/sdk/web/ip.d.ts +5 -0
  134. package/types/ntqq/sdk/wss.d.ts +35 -0
  135. package/types/qq/alemon/apidoc.d.ts +154 -0
  136. package/types/qq/alemon/bot.d.ts +8 -0
  137. package/types/qq/alemon/console.d.ts +1 -0
  138. package/types/qq/alemon/conversation.d.ts +5 -0
  139. package/types/qq/alemon/doc.d.ts +93 -0
  140. package/types/qq/alemon/e.d.ts +38 -0
  141. package/types/qq/alemon/message/AUDIO_ACTION.d.ts +15 -0
  142. package/types/qq/alemon/message/DIRECT_MESSAGE.d.ts +16 -0
  143. package/types/qq/alemon/message/FORUMS_EVENT.d.ts +25 -0
  144. package/types/qq/alemon/message/GUILDS.d.ts +19 -0
  145. package/types/qq/alemon/message/GUILD_MEMBERS.d.ts +11 -0
  146. package/types/qq/alemon/message/GUILD_MESSAGES.d.ts +12 -0
  147. package/types/qq/alemon/message/GUILD_MESSAGE_REACTIONS.d.ts +9 -0
  148. package/types/qq/alemon/message/INTERACTION.d.ts +8 -0
  149. package/types/qq/alemon/message/MESSAGE.d.ts +16 -0
  150. package/types/qq/alemon/message/MESSAGE_AUDIT.d.ts +9 -0
  151. package/types/qq/alemon/message/OPEN_FORUMS_EVENT.d.ts +28 -0
  152. package/types/qq/alemon/message/PUBLIC_GUILD_MESSAGES.d.ts +12 -0
  153. package/types/qq/alemon/permissions.d.ts +29 -0
  154. package/types/qq/alemon/privatechat.d.ts +14 -0
  155. package/types/qq/alemon/segment.d.ts +19 -0
  156. package/types/qq/alemon/types.d.ts +82 -0
  157. package/types/qq/index.d.ts +6 -0
  158. package/types/qq/login.d.ts +6 -0
  159. package/types/types.d.ts +85 -0
  160. package/types/villa/alemon/conversation.d.ts +7 -0
  161. package/types/villa/alemon/message/GUILDS.d.ts +10 -0
  162. package/types/villa/alemon/message/GUILD_MEMBERS.d.ts +14 -0
  163. package/types/villa/alemon/message/GUILD_MESSAGE_REACTIONS.d.ts +7 -0
  164. package/types/villa/alemon/message/MESSAGES.d.ts +7 -0
  165. package/types/villa/alemon/message/MESSAGE_AUDIT.d.ts +10 -0
  166. package/types/villa/alemon/message/e.d.ts +37 -0
  167. package/types/villa/alemon/segment.d.ts +26 -0
  168. package/types/villa/index.d.ts +1 -0
  169. package/types/villa/login.d.ts +7 -0
@@ -0,0 +1,218 @@
1
+ import { InstructionMatching } from '../../../alemon/index.js';
2
+ import { ClientAPIByQQ as Client, ClinetWeb, getWebConfig } from '../../sdk/index.js';
3
+ import { segmentQQ } from '../segment.js';
4
+ import { getBotMsgByNtqq } from '../bot.js';
5
+ import { getBotConfigByKey } from '../../../login.js';
6
+ import IMGS from 'image-size';
7
+ /**
8
+ * 获取ip
9
+ */
10
+ const ip = await ClinetWeb.getIP();
11
+ /**
12
+ * 公私域合并
13
+ * @param e
14
+ * @param data 原数据
15
+ * @returns
16
+ */
17
+ export const GROUP_AT_MESSAGE_CREATE = async (event) => {
18
+ const e = {};
19
+ e.platform = 'ntqq';
20
+ e.bot = getBotMsgByNtqq();
21
+ e.event = 'MESSAGES';
22
+ e.eventType = 'CREATE';
23
+ e.isPrivate = false;
24
+ e.isRecall = false;
25
+ e.isGroup = true;
26
+ /**
27
+ * 得到登录配置
28
+ */
29
+ const cfg = getBotConfigByKey('ntqq');
30
+ /**
31
+ * 得到主人id
32
+ */
33
+ const masterID = cfg.masterID;
34
+ /**
35
+ * 默认不是主人
36
+ */
37
+ e.isMaster = false;
38
+ /**
39
+ * 检查身份
40
+ */
41
+ if (event.author.id == masterID) {
42
+ /**
43
+ * 是主人
44
+ */
45
+ e.isMaster = true;
46
+ }
47
+ const webCfg = getWebConfig();
48
+ /**
49
+ * 消息发送机制
50
+ * @param msg 消息
51
+ * @param img
52
+ * @returns
53
+ */
54
+ e.reply = async (msg, img, name) => {
55
+ if (Buffer.isBuffer(msg)) {
56
+ try {
57
+ let url = '';
58
+ if (Buffer.isBuffer(msg)) {
59
+ /**
60
+ * 挂载图片
61
+ */
62
+ const uul = await ClinetWeb.setLocalImg(msg);
63
+ url = `${webCfg.http}://${ip}:${webCfg.callback_port}${uul}`;
64
+ return await Client.postFilesByGroup(event.group_id, url).catch(err => {
65
+ console.error(err);
66
+ return false;
67
+ });
68
+ }
69
+ }
70
+ catch (err) {
71
+ console.error(err);
72
+ return false;
73
+ }
74
+ }
75
+ const content = Array.isArray(msg)
76
+ ? msg.join('')
77
+ : typeof msg === 'string'
78
+ ? msg
79
+ : undefined;
80
+ if (Buffer.isBuffer(img)) {
81
+ try {
82
+ let url = '';
83
+ const dimensions = IMGS.imageSize(img);
84
+ const uul = await ClinetWeb.setLocalImg(img);
85
+ url = `${webCfg.http}://${ip}:${webCfg.callback_port}${uul}`;
86
+ return await Client.postMessageByGroup(event.group_id, `${content} ![text #${dimensions.width}px #${dimensions.height}px](${url})`, event.id)
87
+ .then(() => true)
88
+ .catch((err) => {
89
+ console.error(err);
90
+ return false;
91
+ });
92
+ }
93
+ catch (err) {
94
+ console.error(err);
95
+ return false;
96
+ }
97
+ }
98
+ return await Client.postMessageByGroup(event.group_id, content, event.id)
99
+ .then(() => true)
100
+ .catch((err) => {
101
+ console.error(err);
102
+ return false;
103
+ });
104
+ };
105
+ e.replyCard = async (arr) => {
106
+ for (const item of arr) {
107
+ try {
108
+ if (item.type == 'qq_ark' || item.type == 'qq_embed') {
109
+ console.info('暂不可用');
110
+ return false;
111
+ }
112
+ else {
113
+ return false;
114
+ }
115
+ }
116
+ catch {
117
+ return false;
118
+ }
119
+ }
120
+ return true;
121
+ };
122
+ /**
123
+ * 引用消息
124
+ * @param mid
125
+ * @param boj
126
+ * @returns
127
+ */
128
+ e.replyByMid = async (mid, msg) => {
129
+ console.info('暂不可用');
130
+ return false;
131
+ };
132
+ /**
133
+ * 发送表情表态
134
+ * @param mid
135
+ * @param boj { emoji_type: number; emoji_id: string }
136
+ * @returns
137
+ */
138
+ e.replyEmoji = async (mid, boj) => {
139
+ console.info('暂不可用');
140
+ return false;
141
+ };
142
+ /**
143
+ * 删除表情表态
144
+ * @param mid
145
+ * @param boj { emoji_type: number; emoji_id: string }
146
+ * @returns
147
+ */
148
+ e.deleteEmoji = async (mid, boj) => {
149
+ console.info('暂不可用');
150
+ return false;
151
+ };
152
+ /**
153
+ * 消息原文
154
+ */
155
+ e.msg_txt = event.content;
156
+ /**
157
+ * 消息
158
+ */
159
+ e.msg = event.content.trim();
160
+ /**
161
+ * 消息编号
162
+ */
163
+ e.msg_id = event.id;
164
+ /**
165
+ * 用户编号
166
+ */
167
+ e.user_id = event.author.id;
168
+ /**
169
+ * 用户头像
170
+ */
171
+ e.user_avatar = 'https://q1.qlogo.cn/g?b=qq&s=0&nk=1715713638';
172
+ /**
173
+ * 用户名
174
+ */
175
+ e.user_name = '柠檬冲水';
176
+ /**
177
+ * 子频道编号
178
+ */
179
+ e.channel_id = event.group_id;
180
+ /**
181
+ * 频道编号
182
+ */
183
+ e.guild_id = event.group_id;
184
+ /**
185
+ * 模块
186
+ */
187
+ e.segment = segmentQQ;
188
+ /**
189
+ * 被艾特的用户
190
+ */
191
+ e.at_users = [];
192
+ /**
193
+ * 艾特消息处理
194
+ */
195
+ e.at = false;
196
+ /**
197
+ * 存在at
198
+ */
199
+ if (e.at) {
200
+ /**
201
+ * 得到第一个艾特
202
+ */
203
+ e.at_user = e.at_users.find(item => item.bot != true);
204
+ }
205
+ /**
206
+ * 消息处理
207
+ */
208
+ await InstructionMatching(e)
209
+ .then(() => {
210
+ console.info(`\n[${e.channel_id}] [${e.user_name}] [${true}] \n ${e.msg_txt}`);
211
+ return;
212
+ })
213
+ .catch((err) => {
214
+ console.error(err);
215
+ console.info(`\n[${e.channel_id}] [${e.user_name}] [${false}] \n ${e.msg_txt}`);
216
+ return;
217
+ });
218
+ };
@@ -0,0 +1,29 @@
1
+ export const segmentQQ = {
2
+ /**
3
+ * 艾特某人
4
+ * @param uid
5
+ * @returns
6
+ */
7
+ at: function (uid) {
8
+ // 暂时用户@
9
+ return ``; // 没有艾特了
10
+ },
11
+ /**
12
+ * 艾特全体
13
+ * @returns
14
+ */
15
+ atAll: function atAll() {
16
+ return `@everyone`;
17
+ },
18
+ /**
19
+ * 子频道引用
20
+ * @param channel_id
21
+ * @returns
22
+ */
23
+ atChannel: function (channel_id) {
24
+ return ``; // 没有
25
+ },
26
+ link: function (title, centent) {
27
+ return `[🔗${title}](${centent})`;
28
+ }
29
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,77 @@
1
+ import { checkRobotByQQ } from './login.js';
2
+ import { getBotConfigByKey } from '../login.js';
3
+ import { conversation } from './alemon/conversation.js';
4
+ import { setBotConfig, createClient, ClientAPIByQQ, ClinetWeb, getWebConfig } from './sdk/index.js';
5
+ import { createWeb } from './sdk/web/client.js';
6
+ export async function createAlemonByNtqq() {
7
+ /**
8
+ * 登录
9
+ */
10
+ if (await checkRobotByQQ().catch(err => {
11
+ console.error(err);
12
+ process.exit();
13
+ })) {
14
+ /**
15
+ * 读取配置
16
+ */
17
+ const cfg = getBotConfigByKey('ntqq');
18
+ /**
19
+ * 发送请求
20
+ */
21
+ const data = await ClientAPIByQQ.getAuthentication(cfg.appID, cfg.secret).then(res => res.data);
22
+ const g = {
23
+ appID: cfg.appID,
24
+ token: data.access_token,
25
+ secret: cfg.secret,
26
+ intents: ['C2C_MESSAGE_CREATE', 'GROUP_AT_MESSAGE_CREATE']
27
+ };
28
+ /**
29
+ * 设置配置
30
+ */
31
+ setBotConfig(g);
32
+ const bal = async () => {
33
+ /**
34
+ * 发送请求
35
+ */
36
+ const data = await ClientAPIByQQ.getAuthentication(cfg.appID, cfg.secret).then(res => res.data);
37
+ g.token = data.access_token;
38
+ /**
39
+ * 设置配置
40
+ */
41
+ setBotConfig(g);
42
+ console.info('刷新时间:', data.expires_in, '秒');
43
+ setTimeout(bal, data.expires_in * 1000);
44
+ };
45
+ setTimeout(bal, data.expires_in * 1000);
46
+ /**
47
+ * 创建客户端
48
+ */
49
+ createClient(conversation);
50
+ /**
51
+ * 创建web端
52
+ */
53
+ createWeb({
54
+ callback_port: cfg.port,
55
+ http: cfg.http,
56
+ img_url: cfg.img_url,
57
+ IMAGE_DIR: cfg.IMAGE_DIR,
58
+ img_size: cfg.size
59
+ });
60
+ const webCfg = getWebConfig();
61
+ /**
62
+ * 获取ip4
63
+ */
64
+ const ip = await ClinetWeb.getIP();
65
+ if (ip) {
66
+ console.info(`[OPEN] ${webCfg.http ?? 'http'}://${ip}:${webCfg.port ?? 9090}`);
67
+ // 启动清除机制
68
+ ClinetWeb.autoClearImages(600000);
69
+ }
70
+ else {
71
+ console.error('公网IP识别失败~暂无法支持运行');
72
+ return;
73
+ }
74
+ return true;
75
+ }
76
+ return false;
77
+ }
@@ -0,0 +1,74 @@
1
+ import prompts from 'prompts';
2
+ import { setBotConfigByKey, getBotConfigByKey } from '../login.js';
3
+ import { getToml, writeToml } from '../config.js';
4
+ import { NtQQEventsEnum } from '../types.js';
5
+ /**
6
+ * 登录配置
7
+ * @param Bcf
8
+ * @returns
9
+ */
10
+ export async function checkRobotByQQ() {
11
+ if (process.argv.indexOf('login') == -1) {
12
+ const config = getBotConfigByKey('ntqq');
13
+ if ((config ?? '') !== '' &&
14
+ (config.appID ?? '') !== '' &&
15
+ (config.token ?? '') !== '') {
16
+ if (!config.intents) {
17
+ config.intents = [
18
+ NtQQEventsEnum.GROUP_AT_MESSAGE_CREATE,
19
+ NtQQEventsEnum.C2C_MESSAGE_CREATE
20
+ ];
21
+ }
22
+ setBotConfigByKey('ntqq', config);
23
+ return true;
24
+ }
25
+ }
26
+ console.info('[LOGIN]', '-----------------------');
27
+ const timeoutId = setTimeout(() => {
28
+ throw '超过1分钟未完成登录';
29
+ }, 60000);
30
+ const { appID, token } = await prompts([
31
+ {
32
+ type: 'password',
33
+ name: 'appID',
34
+ message: 'BotAppID: ',
35
+ validate: value => value !== '' && typeof value === 'string' ? true : '机器人 appID: '
36
+ },
37
+ {
38
+ type: 'password',
39
+ name: 'token',
40
+ message: 'BotToken: ',
41
+ validate: value => value !== '' && typeof value === 'string' ? true : '机器人 token: '
42
+ }
43
+ ]).catch((err) => {
44
+ console.error(err);
45
+ process.exit();
46
+ });
47
+ if (!appID || !token) {
48
+ return false;
49
+ }
50
+ clearTimeout(timeoutId);
51
+ /**
52
+ * 默认公域机器人
53
+ */
54
+ const intents = [
55
+ NtQQEventsEnum.GROUP_AT_MESSAGE_CREATE,
56
+ NtQQEventsEnum.C2C_MESSAGE_CREATE
57
+ ];
58
+ // 得到已变更的配置
59
+ const db = getBotConfigByKey('ntqq');
60
+ // 得到配置
61
+ const data = getToml();
62
+ data.ntqq = {
63
+ ...db,
64
+ // 覆盖新配置
65
+ appID,
66
+ token,
67
+ intents
68
+ };
69
+ // 写入配置
70
+ writeToml(data);
71
+ // 设置配置
72
+ setBotConfigByKey('ntqq', data.ntqq);
73
+ return true;
74
+ }
@@ -0,0 +1,158 @@
1
+ import axios from 'axios';
2
+ import { getBotConfig } from './config.js';
3
+ let aut;
4
+ export function setAuthentication(val) {
5
+ aut = val;
6
+ }
7
+ /**
8
+ * 得到鉴权
9
+ * @param appId
10
+ * @param clientSecret
11
+ * @param url
12
+ * @returns
13
+ */
14
+ export function getAuthentication(appId, clientSecret) {
15
+ return axios.post(aut ?? 'https://bots.qq.com/app/getAppAccessToken', {
16
+ appId: appId,
17
+ clientSecret: clientSecret
18
+ });
19
+ }
20
+ /**
21
+ * 创建axios实例
22
+ * @param config
23
+ * @returns
24
+ */
25
+ export async function requestService(config) {
26
+ const { token } = getBotConfig();
27
+ const service = await axios.create({
28
+ baseURL: 'https://api.sgroup.qq.com',
29
+ timeout: 20000,
30
+ headers: {
31
+ Authorization: `QQBot ${token}`
32
+ }
33
+ });
34
+ return service(config);
35
+ }
36
+ /**
37
+ * 发送图片
38
+ * @param openid
39
+ * @param content
40
+ * @returns
41
+ */
42
+ export async function postFilesByUsers(openid, content) {
43
+ const { appID } = getBotConfig();
44
+ return requestService({
45
+ url: `/v2/users/${openid}/files`,
46
+ method: 'post',
47
+ headers: {
48
+ 'X-Union-Appid': appID
49
+ },
50
+ data: {
51
+ srv_send_msg: true,
52
+ url: content,
53
+ file_type: 1 // 1 图文 2 视频 3 语言 4 文件
54
+ }
55
+ });
56
+ }
57
+ /**
58
+ * 发送群聊图片
59
+ * @param openid
60
+ * @param content
61
+ * @returns
62
+ */
63
+ export async function postFilesByGroup(openid, content) {
64
+ const { appID } = getBotConfig();
65
+ return requestService({
66
+ url: `/v2/groups/${openid}/files`,
67
+ method: 'post',
68
+ headers: {
69
+ 'X-Union-Appid': appID
70
+ },
71
+ data: {
72
+ srv_send_msg: true,
73
+ url: content,
74
+ file_type: 1 // 1 图文 2 视频 3 语言 4 文件
75
+ }
76
+ });
77
+ }
78
+ /**
79
+ * 发送私聊消息
80
+ * @param openid
81
+ * @param content
82
+ * @returns
83
+ */
84
+ export async function postMessageByUser(openid, content, msg_id) {
85
+ const { appID } = getBotConfig();
86
+ if (/\[🔗[^\]]+\]\([^)]+\)|@everyone/.test(content)) {
87
+ // md
88
+ return requestService({
89
+ url: `/v2/users/${openid}/messages`,
90
+ method: 'post',
91
+ headers: {
92
+ 'X-Union-Appid': appID
93
+ },
94
+ data: {
95
+ content: 'md',
96
+ msg_id: msg_id,
97
+ markdown: { content },
98
+ msg_type: 2 // 0 文本 1 图文 2 md 3 ark 4 embed
99
+ }
100
+ });
101
+ }
102
+ else {
103
+ return requestService({
104
+ url: `/v2/users/${openid}/messages`,
105
+ method: 'post',
106
+ headers: {
107
+ 'X-Union-Appid': appID
108
+ },
109
+ data: {
110
+ content: content,
111
+ msg_id: msg_id,
112
+ // markdown: { content },
113
+ msg_type: 0 // 0 文本 1 图文 2 md 3 ark 4 embed
114
+ }
115
+ });
116
+ }
117
+ }
118
+ /**
119
+ * 发送群聊消息
120
+ * @param openid
121
+ * @param content
122
+ * @returns
123
+ */
124
+ export async function postMessageByGroup(group_openid, content, msg_id) {
125
+ const { appID } = getBotConfig();
126
+ if (/\[[^\]]+\]\([^)]+\)|@everyone/.test(content)) {
127
+ // md
128
+ return requestService({
129
+ url: `/v2/groups/${group_openid}/messages`,
130
+ method: 'post',
131
+ headers: {
132
+ 'X-Union-Appid': appID
133
+ },
134
+ data: {
135
+ content: 'md',
136
+ msg_id: msg_id,
137
+ markdown: { content },
138
+ msg_type: 2,
139
+ timestamp: Math.floor(Date.now() / 1000)
140
+ }
141
+ });
142
+ }
143
+ else {
144
+ return requestService({
145
+ url: `/v2/groups/${group_openid}/messages`,
146
+ method: 'post',
147
+ headers: {
148
+ 'X-Union-Appid': appID
149
+ },
150
+ data: {
151
+ content: content,
152
+ msg_id: msg_id,
153
+ msg_type: 0,
154
+ timestamp: Math.floor(Date.now() / 1000)
155
+ }
156
+ });
157
+ }
158
+ }
@@ -0,0 +1,46 @@
1
+ let cfg = {
2
+ appID: '',
3
+ token: '',
4
+ secret: '',
5
+ intents: []
6
+ };
7
+ /**
8
+ * 得到机器人配置
9
+ * @returns
10
+ */
11
+ export function getBotConfig() {
12
+ return cfg;
13
+ }
14
+ /**
15
+ * 设置机器人配置
16
+ * @param val
17
+ * @returns
18
+ */
19
+ export function setBotConfig(val) {
20
+ cfg = val;
21
+ return;
22
+ }
23
+ /**
24
+ * 配置
25
+ */
26
+ let ClientCfg = {
27
+ callback_port: 9090,
28
+ img_size: 9999999,
29
+ http: 'http',
30
+ img_url: '/api/mys/img',
31
+ IMAGE_DIR: '/data/mys/img'
32
+ };
33
+ /**
34
+ * 设置配置
35
+ * @param cfg
36
+ */
37
+ export function setWebConfig(cfg) {
38
+ ClientCfg = cfg;
39
+ }
40
+ /**
41
+ * 得到配置
42
+ * @returns
43
+ */
44
+ export function getWebConfig() {
45
+ return ClientCfg;
46
+ }
@@ -0,0 +1,5 @@
1
+ export * as ClientAPIByQQ from './api.js';
2
+ export * from './typings.js';
3
+ export * from './config.js';
4
+ export * from './wss.js';
5
+ export * as ClinetWeb from './web/index.js';
@@ -0,0 +1,69 @@
1
+ const intentsMap = {
2
+ GUILDS: 1 << 0,
3
+ GUILD_CREATE: 1 << 0,
4
+ GUILD_UPDATE: 1 << 0,
5
+ GUILD_DELETE: 1 << 0,
6
+ CHANNEL_CREATE: 1 << 0,
7
+ CHANNEL_UPDATE: 1 << 0,
8
+ CHANNEL_DELETE: 1 << 0,
9
+ GUILD_MEMBERS: 1 << 1,
10
+ GUILD_MEMBER_ADD: 1 << 1,
11
+ GUILD_MEMBER_UPDATE: 1 << 1,
12
+ GUILD_MEMBER_REMOVE: 1 << 1,
13
+ GUILD_MESSAGES: 1 << 9,
14
+ MESSAGE_CREATE: 1 << 9,
15
+ MESSAGE_DELETE: 1 << 9,
16
+ GUILD_MESSAGE_REACTIONS: 1 << 10,
17
+ MESSAGE_REACTION_ADD: 1 << 10,
18
+ MESSAGE_REACTION_REMOVE: 1 << 10,
19
+ DIRECT_MESSAGE: 1 << 12,
20
+ DIRECT_MESSAGE_CREATE: 1 << 12,
21
+ DIRECT_MESSAGE_DELETE: 1 << 12,
22
+ OPEN_FORUMS_EVENT: 1 << 18,
23
+ OPEN_FORUM_THREAD_CREATE: 1 << 18,
24
+ OPEN_FORUM_THREAD_UPDATE: 1 << 18,
25
+ OPEN_FORUM_THREAD_DELETE: 1 << 18,
26
+ OPEN_FORUM_POST_CREATE: 1 << 18,
27
+ OPEN_FORUM_POST_DELETE: 1 << 18,
28
+ OPEN_FORUM_REPLY_CREATE: 1 << 18,
29
+ OPEN_FORUM_REPLY_DELETE: 1 << 18,
30
+ AUDIO_OR_LIVE_CHANNEL_MEMBER: 1 << 19,
31
+ AUDIO_OR_LIVE_CHANNEL_MEMBER_ENTER: 1 << 19,
32
+ AUDIO_OR_LIVE_CHANNEL_MEMBER_EXIT: 1 << 19,
33
+ INTERACTION: 1 << 26,
34
+ INTERACTION_CREATE: 1 << 26,
35
+ MESSAGE_AUDIT: 1 << 27,
36
+ MESSAGE_AUDIT_PASS: 1 << 27,
37
+ MESSAGE_AUDIT_REJECT: 1 << 27,
38
+ FORUMS_EVENT: 1 << 28,
39
+ FORUM_THREAD_CREATE: 1 << 28,
40
+ FORUM_THREAD_UPDATE: 1 << 28,
41
+ FORUM_THREAD_DELETE: 1 << 28,
42
+ FORUM_POST_CREATE: 1 << 28,
43
+ FORUM_POST_DELETE: 1 << 28,
44
+ FORUM_REPLY_CREATE: 1 << 28,
45
+ FORUM_REPLY_DELETE: 1 << 28,
46
+ FORUM_PUBLISH_AUDIT_RESULT: 1 << 28,
47
+ AUDIO_ACTION: 1 << 29,
48
+ AUDIO_START: 1 << 29,
49
+ AUDIO_FINISH: 1 << 29,
50
+ AUDIO_ON_MIC: 1 << 29,
51
+ AUDIO_OFF_MIC: 1 << 29,
52
+ PUBLIC_GUILD_MESSAGES: 1 << 30,
53
+ AT_MESSAGE_CREATE: 1 << 30,
54
+ PUBLIC_MESSAGE_DELETE: 1 << 30,
55
+ GROUP_AT_MESSAGE_CREATE: 1 << 25,
56
+ C2C_MESSAGE_CREATE: 1 << 25
57
+ // FRIEND_ADD: 1 << 25
58
+ // GROUP_ADD_ROBOT: 1 << 25
59
+ };
60
+ export function getIntentsMask(intents) {
61
+ let intentsMask = 0;
62
+ for (const item of intents) {
63
+ const mask = intentsMap[item];
64
+ if (mask) {
65
+ intentsMask |= mask;
66
+ }
67
+ }
68
+ return intentsMask;
69
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,9 @@
1
+ /**
2
+ * 订阅枚举
3
+ */
4
+ export const AvailableIntentsEventsEnum = [
5
+ 'FRIEND_ADD',
6
+ 'GROUP_AT_MESSAGE_CREATE',
7
+ 'C2C_MESSAGE_CREATE',
8
+ 'INTERACTION_CREATE'
9
+ ];