@alemonjs/qq-bot 2.1.0-alpha.2 → 2.1.0-alpha.21

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 (109) hide show
  1. package/README.md +7 -30
  2. package/lib/config.d.ts +8 -0
  3. package/lib/config.js +20 -0
  4. package/lib/desktop.d.ts +1 -3
  5. package/lib/desktop.js +3 -12
  6. package/lib/hook.d.ts +30 -9
  7. package/lib/hook.js +19 -17
  8. package/lib/index.d.ts +5 -6
  9. package/lib/index.js +37 -19
  10. package/lib/index.webhook.d.ts +1 -0
  11. package/lib/index.webhook.js +5 -4
  12. package/lib/index.websoket.d.ts +1 -0
  13. package/lib/index.websoket.js +41 -22
  14. package/lib/message/AT_MESSAGE_CREATE.d.ts +35 -0
  15. package/lib/message/AT_MESSAGE_CREATE.js +1 -0
  16. package/lib/message/CHANNEL_CREATE.d.ts +15 -0
  17. package/lib/message/CHANNEL_CREATE.js +1 -0
  18. package/lib/message/CHANNEL_DELETE.d.ts +15 -0
  19. package/lib/message/CHANNEL_DELETE.js +1 -0
  20. package/lib/message/CHANNEL_UPDATE.d.ts +15 -0
  21. package/lib/message/CHANNEL_UPDATE.js +1 -0
  22. package/lib/message/DIRECT_MESSAGE_CREATE.d.ts +29 -0
  23. package/lib/message/DIRECT_MESSAGE_CREATE.js +1 -0
  24. package/lib/message/DIRECT_MESSAGE_DELETE.d.ts +17 -0
  25. package/lib/message/DIRECT_MESSAGE_DELETE.js +1 -0
  26. package/lib/message/ERROR.d.ts +1 -0
  27. package/lib/message/ERROR.js +1 -0
  28. package/lib/message/GUILD_CREATE.d.ts +15 -0
  29. package/lib/message/GUILD_CREATE.js +1 -0
  30. package/lib/message/GUILD_DELETE.d.ts +15 -0
  31. package/lib/message/GUILD_DELETE.js +1 -0
  32. package/lib/message/GUILD_MEMBER_ADD.d.ts +14 -0
  33. package/lib/message/GUILD_MEMBER_ADD.js +1 -0
  34. package/lib/message/GUILD_MEMBER_REMOVE.d.ts +14 -0
  35. package/lib/message/GUILD_MEMBER_REMOVE.js +1 -0
  36. package/lib/message/GUILD_MEMBER_UPDATE.d.ts +14 -0
  37. package/lib/message/GUILD_MEMBER_UPDATE.js +1 -0
  38. package/lib/message/GUILD_UPDATE.d.ts +15 -0
  39. package/lib/message/GUILD_UPDATE.js +1 -0
  40. package/lib/message/INTERACTION_CREATE.d.ts +53 -0
  41. package/lib/message/INTERACTION_CREATE.js +1 -0
  42. package/lib/message/MESSAGE_CREATE.d.ts +1 -0
  43. package/lib/message/MESSAGE_CREATE.js +1 -0
  44. package/lib/message/MESSAGE_DELETE.d.ts +1 -0
  45. package/lib/message/MESSAGE_DELETE.js +1 -0
  46. package/lib/message/MESSAGE_REACTION_ADD.d.ts +13 -0
  47. package/lib/message/MESSAGE_REACTION_ADD.js +1 -0
  48. package/lib/message/MESSAGE_REACTION_REMOVE.d.ts +13 -0
  49. package/lib/message/MESSAGE_REACTION_REMOVE.js +1 -0
  50. package/lib/message/PUBLIC_MESSAGE_DELETE.d.ts +15 -0
  51. package/lib/message/PUBLIC_MESSAGE_DELETE.js +1 -0
  52. package/lib/message/READY.d.ts +6 -0
  53. package/lib/message/READY.js +1 -0
  54. package/lib/message/group/C2C_MESSAGE_CREATE.d.ts +9 -0
  55. package/lib/message/group/C2C_MESSAGE_CREATE.js +1 -0
  56. package/lib/message/group/C2C_MSG_RECEIVE.d.ts +4 -0
  57. package/lib/message/group/C2C_MSG_RECEIVE.js +1 -0
  58. package/lib/message/group/C2C_MSG_REJECT.d.ts +4 -0
  59. package/lib/message/group/C2C_MSG_REJECT.js +1 -0
  60. package/lib/message/group/FRIEND_ADD.d.ts +4 -0
  61. package/lib/message/group/FRIEND_ADD.js +1 -0
  62. package/lib/message/group/FRIEND_DEL.d.ts +4 -0
  63. package/lib/message/group/FRIEND_DEL.js +1 -0
  64. package/lib/message/group/GROUP_ADD_ROBOT.d.ts +5 -0
  65. package/lib/message/group/GROUP_ADD_ROBOT.js +1 -0
  66. package/lib/message/group/GROUP_AT_MESSAGE_CREATE.d.ts +11 -0
  67. package/lib/message/group/GROUP_AT_MESSAGE_CREATE.js +1 -0
  68. package/lib/message/group/GROUP_DEL_ROBOT.d.ts +5 -0
  69. package/lib/message/group/GROUP_DEL_ROBOT.js +1 -0
  70. package/lib/message/group/GROUP_MSG_RECEIVE.d.ts +5 -0
  71. package/lib/message/group/GROUP_MSG_RECEIVE.js +1 -0
  72. package/lib/message/group/GROUP_MSG_REJECT.d.ts +5 -0
  73. package/lib/message/group/GROUP_MSG_REJECT.js +1 -0
  74. package/lib/register.d.ts +2 -3
  75. package/lib/register.js +270 -176
  76. package/lib/sdk/api.d.ts +196 -969
  77. package/lib/sdk/api.js +267 -916
  78. package/lib/sdk/client.webhook.d.ts +9 -0
  79. package/lib/sdk/{client.js → client.webhook.js} +19 -53
  80. package/lib/sdk/client.websoket.d.ts +9 -0
  81. package/lib/sdk/client.websoket.js +43 -96
  82. package/lib/sdk/config.d.ts +1 -0
  83. package/lib/sdk/instance.d.ts +3 -0
  84. package/lib/sdk/instance.js +93 -0
  85. package/lib/sdk/intents.d.ts +3 -0
  86. package/lib/sdk/intents.js +25 -90
  87. package/lib/sdk/message.d.ts +4 -0
  88. package/lib/sdk/message.group.d.ts +24 -0
  89. package/lib/sdk/message.group.js +1 -0
  90. package/lib/sdk/message.guild.d.ts +38 -0
  91. package/lib/sdk/message.guild.js +1 -0
  92. package/lib/sdk/message.js +1 -0
  93. package/lib/sdk/message.public.d.ts +6 -0
  94. package/lib/sdk/message.public.js +1 -0
  95. package/lib/sdk/typing.d.ts +67 -59
  96. package/lib/sdk/typing.js +1 -0
  97. package/lib/sdk/webhook.secret.d.ts +14 -0
  98. package/lib/sdk/webhook.secret.js +6 -21
  99. package/lib/sends.d.ts +29 -0
  100. package/lib/sends.js +546 -477
  101. package/lib/utils.d.ts +1 -0
  102. package/lib/utils.js +7 -12
  103. package/package.json +9 -5
  104. package/lib/index.group.js +0 -19
  105. package/lib/index.guild.js +0 -36
  106. package/lib/sdk/client.websoket.group.js +0 -221
  107. package/lib/sdk/client.websoket.guild.js +0 -205
  108. package/lib/sdk/counter.js +0 -19
  109. package/lib/sdk/from.js +0 -44
