@alemonjs/qq-bot 2.1.0-alpha.19 → 2.1.0-alpha.20

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 (101) hide show
  1. package/lib/config.d.ts +8 -3
  2. package/lib/desktop.d.ts +1 -3
  3. package/lib/desktop.js +0 -10
  4. package/lib/hook.d.ts +12 -29
  5. package/lib/hook.js +0 -20
  6. package/lib/index.d.ts +4 -6
  7. package/lib/index.js +2 -5
  8. package/lib/index.webhook.d.ts +1 -0
  9. package/lib/index.webhook.js +0 -1
  10. package/lib/index.websoket.d.ts +1 -0
  11. package/lib/index.websoket.js +4 -5
  12. package/lib/message/AT_MESSAGE_CREATE.d.ts +1 -3
  13. package/lib/message/AT_MESSAGE_CREATE.js +1 -0
  14. package/lib/message/CHANNEL_CREATE.d.ts +15 -0
  15. package/lib/message/CHANNEL_CREATE.js +1 -0
  16. package/lib/message/CHANNEL_DELETE.d.ts +15 -0
  17. package/lib/message/CHANNEL_DELETE.js +1 -0
  18. package/lib/message/CHANNEL_UPDATE.d.ts +15 -0
  19. package/lib/message/CHANNEL_UPDATE.js +1 -0
  20. package/lib/message/DIRECT_MESSAGE_CREATE.d.ts +1 -8
  21. package/lib/message/DIRECT_MESSAGE_CREATE.js +1 -0
  22. package/lib/message/DIRECT_MESSAGE_DELETE.d.ts +17 -0
  23. package/lib/message/DIRECT_MESSAGE_DELETE.js +1 -0
  24. package/lib/message/ERROR.d.ts +1 -0
  25. package/lib/message/ERROR.js +1 -0
  26. package/lib/message/GUILD_CREATE.d.ts +15 -0
  27. package/lib/message/GUILD_CREATE.js +1 -0
  28. package/lib/message/GUILD_DELETE.d.ts +15 -0
  29. package/lib/message/GUILD_DELETE.js +1 -0
  30. package/lib/message/GUILD_MEMBER_ADD.d.ts +14 -0
  31. package/lib/message/GUILD_MEMBER_ADD.js +1 -0
  32. package/lib/message/GUILD_MEMBER_REMOVE.d.ts +14 -0
  33. package/lib/message/GUILD_MEMBER_REMOVE.js +1 -0
  34. package/lib/message/GUILD_MEMBER_UPDATE.d.ts +14 -0
  35. package/lib/message/GUILD_MEMBER_UPDATE.js +1 -0
  36. package/lib/message/GUILD_UPDATE.d.ts +15 -0
  37. package/lib/message/GUILD_UPDATE.js +1 -0
  38. package/lib/message/INTERACTION_CREATE.d.ts +1 -8
  39. package/lib/message/INTERACTION_CREATE.js +1 -0
  40. package/lib/message/MESSAGE_CREATE.d.ts +1 -0
  41. package/lib/message/MESSAGE_CREATE.js +1 -0
  42. package/lib/message/MESSAGE_DELETE.d.ts +1 -0
  43. package/lib/message/MESSAGE_DELETE.js +1 -0
  44. package/lib/message/MESSAGE_REACTION_ADD.d.ts +13 -0
  45. package/lib/message/MESSAGE_REACTION_ADD.js +1 -0
  46. package/lib/message/MESSAGE_REACTION_REMOVE.d.ts +13 -0
  47. package/lib/message/MESSAGE_REACTION_REMOVE.js +1 -0
  48. package/lib/message/PUBLIC_MESSAGE_DELETE.d.ts +15 -0
  49. package/lib/message/PUBLIC_MESSAGE_DELETE.js +1 -0
  50. package/lib/message/READY.d.ts +6 -0
  51. package/lib/message/READY.js +1 -0
  52. package/lib/message/group/C2C_MESSAGE_CREATE.d.ts +1 -3
  53. package/lib/message/group/C2C_MESSAGE_CREATE.js +1 -0
  54. package/lib/message/group/C2C_MSG_RECEIVE.d.ts +4 -0
  55. package/lib/message/group/C2C_MSG_RECEIVE.js +1 -0
  56. package/lib/message/group/C2C_MSG_REJECT.d.ts +4 -0
  57. package/lib/message/group/C2C_MSG_REJECT.js +1 -0
  58. package/lib/message/group/FRIEND_ADD.d.ts +4 -0
  59. package/lib/message/group/FRIEND_ADD.js +1 -0
  60. package/lib/message/group/FRIEND_DEL.d.ts +4 -0
  61. package/lib/message/group/FRIEND_DEL.js +1 -0
  62. package/lib/message/group/GROUP_ADD_ROBOT.d.ts +5 -0
  63. package/lib/message/group/GROUP_ADD_ROBOT.js +1 -0
  64. package/lib/message/group/GROUP_AT_MESSAGE_CREATE.d.ts +1 -6
  65. package/lib/message/group/GROUP_AT_MESSAGE_CREATE.js +1 -0
  66. package/lib/message/group/GROUP_DEL_ROBOT.d.ts +5 -0
  67. package/lib/message/group/GROUP_DEL_ROBOT.js +1 -0
  68. package/lib/message/group/GROUP_MSG_RECEIVE.d.ts +5 -0
  69. package/lib/message/group/GROUP_MSG_RECEIVE.js +1 -0
  70. package/lib/message/group/GROUP_MSG_REJECT.d.ts +5 -0
  71. package/lib/message/group/GROUP_MSG_REJECT.js +1 -0
  72. package/lib/register.d.ts +2 -0
  73. package/lib/register.js +0 -97
  74. package/lib/sdk/api.d.ts +6 -529
  75. package/lib/sdk/api.js +0 -526
  76. package/lib/sdk/client.webhook.d.ts +9 -0
  77. package/lib/sdk/client.webhook.js +0 -39
  78. package/lib/sdk/client.websoket.d.ts +9 -0
  79. package/lib/sdk/client.websoket.js +4 -57
  80. package/lib/sdk/config.d.ts +1 -0
  81. package/lib/sdk/instance.d.ts +3 -0
  82. package/lib/sdk/instance.js +3 -19
  83. package/lib/sdk/intents.d.ts +3 -0
  84. package/lib/sdk/intents.js +25 -90
  85. package/lib/sdk/message.d.ts +4 -0
  86. package/lib/sdk/message.group.d.ts +24 -0
  87. package/lib/sdk/message.group.js +1 -0
  88. package/lib/sdk/message.guild.d.ts +38 -0
  89. package/lib/sdk/message.guild.js +1 -0
  90. package/lib/sdk/message.js +1 -0
  91. package/lib/sdk/message.public.d.ts +6 -0
  92. package/lib/sdk/message.public.js +1 -0
  93. package/lib/sdk/typing.d.ts +21 -11
  94. package/lib/sdk/typing.js +1 -0
  95. package/lib/sdk/webhook.secret.d.ts +14 -0
  96. package/lib/sdk/webhook.secret.js +2 -19
  97. package/lib/sends.d.ts +29 -0
  98. package/lib/sends.js +19 -107
  99. package/lib/utils.d.ts +1 -0
  100. package/lib/utils.js +8 -0
  101. package/package.json +4 -4
@@ -0,0 +1,9 @@
1
+ import { QQBotAPI } from './api.js';
2
+ import { QQBotEventMap } from './message.js';
3
+ import { Options } from '../config.js';
4
+ export declare class QQBotClient extends QQBotAPI {
5
+ #private;
6
+ constructor(opstion: Options);
7
+ on<T extends keyof QQBotEventMap>(key: T, val: (event: QQBotEventMap[T]) => any): this;
8
+ connect(): void;
9
+ }
@@ -13,21 +13,12 @@ class QQBotClient extends QQBotAPI {
13
13
  #count = 0;
14
14
  #client = [];
15
15
  #ws = null;
16
- /**
17
- * 设置配置
18
- * @param opstion
19
- */
20
16
  constructor(opstion) {
21
17
  super();
22
18
  for (const key in opstion) {
23
19
  config.set(key, opstion[key]);
24
20
  }
25
21
  }
26
- /**
27
- * 注册事件处理程序
28
- * @param key 事件名称
29
- * @param val 事件处理函数
30
- */
31
22
  on(key, val) {
32
23
  if (!this.#events[key]) {
33
24
  this.#events[key] = [];
@@ -35,11 +26,6 @@ class QQBotClient extends QQBotAPI {
35
26
  this.#events[key].push(val);
36
27
  return this;
37
28
  }
38
- /**
39
- * 定时鉴权
40
- * @param cfg
41
- * @returns
42
- */
43
29
  async #setTimeoutBotConfig() {
44
30
  const callBack = async () => {
45
31
  const app_id = config.get('app_id');
@@ -50,7 +36,6 @@ class QQBotClient extends QQBotAPI {
50
36
  if (!secret) {
51
37
  return;
52
38
  }
53
- // 发送请求
54
39
  const data = await this.getAuthentication(app_id, secret).then(res => res.data);
55
40
  config.set('access_token', data.access_token);
56
41
  console.info('refresh', data.expires_in, 's');
@@ -58,11 +43,6 @@ class QQBotClient extends QQBotAPI {
58
43
  };
59
44
  await callBack();
60
45
  }
61
- /**
62
- *
63
- * @param cfg
64
- * @param conversation
65
- */
66
46
  connect() {
67
47
  try {
68
48
  const ws = config.get('ws');
@@ -87,7 +67,6 @@ class QQBotClient extends QQBotAPI {
87
67
  ctx.req.on('end', () => (ctx.request.rawBody = rawData));
88
68
  await next();
89
69
  });
90
- // 启动服务
91
70
  router.post(route, ctx => {
92
71
  const sign = ctx.req.headers['x-signature-ed25519'];
93
72
  const timestamp = ctx.req.headers['x-signature-timestamp'];
@@ -102,20 +81,16 @@ class QQBotClient extends QQBotAPI {
102
81
  if (+body.op === 13) {
103
82
  ctx.status = 200;
104
83
  ctx.body = {
105
- // 返回明文 token
106
84
  plain_token: body.d.plain_token,
107
- // 生成签名
108
85
  signature: ntqqWebhook.getSign(body.d.event_ts, body.d.plain_token)
109
86
  };
110
87
  }
111
88
  else if (+body.op === 0) {
112
89
  ctx.status = 204;
113
- // 根据事件类型,处理事件
114
90
  for (const event of this.#events[body.t] || []) {
115
91
  event(body.d);
116
92
  }
117
93
  const accessToken = config.get('access_token');
118
- // 也可以分法到客户端。 发送失败需要处理 或清理调
119
94
  for (const client of this.#client) {
120
95
  try {
121
96
  if (accessToken) {
@@ -131,22 +106,17 @@ class QQBotClient extends QQBotAPI {
131
106
  });
132
107
  this.#app.use(router.routes());
133
108
  this.#app.use(router.allowedMethods());
134
- // 启动服务
135
109
  const server = this.#app.listen(cfg.port, () => {
136
110
  console.log('Server running at http://localhost:' + cfg.port + route);
137
111
  });
138
- // 创建 WebSocketServer 并监听同一个端口
139
112
  const wss = new WebSocketServer({ server: server });
140
113
  console.log('Server running at ws://localhost:' + cfg.port + '/');
141
- // 处理客户端连接
142
114
  wss.on('connection', ws => {
143
115
  const clientId = v4();
144
116
  ws['clientId'] = clientId;
145
117
  console.log(clientId, 'connection');
146
118
  this.#client.push({ id: clientId, ws });
147
- // 处理消息事件
148
119
  ws.on('message', (message) => {
149
- // 拿到消息
150
120
  try {
151
121
  const body = JSON.parse(message.toString());
152
122
  for (const event of this.#events[body.t] || []) {
@@ -157,7 +127,6 @@ class QQBotClient extends QQBotAPI {
157
127
  this.#error(e);
158
128
  }
159
129
  });
160
- // 处理关闭事件
161
130
  ws.on('close', () => {
162
131
  console.log(`${clientId} disconnected`);
163
132
  this.#client = this.#client.filter(client => client.id !== clientId);
@@ -166,7 +135,6 @@ class QQBotClient extends QQBotAPI {
166
135
  }
167
136
  else {
168
137
  const reConnect = () => {
169
- // 使用了ws服务器
170
138
  this.#ws = new WebSocket(ws);
171
139
  this.#ws.on('open', () => {
172
140
  this.#count = 0;
@@ -174,7 +142,6 @@ class QQBotClient extends QQBotAPI {
174
142
  });
175
143
  this.#ws.on('message', data => {
176
144
  try {
177
- // 拿到消息
178
145
  const body = JSON.parse(data.toString());
179
146
  const accessToken = body['access_token'];
180
147
  if (accessToken) {
@@ -190,11 +157,9 @@ class QQBotClient extends QQBotAPI {
190
157
  });
191
158
  this.#ws.on('close', () => {
192
159
  console.log('ws closed');
193
- // 重连5次,超过5次不再重连
194
160
  if (this.#count > 5) {
195
161
  return;
196
162
  }
197
- // 1.3s 后重连
198
163
  setTimeout(() => {
199
164
  reConnect();
200
165
  }, 1300);
@@ -210,10 +175,6 @@ class QQBotClient extends QQBotAPI {
210
175
  this.#error(e);
211
176
  }
212
177
  }
213
- /**
214
- *
215
- * @param error
216
- */
217
178
  #error(error) {
218
179
  if (this.#events['ERROR']) {
219
180
  for (const event of this.#events['ERROR'] || []) {
@@ -0,0 +1,9 @@
1
+ import { QQBotAPI } from './api.js';
2
+ import { QQBotEventMap } from './message.js';
3
+ import { Options } from './typing.js';
4
+ export declare class QQBotClients extends QQBotAPI {
5
+ #private;
6
+ constructor(opstion: Options);
7
+ on<T extends keyof QQBotEventMap>(key: T, val: (event: QQBotEventMap[T]) => any): this;
8
+ connect(gatewayURL?: string): Promise<void>;
9
+ }
@@ -4,35 +4,18 @@ import { config } from './config.js';
4
4
  import { getIntentsMask } from './intents.js';
5
5
  import { Counter } from 'alemonjs/utils';
6
6
 
7
- /**
8
- * 连接
9
- */
10
7
  class QQBotClients extends QQBotAPI {
11
- //
12
- #counter = new Counter(1); // 初始值为1
13
- // 标记是否已连接
8
+ #counter = new Counter(1);
14
9
  #isConnected = false;
15
- // 存储最新的消息序号
16
10
  #heartbeat_interval = 30000;
17
- // 鉴权
18
11
  #IntervalId = null;
19
- // url
20
12
  #gatewayUrl = null;
21
- /**
22
- * 设置配置
23
- * @param opstion
24
- */
25
13
  constructor(opstion) {
26
14
  super();
27
15
  for (const key in opstion) {
28
16
  config.set(key, opstion[key]);
29
17
  }
30
18
  }
31
- /**
32
- * 定时鉴权
33
- * @param cfg
34
- * @returns
35
- */
36
19
  async #setTimeoutBotConfig() {
37
20
  const accessToken = async () => {
38
21
  const app_id = config.get('app_id');
@@ -40,7 +23,6 @@ class QQBotClients extends QQBotAPI {
40
23
  if (!app_id || !secret) {
41
24
  return;
42
25
  }
43
- // 发送请求
44
26
  const data = await this.getAuthentication(app_id, secret).then(res => res.data);
45
27
  config.set('access_token', data.access_token);
46
28
  console.info('refresh', data.expires_in, 's');
@@ -48,16 +30,12 @@ class QQBotClients extends QQBotAPI {
48
30
  };
49
31
  await accessToken();
50
32
  }
51
- /**
52
- * 鉴权数据
53
- * @returns
54
- */
55
33
  #aut() {
56
34
  const token = config.get('access_token');
57
35
  const intents = config.get('intents');
58
36
  const shard = config.get('shard');
59
37
  return {
60
- op: 2, // op = 2
38
+ op: 2,
61
39
  d: {
62
40
  token: `QQBot ${token}`,
63
41
  intents: getIntentsMask(intents),
@@ -72,11 +50,6 @@ class QQBotClients extends QQBotAPI {
72
50
  }
73
51
  #ws = null;
74
52
  #events = {};
75
- /**
76
- * 注册事件处理程序
77
- * @param key 事件名称
78
- * @param val 事件处理函数
79
- */
80
53
  on(key, val) {
81
54
  if (!this.#events[key]) {
82
55
  this.#events[key] = [];
@@ -84,22 +57,14 @@ class QQBotClients extends QQBotAPI {
84
57
  this.#events[key].push(val);
85
58
  return this;
86
59
  }
87
- /**
88
- *
89
- * @param cfg
90
- * @param conversation
91
- */
92
60
  async connect(gatewayURL) {
93
- // 定时模式
94
61
  await this.#setTimeoutBotConfig();
95
- // 请求url
96
62
  if (!this.#gatewayUrl) {
97
63
  this.#gatewayUrl = gatewayURL ?? (await this.gateway().then(res => res?.url));
98
64
  }
99
65
  if (!this.#gatewayUrl) {
100
66
  return;
101
67
  }
102
- // 重新连接的逻辑
103
68
  const reconnect = () => {
104
69
  if (this.#counter.value >= 5) {
105
70
  console.info('The maximum number of reconnections has been reached, cancel reconnection');
@@ -107,9 +72,7 @@ class QQBotClients extends QQBotAPI {
107
72
  }
108
73
  setTimeout(() => {
109
74
  console.info('[ws-qqbot] reconnecting...');
110
- // 重新starrt
111
75
  start();
112
- // 记录
113
76
  this.#counter.next();
114
77
  }, 5000);
115
78
  };
@@ -120,7 +83,6 @@ class QQBotClients extends QQBotAPI {
120
83
  if (this.#events[t]) {
121
84
  try {
122
85
  for (const event of this.#events[t]) {
123
- // 是否是函数
124
86
  if (typeof event !== 'function') {
125
87
  continue;
126
88
  }
@@ -130,7 +92,6 @@ class QQBotClients extends QQBotAPI {
130
92
  catch (err) {
131
93
  if (this.#events['ERROR']) {
132
94
  for (const event of this.#events['ERROR']) {
133
- // 是否是函数
134
95
  if (typeof event !== 'function') {
135
96
  continue;
136
97
  }
@@ -139,21 +100,18 @@ class QQBotClients extends QQBotAPI {
139
100
  }
140
101
  }
141
102
  }
142
- // Ready Event,鉴权成功
143
103
  if (t === 'READY') {
144
104
  this.#IntervalId = setInterval(() => {
145
105
  if (this.#isConnected && this.#ws) {
146
106
  this.#ws.send(JSON.stringify({
147
- op: 1, // op = 1
148
- d: null // 如果是第一次连接,传null
107
+ op: 1,
108
+ d: null
149
109
  }));
150
110
  }
151
111
  }, this.#heartbeat_interval);
152
112
  }
153
- // Resumed Event,恢复连接成功
154
113
  if (t === 'RESUMED') {
155
114
  console.info('[ws-qqbot] restore connection');
156
- // 重制次数
157
115
  this.#counter.reStart();
158
116
  }
159
117
  },
@@ -161,9 +119,7 @@ class QQBotClients extends QQBotAPI {
161
119
  console.info('[ws-qqbot] connection attempt', d);
162
120
  },
163
121
  7: ({ d }) => {
164
- // 执行重新连接
165
122
  console.info('[ws-qqbot] reconnect', d);
166
- // 取消鉴权发送
167
123
  if (this.#IntervalId) {
168
124
  clearInterval(this.#IntervalId);
169
125
  }
@@ -172,42 +128,33 @@ class QQBotClients extends QQBotAPI {
172
128
  console.info('[ws-qqbot] parameter error', d);
173
129
  },
174
130
  10: ({ d }) => {
175
- // 重制次数
176
131
  this.#isConnected = true;
177
- // 记录新循环
178
132
  this.#heartbeat_interval = d.heartbeat_interval;
179
- // 发送鉴权
180
133
  if (this.#ws) {
181
134
  this.#ws.send(JSON.stringify(this.#aut()));
182
135
  }
183
136
  },
184
137
  11: () => {
185
- // OpCode 11 Heartbeat ACK 消息,心跳发送成功
186
138
  console.info('[ws-qqbot] heartbeat transmission');
187
- // 重制次数
188
139
  this.#counter.reStart();
189
140
  },
190
141
  12: ({ d }) => {
191
142
  console.debug('[ws-qqbot] platform data', d);
192
143
  }
193
144
  };
194
- // 连接
195
145
  this.#ws = new WebSocket(this.#gatewayUrl);
196
146
  this.#ws.on('open', () => {
197
147
  console.info('[ws-qqbot] open');
198
148
  });
199
- // 监听消息
200
149
  this.#ws.on('message', msg => {
201
150
  const message = JSON.parse(msg.toString('utf8'));
202
151
  if (process.env.NTQQ_WS === 'dev') {
203
152
  console.info('message', message);
204
153
  }
205
- // 根据 opcode 进行处理
206
154
  if (map[message.op]) {
207
155
  map[message.op](message);
208
156
  }
209
157
  });
210
- // 关闭
211
158
  this.#ws.on('close', err => {
212
159
  void reconnect();
213
160
  console.info('[ws-qqbot] close', err);
@@ -0,0 +1 @@
1
+ export declare const config: Map<string, any>;
@@ -0,0 +1,3 @@
1
+ import { AxiosInstance } from 'axios';
2
+ import { type AxiosRequestConfig } from 'axios';
3
+ export declare const createAxiosInstance: (service: AxiosInstance, options: AxiosRequestConfig) => Promise<any>;
@@ -6,17 +6,14 @@ const filterHeaders = (headers = {}) => {
6
6
  const sensitiveKeys = [/^authorization$/i, /^cookie$/i, /^set-cookie$/i, /token/i, /key/i, /jwt/i, /^session[-_]id$/i, /^uid$/i, /^user[-_]id$/i];
7
7
  for (const key in headers) {
8
8
  if (/^_/.test(key)) {
9
- continue; // 跳过 _ 开头
9
+ continue;
10
10
  }
11
- // 去掉 Symbol 类型的 key
12
11
  if (typeof key === 'symbol') {
13
12
  continue;
14
13
  }
15
- // 去掉函数
16
14
  if (typeof headers[key] === 'function') {
17
15
  continue;
18
16
  }
19
- // 如果是敏感字段全部替换为 ******
20
17
  if (sensitiveKeys.some(re => re.test(key))) {
21
18
  filtered[key] = '******';
22
19
  }
@@ -33,13 +30,11 @@ const filterConfig = (config = {}) => {
33
30
  const filtered = {};
34
31
  for (const key in config) {
35
32
  if (/^_/.test(key)) {
36
- continue; // 跳过 _ 开头
33
+ continue;
37
34
  }
38
- // 去掉 Symbol 类型的 key
39
35
  if (typeof key === 'symbol') {
40
36
  continue;
41
37
  }
42
- // 去掉函数
43
38
  if (typeof config[key] === 'function') {
44
39
  continue;
45
40
  }
@@ -54,13 +49,11 @@ const filterRequest = (request = {}) => {
54
49
  const filtered = {};
55
50
  for (const key in request) {
56
51
  if (/^_/.test(key)) {
57
- continue; // 跳过 _ 开头
52
+ continue;
58
53
  }
59
- // 去掉 Symbol 类型的 key
60
54
  if (typeof key === 'symbol') {
61
55
  continue;
62
56
  }
63
- // 去掉函数
64
57
  if (typeof request[key] === 'function') {
65
58
  continue;
66
59
  }
@@ -68,9 +61,7 @@ const filterRequest = (request = {}) => {
68
61
  }
69
62
  return filtered;
70
63
  };
71
- // 处理axios错误
72
64
  const loggerError = err => {
73
- // 错误时的请求头
74
65
  logger.error('[axios] error', {
75
66
  config: {
76
67
  headers: filterHeaders(err?.config?.headers),
@@ -88,19 +79,12 @@ const loggerError = err => {
88
79
  message: err?.message
89
80
  });
90
81
  };
91
- /**
92
- * 基础请求
93
- * @param service
94
- * @param options
95
- * @returns
96
- */
97
82
  const createAxiosInstance = (service, options) => {
98
83
  return new Promise((resolve, reject) => {
99
84
  service(options)
100
85
  .then(res => resolve(res?.data ?? {}))
101
86
  .catch(err => {
102
87
  loggerError(err);
103
- // 丢出错误中携带的响应数据
104
88
  reject(err?.response?.data);
105
89
  });
106
90
  });
@@ -0,0 +1,3 @@
1
+ export declare const AvailableIntentsEventsEnum: readonly ["GUILDS", "GUILD_MEMBERS", "GUILD_MESSAGES", "GUILD_MESSAGE_REACTIONS", "DIRECT_MESSAGE", "INTERACTION", "MESSAGE_AUDIT", "FORUMS_EVENT", "AUDIO_ACTION", "PUBLIC_GUILD_MESSAGES", "GROUP_AND_C2C_EVENT"];
2
+ export type IntentsEnum = (typeof AvailableIntentsEventsEnum)[number];
3
+ export declare function getIntentsMask(intents: IntentsEnum[]): number;
@@ -1,94 +1,29 @@
1
- /**
2
- * GUILDS (1 << 0)
3
- - GUILD_CREATE // 当机器人加入新guild时
4
- - GUILD_UPDATE // 当guild资料发生变更时
5
- - GUILD_DELETE // 当机器人退出guild时
6
- - CHANNEL_CREATE // 当channel被创建时
7
- - CHANNEL_UPDATE // 当channel被更新时
8
- - CHANNEL_DELETE // 当channel被删除时
9
-
10
- GUILD_MEMBERS (1 << 1)
11
- - GUILD_MEMBER_ADD // 当成员加入时
12
- - GUILD_MEMBER_UPDATE // 当成员资料变更时
13
- - GUILD_MEMBER_REMOVE // 当成员被移除时
14
-
15
- GUILD_MESSAGES (1 << 9) // 消息事件,仅 *私域* 机器人能够设置此 intents。
16
- - MESSAGE_CREATE // 发送消息事件,代表频道内的全部消息,而不只是 at 机器人的消息。内容与 AT_MESSAGE_CREATE 相同
17
- - MESSAGE_DELETE // 删除(撤回)消息事件
18
-
19
- GUILD_MESSAGE_REACTIONS (1 << 10)
20
- - MESSAGE_REACTION_ADD // 为消息添加表情表态
21
- - MESSAGE_REACTION_REMOVE // 为消息删除表情表态
22
-
23
- DIRECT_MESSAGE (1 << 12)
24
- - DIRECT_MESSAGE_CREATE // 当收到用户发给机器人的私信消息时
25
- - DIRECT_MESSAGE_DELETE // 删除(撤回)消息事件
26
-
27
-
28
- GROUP_AND_C2C_EVENT (1 << 25)
29
- - C2C_MESSAGE_CREATE // 用户单聊发消息给机器人时候
30
- - FRIEND_ADD // 用户添加使用机器人
31
- - FRIEND_DEL // 用户删除机器人
32
- - C2C_MSG_REJECT // 用户在机器人资料卡手动关闭"主动消息"推送
33
- - C2C_MSG_RECEIVE // 用户在机器人资料卡手动开启"主动消息"推送开关
34
- - GROUP_AT_MESSAGE_CREATE // 用户在群里@机器人时收到的消息
35
- - GROUP_ADD_ROBOT // 机器人被添加到群聊
36
- - GROUP_DEL_ROBOT // 机器人被移出群聊
37
- - GROUP_MSG_REJECT // 群管理员主动在机器人资料页操作关闭通知
38
- - GROUP_MSG_RECEIVE // 群管理员主动在机器人资料页操作开启通知
39
-
40
- INTERACTION (1 << 26)
41
- - INTERACTION_CREATE // 互动事件创建时
42
-
43
- MESSAGE_AUDIT (1 << 27)
44
- - MESSAGE_AUDIT_PASS // 消息审核通过
45
- - MESSAGE_AUDIT_REJECT // 消息审核不通过
46
-
47
- FORUMS_EVENT (1 << 28) // 论坛事件,仅 *私域* 机器人能够设置此 intents。
48
- - FORUM_THREAD_CREATE // 当用户创建主题时
49
- - FORUM_THREAD_UPDATE // 当用户更新主题时
50
- - FORUM_THREAD_DELETE // 当用户删除主题时
51
- - FORUM_POST_CREATE // 当用户创建帖子时
52
- - FORUM_POST_DELETE // 当用户删除帖子时
53
- - FORUM_REPLY_CREATE // 当用户回复评论时
54
- - FORUM_REPLY_DELETE // 当用户回复评论时
55
- - FORUM_PUBLISH_AUDIT_RESULT // 当用户发表审核通过时
56
-
57
- AUDIO_ACTION (1 << 29)
58
- - AUDIO_START // 音频开始播放时
59
- - AUDIO_FINISH // 音频播放结束时
60
- - AUDIO_ON_MIC // 上麦时
61
- - AUDIO_OFF_MIC // 下麦时
62
-
63
- PUBLIC_GUILD_MESSAGES (1 << 30) // 消息事件,此为公域的消息事件
64
- - AT_MESSAGE_CREATE // 当收到@机器人的消息时
65
- - PUBLIC_MESSAGE_DELETE // 当频道的消息被删除时
66
- */
67
- /**
68
- * 订阅枚举
69
- */
70
- /**
71
- * 订阅事件集合
72
- */
1
+ const AvailableIntentsEventsEnum = [
2
+ 'GUILDS',
3
+ 'GUILD_MEMBERS',
4
+ 'GUILD_MESSAGES',
5
+ 'GUILD_MESSAGE_REACTIONS',
6
+ 'DIRECT_MESSAGE',
7
+ 'INTERACTION',
8
+ 'MESSAGE_AUDIT',
9
+ 'FORUMS_EVENT',
10
+ 'AUDIO_ACTION',
11
+ 'PUBLIC_GUILD_MESSAGES',
12
+ 'GROUP_AND_C2C_EVENT'
13
+ ];
73
14
  const intentsMap = {
74
- GUILDS: 1 << 0, // 频道事件
75
- GUILD_MEMBERS: 1 << 1, // 成员
76
- GUILD_MESSAGES: 1 << 9, // 消息事件,仅 *私域*
77
- GUILD_MESSAGE_REACTIONS: 1 << 10, // 消息表情表态
78
- DIRECT_MESSAGE: 1 << 12, // 私信消息
79
- INTERACTION: 1 << 26, // 互动事件
80
- // INTERACTION_CREATE: 1 << 26,
81
- MESSAGE_AUDIT: 1 << 27, // 消息审核
82
- FORUMS_EVENT: 1 << 28, // 论坛事件,仅 *私域*
83
- AUDIO_ACTION: 1 << 29, // 音频
84
- PUBLIC_GUILD_MESSAGES: 1 << 30, // 消息事件,此为公域的消息事件
85
- GROUP_AND_C2C_EVENT: 1 << 25 // group all
15
+ GUILDS: 1 << 0,
16
+ GUILD_MEMBERS: 1 << 1,
17
+ GUILD_MESSAGES: 1 << 9,
18
+ GUILD_MESSAGE_REACTIONS: 1 << 10,
19
+ DIRECT_MESSAGE: 1 << 12,
20
+ INTERACTION: 1 << 26,
21
+ MESSAGE_AUDIT: 1 << 27,
22
+ FORUMS_EVENT: 1 << 28,
23
+ AUDIO_ACTION: 1 << 29,
24
+ PUBLIC_GUILD_MESSAGES: 1 << 30,
25
+ GROUP_AND_C2C_EVENT: 1 << 25
86
26
  };
87
- /**
88
- *
89
- * @param intents
90
- * @returns
91
- */
92
27
  function getIntentsMask(intents) {
93
28
  let intentsMask = 0;
94
29
  for (const item of intents) {
@@ -100,4 +35,4 @@ function getIntentsMask(intents) {
100
35
  return intentsMask;
101
36
  }
102
37
 
103
- export { getIntentsMask };
38
+ export { AvailableIntentsEventsEnum, getIntentsMask };
@@ -0,0 +1,4 @@
1
+ import type { QQBotGroupEventMap } from './message.group';
2
+ import type { QQBotGuildEventMap } from './message.guild';
3
+ import { QQBotPublicEventMap } from './message.public';
4
+ export type QQBotEventMap = QQBotGroupEventMap & QQBotGuildEventMap & QQBotPublicEventMap;
@@ -0,0 +1,24 @@
1
+ import { C2C_MESSAGE_CREATE_TYPE } from '../message/group/C2C_MESSAGE_CREATE';
2
+ import { C2C_MSG_REJECT_TYPE } from '../message/group/C2C_MSG_REJECT';
3
+ import { C2C_MSG_RECEIVE_TYPE } from '../message/group/C2C_MSG_RECEIVE';
4
+ import { GROUP_ADD_ROBOT_TYPE } from '../message/group/GROUP_ADD_ROBOT';
5
+ import { GROUP_AT_MESSAGE_CREATE_TYPE } from '../message/group/GROUP_AT_MESSAGE_CREATE';
6
+ import { GROUP_DEL_ROBOT_TYPE } from '../message/group/GROUP_DEL_ROBOT';
7
+ import { GROUP_MSG_RECEIVE_TYPE } from '../message/group/GROUP_MSG_RECEIVE';
8
+ import { GROUP_MSG_REJECT_TYPE } from '../message/group/GROUP_MSG_REJECT';
9
+ import { FRIEND_ADD_TYPE } from '../message/group/FRIEND_ADD';
10
+ import { FRIEND_DEL_TYPE } from '../message/group/FRIEND_DEL';
11
+ import { ERROR_TYPE } from '../message/ERROR';
12
+ export type QQBotGroupEventMap = {
13
+ C2C_MESSAGE_CREATE: C2C_MESSAGE_CREATE_TYPE;
14
+ C2C_MSG_REJECT: C2C_MSG_REJECT_TYPE;
15
+ C2C_MSG_RECEIVE: C2C_MSG_RECEIVE_TYPE;
16
+ GROUP_ADD_ROBOT: GROUP_ADD_ROBOT_TYPE;
17
+ GROUP_AT_MESSAGE_CREATE: GROUP_AT_MESSAGE_CREATE_TYPE;
18
+ GROUP_DEL_ROBOT: GROUP_DEL_ROBOT_TYPE;
19
+ GROUP_MSG_RECEIVE: GROUP_MSG_RECEIVE_TYPE;
20
+ GROUP_MSG_REJECT: GROUP_MSG_REJECT_TYPE;
21
+ FRIEND_ADD: FRIEND_ADD_TYPE;
22
+ FRIEND_DEL: FRIEND_DEL_TYPE;
23
+ ERROR: ERROR_TYPE;
24
+ };
@@ -0,0 +1 @@
1
+
@@ -0,0 +1,38 @@
1
+ import { CHANNEL_CREATE_TYPE } from '../message/CHANNEL_CREATE';
2
+ import { CHANNEL_DELETE_TYPE } from '../message/CHANNEL_DELETE';
3
+ import { CHANNEL_UPDATE_TYPE } from '../message/CHANNEL_UPDATE';
4
+ import { DIRECT_MESSAGE_CREATE_TYPE } from '../message/DIRECT_MESSAGE_CREATE';
5
+ import { DIRECT_MESSAGE_DELETE_TYPE } from '../message/DIRECT_MESSAGE_DELETE';
6
+ import { GUILD_CREATE_TYPE } from '../message/GUILD_CREATE';
7
+ import { GUILD_DELETE_TYPE } from '../message/GUILD_DELETE';
8
+ import { GUILD_MEMBER_ADD_TYPE } from '../message/GUILD_MEMBER_ADD';
9
+ import { GUILD_MEMBER_REMOVE_TYPE } from '../message/GUILD_MEMBER_REMOVE';
10
+ import { GUILD_MEMBER_UPDATE_TYPE } from '../message/GUILD_MEMBER_UPDATE';
11
+ import { GUILD_UPDATE_TYPE } from '../message/GUILD_UPDATE';
12
+ import { MESSAGE_CREATE_TYPE } from '../message/MESSAGE_CREATE';
13
+ import { MESSAGE_DELETE_TYPE } from '../message/MESSAGE_DELETE';
14
+ import { MESSAGE_REACTION_ADD_TYPE } from '../message/MESSAGE_REACTION_ADD';
15
+ import { MESSAGE_REACTION_REMOVE_TYPE } from '../message/MESSAGE_REACTION_REMOVE';
16
+ import { AT_MESSAGE_CREATE_TYPE } from '../message/AT_MESSAGE_CREATE';
17
+ import { PUBLIC_MESSAGE_DELETE_TYPE } from '../message/PUBLIC_MESSAGE_DELETE';
18
+ import { READY_TYPE } from '../message/READY';
19
+ export type QQBotGuildEventMap = {
20
+ CHANNEL_CREATE: CHANNEL_CREATE_TYPE;
21
+ CHANNEL_DELETE: CHANNEL_DELETE_TYPE;
22
+ CHANNEL_UPDATE: CHANNEL_UPDATE_TYPE;
23
+ DIRECT_MESSAGE_CREATE: DIRECT_MESSAGE_CREATE_TYPE;
24
+ DIRECT_MESSAGE_DELETE: DIRECT_MESSAGE_DELETE_TYPE;
25
+ GUILD_CREATE: GUILD_CREATE_TYPE;
26
+ GUILD_DELETE: GUILD_DELETE_TYPE;
27
+ GUILD_MEMBER_ADD: GUILD_MEMBER_ADD_TYPE;
28
+ GUILD_MEMBER_REMOVE: GUILD_MEMBER_REMOVE_TYPE;
29
+ GUILD_MEMBER_UPDATE: GUILD_MEMBER_UPDATE_TYPE;
30
+ GUILD_UPDATE: GUILD_UPDATE_TYPE;
31
+ MESSAGE_CREATE: MESSAGE_CREATE_TYPE;
32
+ MESSAGE_DELETE: MESSAGE_DELETE_TYPE;
33
+ MESSAGE_REACTION_ADD: MESSAGE_REACTION_ADD_TYPE;
34
+ MESSAGE_REACTION_REMOVE: MESSAGE_REACTION_REMOVE_TYPE;
35
+ AT_MESSAGE_CREATE: AT_MESSAGE_CREATE_TYPE;
36
+ PUBLIC_MESSAGE_DELETE: PUBLIC_MESSAGE_DELETE_TYPE;
37
+ READY: READY_TYPE;
38
+ };
@@ -0,0 +1 @@
1
+
@@ -0,0 +1 @@
1
+
@@ -0,0 +1,6 @@
1
+ import { ERROR_TYPE } from '../message/ERROR';
2
+ import { INTERACTION_CREATE_TYPE } from '../message/INTERACTION_CREATE';
3
+ export type QQBotPublicEventMap = {
4
+ INTERACTION_CREATE: INTERACTION_CREATE_TYPE;
5
+ ERROR: ERROR_TYPE;
6
+ };