@@ -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,37 +26,28 @@ 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');
46
- if (!app_id)
32
+ if (!app_id) {
47
33
  return;
34
+ }
48
35
  const secret = config.get('secret');
49
- if (!secret)
36
+ if (!secret) {
50
37
  return;
51
- // 发送请求
38
+ }
52
39
  const data = await this.getAuthentication(app_id, secret).then(res => res.data);
53
40
  config.set('access_token', data.access_token);
54
41
  console.info('refresh', data.expires_in, 's');
55
- setTimeout(callBack, data.expires_in * 1000);
42
+ setTimeout(() => void callBack(), data.expires_in * 1000);
56
43
  };
57
44
  await callBack();
58
45
  }
59
- /**
60
- *
61
- * @param cfg
62
- * @param conversation
63
- */
64
46
  connect() {
65
47
  try {
66
48
  const ws = config.get('ws');
67
49
  if (!ws) {
68
- this.#setTimeoutBotConfig();
50
+ void this.#setTimeoutBotConfig();
69
51
  this.#app = new Koa();
70
52
  this.#app.use(bodyParser());
71
53
  const router = new Router();
@@ -85,8 +67,7 @@ class QQBotClient extends QQBotAPI {
85
67
  ctx.req.on('end', () => (ctx.request.rawBody = rawData));
86
68
  await next();
87
69
  });
88
- // 启动服务
89
- router.post(route, async (ctx) => {
70
+ router.post(route, ctx => {
90
71
  const sign = ctx.req.headers['x-signature-ed25519'];
91
72
  const timestamp = ctx.req.headers['x-signature-timestamp'];
92
73
  const rawBody = ctx.request.rawBody;
@@ -97,27 +78,24 @@ class QQBotClient extends QQBotAPI {
97
78
  return;
98
79
  }
99
80
  const body = ctx.request.body;
100
- if (body.op == 13) {
81
+ if (+body.op === 13) {
101
82
  ctx.status = 200;
102
83
  ctx.body = {
103
- // 返回明文 token
104
84
  plain_token: body.d.plain_token,
105
- // 生成签名
106
85
  signature: ntqqWebhook.getSign(body.d.event_ts, body.d.plain_token)
107
86
  };
108
87
  }
109
- else if (body.op == 0) {
88
+ else if (+body.op === 0) {
110
89
  ctx.status = 204;
111
- // 根据事件类型,处理事件
112
90
  for (const event of this.#events[body.t] || []) {
113
91
  event(body.d);
114
92
  }
115
- const access_token = config.get('access_token');
116
- // 也可以分法到客户端。 发送失败需要处理 或清理调
93
+ const accessToken = config.get('access_token');
117
94
  for (const client of this.#client) {
118
95
  try {
119
- if (access_token)
120
- body['access_token'] = access_token;
96
+ if (accessToken) {
97
+ body['access_token'] = accessToken;
98
+ }
121
99
  client.ws.send(JSON.stringify(body));
122
100
  }
123
101
  catch (e) {
@@ -128,22 +106,17 @@ class QQBotClient extends QQBotAPI {
128
106
  });
129
107
  this.#app.use(router.routes());
130
108
  this.#app.use(router.allowedMethods());
131
- // 启动服务
132
109
  const server = this.#app.listen(cfg.port, () => {
133
110
  console.log('Server running at http://localhost:' + cfg.port + route);
134
111
  });
135
- // 创建 WebSocketServer 并监听同一个端口
136
112
  const wss = new WebSocketServer({ server: server });
137
113
  console.log('Server running at ws://localhost:' + cfg.port + '/');
138
- // 处理客户端连接
139
114
  wss.on('connection', ws => {
140
115
  const clientId = v4();
141
116
  ws['clientId'] = clientId;
142
117
  console.log(clientId, 'connection');
143
118
  this.#client.push({ id: clientId, ws });
144
- // 处理消息事件
145
119
  ws.on('message', (message) => {
146
- // 拿到消息
147
120
  try {
148
121
  const body = JSON.parse(message.toString());
149
122
  for (const event of this.#events[body.t] || []) {
@@ -154,7 +127,6 @@ class QQBotClient extends QQBotAPI {
154
127
  this.#error(e);
155
128
  }
156
129
  });
157
- // 处理关闭事件
158
130
  ws.on('close', () => {
159
131
  console.log(`${clientId} disconnected`);
160
132
  this.#client = this.#client.filter(client => client.id !== clientId);
@@ -163,7 +135,6 @@ class QQBotClient extends QQBotAPI {
163
135
  }
164
136
  else {
165
137
  const reConnect = () => {
166
- // 使用了ws服务器
167
138
  this.#ws = new WebSocket(ws);
168
139
  this.#ws.on('open', () => {
169
140
  this.#count = 0;
@@ -171,11 +142,11 @@ class QQBotClient extends QQBotAPI {
171
142
  });
172
143
  this.#ws.on('message', data => {
173
144
  try {
174
- // 拿到消息
175
145
  const body = JSON.parse(data.toString());
176
- const access_token = body['access_token'];
177
- if (access_token)
178
- config.set('access_token', access_token);
146
+ const accessToken = body['access_token'];
147
+ if (accessToken) {
148
+ config.set('access_token', accessToken);
149
+ }
179
150
  for (const event of this.#events[body.t] || []) {
180
151
  event(body.d);
181
152
  }
@@ -186,10 +157,9 @@ class QQBotClient extends QQBotAPI {
186
157
  });
187
158
  this.#ws.on('close', () => {
188
159
  console.log('ws closed');
189
- // 重连5次,超过5次不再重连
190
- if (this.#count > 5)
160
+ if (this.#count > 5) {
191
161
  return;
192
- // 1.3s 后重连
162
+ }
193
163
  setTimeout(() => {
194
164
  reConnect();
195
165
  }, 1300);
@@ -205,10 +175,6 @@ class QQBotClient extends QQBotAPI {
205
175
  this.#error(e);
206
176
  }
207
177
  }
208
- /**
209
- *
210
- * @param error
211
- */
212
178
  #error(error) {
213
179
  if (this.#events['ERROR']) {
214
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
+ }
@@ -2,62 +2,40 @@ import WebSocket from 'ws';
2
2
  import { QQBotAPI } from './api.js';
3
3
  import { config } from './config.js';
4
4
  import { getIntentsMask } from './intents.js';
5
- import { Counter } from './counter.js';
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');
39
22
  const secret = config.get('secret');
40
- if (!app_id || !secret)
23
+ if (!app_id || !secret) {
41
24
  return;
42
- // 发送请求
25
+ }
43
26
  const data = await this.getAuthentication(app_id, secret).then(res => res.data);
44
27
  config.set('access_token', data.access_token);
45
28
  console.info('refresh', data.expires_in, 's');
46
- setTimeout(accessToken, data.expires_in * 1000);
29
+ setTimeout(() => void accessToken(), data.expires_in * 1000);
47
30
  };
48
31
  await accessToken();
49
- return;
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,145 +50,114 @@ 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
- if (!this.#events[key])
54
+ if (!this.#events[key]) {
82
55
  this.#events[key] = [];
56
+ }
83
57
  this.#events[key].push(val);
84
58
  return this;
85
59
  }
86
- /**
87
- *
88
- * @param cfg
89
- * @param conversation
90
- */
91
60
  async connect(gatewayURL) {
92
- // 定时模式
93
61
  await this.#setTimeoutBotConfig();
94
- // 请求url
95
62
  if (!this.#gatewayUrl) {
96
63
  this.#gatewayUrl = gatewayURL ?? (await this.gateway().then(res => res?.url));
97
64
  }
98
- if (!this.#gatewayUrl)
65
+ if (!this.#gatewayUrl) {
99
66
  return;
100
- // 重新连接的逻辑
101
- const reconnect = async () => {
102
- if (this.#counter.get() >= 5) {
67
+ }
68
+ const reconnect = () => {
69
+ if (this.#counter.value >= 5) {
103
70
  console.info('The maximum number of reconnections has been reached, cancel reconnection');
104
71
  return;
105
72
  }
106
73
  setTimeout(() => {
107
- console.info('[ws] reconnecting...');
108
- // 重新starrt
74
+ console.info('[ws-qqbot] reconnecting...');
109
75
  start();
110
- // 记录
111
- this.#counter.getNextId();
76
+ this.#counter.next();
112
77
  }, 5000);
113
78
  };
114
79
  const start = () => {
115
80
  if (this.#gatewayUrl) {
116
81
  const map = {
117
- 0: async ({ t, d }) => {
82
+ 0: ({ t, d }) => {
118
83
  if (this.#events[t]) {
119
84
  try {
120
85
  for (const event of this.#events[t]) {
121
- // 是否是函数
122
- if (typeof event != 'function')
86
+ if (typeof event !== 'function') {
123
87
  continue;
88
+ }
124
89
  event(d);
125
90
  }
126
91
  }
127
92
  catch (err) {
128
93
  if (this.#events['ERROR']) {
129
94
  for (const event of this.#events['ERROR']) {
130
- // 是否是函数
131
- if (typeof event != 'function')
95
+ if (typeof event !== 'function') {
132
96
  continue;
97
+ }
133
98
  event(err);
134
99
  }
135
100
  }
136
101
  }
137
102
  }
138
- // Ready Event,鉴权成功
139
103
  if (t === 'READY') {
140
104
  this.#IntervalId = setInterval(() => {
141
- if (this.#isConnected) {
142
- this.#ws &&
143
- this.#ws.send(JSON.stringify({
144
- op: 1, // op = 1
145
- d: null // 如果是第一次连接,传null
146
- }));
105
+ if (this.#isConnected && this.#ws) {
106
+ this.#ws.send(JSON.stringify({
107
+ op: 1,
108
+ d: null
109
+ }));
147
110
  }
148
111
  }, this.#heartbeat_interval);
149
112
  }
150
- // Resumed Event,恢复连接成功
151
113
  if (t === 'RESUMED') {
152
- console.info('[ws] restore connection');
153
- // 重制次数
114
+ console.info('[ws-qqbot] restore connection');
154
115
  this.#counter.reStart();
155
116
  }
156
- return;
157
117
  },
158
118
  6: ({ d }) => {
159
- console.info('[ws] connection attempt', d);
160
- return;
119
+ console.info('[ws-qqbot] connection attempt', d);
161
120
  },
162
- 7: async ({ d }) => {
163
- // 执行重新连接
164
- console.info('[ws] reconnect', d);
165
- // 取消鉴权发送
166
- if (this.#IntervalId)
121
+ 7: ({ d }) => {
122
+ console.info('[ws-qqbot] reconnect', d);
123
+ if (this.#IntervalId) {
167
124
  clearInterval(this.#IntervalId);
168
- return;
125
+ }
169
126
  },
170
127
  9: ({ d }) => {
171
- console.info('[ws] parameter error', d);
172
- return;
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
- this.#ws && this.#ws.send(JSON.stringify(this.#aut()));
181
- return;
133
+ if (this.#ws) {
134
+ this.#ws.send(JSON.stringify(this.#aut()));
135
+ }
182
136
  },
183
137
  11: () => {
184
- // OpCode 11 Heartbeat ACK 消息,心跳发送成功
185
- console.info('[ws] heartbeat transmission');
186
- // 重制次数
138
+ console.info('[ws-qqbot] heartbeat transmission');
187
139
  this.#counter.reStart();
188
- return;
189
140
  },
190
141
  12: ({ d }) => {
191
- console.info('[ws] platform data', d);
192
- return;
142
+ console.debug('[ws-qqbot] platform data', d);
193
143
  }
194
144
  };
195
- // 连接
196
145
  this.#ws = new WebSocket(this.#gatewayUrl);
197
146
  this.#ws.on('open', () => {
198
- console.info('[ws] open');
147
+ console.info('[ws-qqbot] open');
199
148
  });
200
- // 监听消息
201
- this.#ws.on('message', async (msg) => {
149
+ this.#ws.on('message', msg => {
202
150
  const message = JSON.parse(msg.toString('utf8'));
203
- if (process.env.NTQQ_WS == 'dev')
151
+ if (process.env.NTQQ_WS === 'dev') {
204
152
  console.info('message', message);
205
- // 根据 opcode 进行处理
153
+ }
206
154
  if (map[message.op]) {
207
155
  map[message.op](message);
208
156
  }
209
157
  });
210
- // 关闭
211
- this.#ws.on('close', async (err) => {
212
- await reconnect();
213
- console.info('[ws] close', err);
158
+ this.#ws.on('close', err => {
159
+ void reconnect();
160
+ console.info('[ws-qqbot] close', err);
214
161
  });
215
162
  }
216
163
  };
@@ -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>;
@@ -0,0 +1,93 @@
1
+ const filterHeaders = (headers = {}) => {
2
+ if (!headers) {
3
+ return headers;
4
+ }
5
+ const filtered = {};
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
+ for (const key in headers) {
8
+ if (/^_/.test(key)) {
9
+ continue;
10
+ }
11
+ if (typeof key === 'symbol') {
12
+ continue;
13
+ }
14
+ if (typeof headers[key] === 'function') {
15
+ continue;
16
+ }
17
+ if (sensitiveKeys.some(re => re.test(key))) {
18
+ filtered[key] = '******';
19
+ }
20
+ else {
21
+ filtered[key] = headers[key];
22
+ }
23
+ }
24
+ return filtered;
25
+ };
26
+ const filterConfig = (config = {}) => {
27
+ if (!config) {
28
+ return config;
29
+ }
30
+ const filtered = {};
31
+ for (const key in config) {
32
+ if (/^_/.test(key)) {
33
+ continue;
34
+ }
35
+ if (typeof key === 'symbol') {
36
+ continue;
37
+ }
38
+ if (typeof config[key] === 'function') {
39
+ continue;
40
+ }
41
+ filtered[key] = config[key];
42
+ }
43
+ return filtered;
44
+ };
45
+ const filterRequest = (request = {}) => {
46
+ if (!request) {
47
+ return request;
48
+ }
49
+ const filtered = {};
50
+ for (const key in request) {
51
+ if (/^_/.test(key)) {
52
+ continue;
53
+ }
54
+ if (typeof key === 'symbol') {
55
+ continue;
56
+ }
57
+ if (typeof request[key] === 'function') {
58
+ continue;
59
+ }
60
+ filtered[key] = request[key];
61
+ }
62
+ return filtered;
63
+ };
64
+ const loggerError = err => {
65
+ logger.error('[axios] error', {
66
+ config: {
67
+ headers: filterHeaders(err?.config?.headers),
68
+ params: err?.config?.params,
69
+ data: err?.config?.data
70
+ },
71
+ response: {
72
+ status: err?.response?.status,
73
+ statusText: err?.response?.statusText,
74
+ headers: filterHeaders(err?.response?.headers),
75
+ config: filterConfig(err?.response?.config),
76
+ request: filterRequest(err?.response?.request),
77
+ data: err?.response?.data
78
+ },
79
+ message: err?.message
80
+ });
81
+ };
82
+ const createAxiosInstance = (service, options) => {
83
+ return new Promise((resolve, reject) => {
84
+ service(options)
85
+ .then(res => resolve(res?.data ?? {}))
86
+ .catch(err => {
87
+ loggerError(err);
88
+ reject(err?.response?.data);
89
+ });
90
+ });
91
+ };
92
+
93
+ export { createAxiosInstance };
@@ -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;