woodenfish-bot 4.7.4 → 5.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.
package/es/index.js CHANGED
@@ -5,21 +5,14 @@ import _defineProperty from '@babel/runtime/helpers/defineProperty';
5
5
  import _regeneratorRuntime from '@babel/runtime/regenerator';
6
6
  import resty from 'resty-client';
7
7
  import _typeof from '@babel/runtime/helpers/typeof';
8
- import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
9
- import fs from 'fs';
10
- import https from 'https';
8
+ import https from 'node:https';
11
9
  import _possibleConstructorReturn from '@babel/runtime/helpers/possibleConstructorReturn';
12
10
  import _getPrototypeOf from '@babel/runtime/helpers/getPrototypeOf';
13
11
  import _inherits from '@babel/runtime/helpers/inherits';
14
12
  import WebSocket from 'ws';
15
13
  import { EventEmitter } from 'node:events';
16
14
 
17
- var versionMapping = Object.create(null);
18
- function register(version, api) {
19
- versionMapping[version] = api;
20
- }
21
-
22
- var apiMap = {
15
+ var apiMap$1 = {
23
16
  guildURI: '/guilds/:guildID',
24
17
  guildMembersURI: '/guilds/:guildID/members',
25
18
  guildMemberURI: '/guilds/:guildID/members/:userID',
@@ -63,40 +56,10 @@ var apiMap = {
63
56
  // 获取身份组成员列表
64
57
  guildVoiceMembersURI: '/channels/:channelID/voice/members',
65
58
  // 语音子频道在线成员车查询
66
- botMic: '/channels/:channelID/mic',
67
- // 机器人上麦|下麦
68
- groupMessagesURI: '/v2/groups/:groupOpenid/messages',
69
- // 群组消息
70
- groupRichMediaURI: '/v2/groups/:groupOpenid/files',
71
- // 群组富媒体消息
72
- groupMessageURI: '/v2/groups/:groupOpenid/messages/:messageID',
73
- // 群组撤回消息
74
- groupInfoURI: '/v2/groups/:groupOpenid/info',
75
- // 群基本信息
76
- groupBotStateURI: '/v2/groups/:groupOpenid/bot_state',
77
- // 机器人群内状态
78
- groupJoinRequestListURI: '/v2/groups/:groupOpenid/join_request_list',
79
- // 入群申请列表
80
- groupJoinRequestApprovalURI: '/v2/groups/:groupOpenid/approval_join_request/:memberOpenid',
81
- // 入群申请审批
82
- groupRestrictChatSettingURI: '/v2/groups/:groupOpenid/restrict_chat_setting',
83
- // 群禁言状态及成员禁言
84
- groupJoinApprovalStrategiesURI: '/v2/groups/join_approval_strategy',
85
- // 入群自动审批策略列表及创建
86
- groupJoinApprovalStrategyURI: '/v2/groups/join_approval_strategy/:strategyID',
87
- // 入群自动审批策略
88
- groupJoinApprovalStrategyExecuteURI: '/v2/groups/join_approval_strategy/:strategyID/execute',
89
- // 执行入群自动审批策略
90
- groupJoinApprovalStrategyWhitelistURI: '/v2/groups/join_approval_strategy/:strategyID/whitelist_users',
91
- // 入群自动审批白名单
92
- c2cMessagesURI: '/v2/users/:userID/messages',
93
- // C2C消息
94
- c2cRichMediaURI: '/v2/users/:userID/files',
95
- // C2C富媒体消息
96
- c2cMessageURI: '/v2/users/:userID/messages/:messageID' // C2C撤回消息
59
+ botMic: '/channels/:channelID/mic' // 机器人上麦|下麦
97
60
  };
98
- var getURL = function getURL(endpoint) {
99
- return apiMap[endpoint];
61
+ var getURL$1 = function getURL(endpoint) {
62
+ return apiMap$1[endpoint];
100
63
  };
101
64
 
102
65
  var PinsMessage = /*#__PURE__*/function () {
@@ -114,7 +77,7 @@ var PinsMessage = /*#__PURE__*/function () {
114
77
  value: function pinsMessage(channelID) {
115
78
  var options = {
116
79
  method: 'GET',
117
- url: getURL('pinsMessageURI'),
80
+ url: getURL$1('pinsMessageURI'),
118
81
  rest: {
119
82
  channelID: channelID
120
83
  }
@@ -128,7 +91,7 @@ var PinsMessage = /*#__PURE__*/function () {
128
91
  value: function putPinsMessage(channelID, messageID) {
129
92
  var options = {
130
93
  method: 'PUT',
131
- url: getURL('pinsMessageIdURI'),
94
+ url: getURL$1('pinsMessageIdURI'),
132
95
  headers: {
133
96
  'Content-Type': 'application/json;'
134
97
  },
@@ -146,7 +109,7 @@ var PinsMessage = /*#__PURE__*/function () {
146
109
  value: function deletePinsMessage(channelID, messageID) {
147
110
  var options = {
148
111
  method: 'DELETE',
149
- url: getURL('pinsMessageIdURI'),
112
+ url: getURL$1('pinsMessageIdURI'),
150
113
  rest: {
151
114
  channelID: channelID,
152
115
  messageID: messageID
@@ -172,7 +135,7 @@ var Reaction = /*#__PURE__*/function () {
172
135
  value: function postReaction(channelId, reactionToCreate) {
173
136
  var options = {
174
137
  method: 'PUT',
175
- url: getURL('reactionURI'),
138
+ url: getURL$1('reactionURI'),
176
139
  rest: {
177
140
  channelID: channelId,
178
141
  messageID: reactionToCreate === null || reactionToCreate === void 0 ? void 0 : reactionToCreate.message_id,
@@ -189,7 +152,7 @@ var Reaction = /*#__PURE__*/function () {
189
152
  value: function deleteReaction(channelId, reactionToDelete) {
190
153
  var options = {
191
154
  method: 'DELETE',
192
- url: getURL('reactionURI'),
155
+ url: getURL$1('reactionURI'),
193
156
  rest: {
194
157
  channelID: channelId,
195
158
  messageID: reactionToDelete === null || reactionToDelete === void 0 ? void 0 : reactionToDelete.message_id,
@@ -209,7 +172,7 @@ var Reaction = /*#__PURE__*/function () {
209
172
  }
210
173
  var reqOptions = {
211
174
  method: 'GET',
212
- url: getURL('reactionURI'),
175
+ url: getURL$1('reactionURI'),
213
176
  rest: {
214
177
  channelID: channelId,
215
178
  messageID: reactionToCreate === null || reactionToCreate === void 0 ? void 0 : reactionToCreate.message_id,
@@ -238,7 +201,7 @@ var Guild = /*#__PURE__*/function () {
238
201
  value: function guild(guildID) {
239
202
  var options = {
240
203
  method: 'GET',
241
- url: getURL('guildURI'),
204
+ url: getURL$1('guildURI'),
242
205
  rest: {
243
206
  guildID: guildID
244
207
  }
@@ -252,7 +215,7 @@ var Guild = /*#__PURE__*/function () {
252
215
  value: function guildMember(guildID, userID) {
253
216
  var options = {
254
217
  method: 'GET',
255
- url: getURL('guildMemberURI'),
218
+ url: getURL$1('guildMemberURI'),
256
219
  rest: {
257
220
  guildID: guildID,
258
221
  userID: userID
@@ -271,7 +234,7 @@ var Guild = /*#__PURE__*/function () {
271
234
  };
272
235
  var options = {
273
236
  method: 'GET',
274
- url: getURL('guildMembersURI'),
237
+ url: getURL$1('guildMembersURI'),
275
238
  rest: {
276
239
  guildID: guildID
277
240
  },
@@ -293,7 +256,7 @@ var Guild = /*#__PURE__*/function () {
293
256
  }
294
257
  var options = {
295
258
  method: 'DELETE',
296
- url: getURL('guildMemberURI'),
259
+ url: getURL$1('guildMemberURI'),
297
260
  rest: {
298
261
  guildID: guildID,
299
262
  userID: userID
@@ -309,7 +272,7 @@ var Guild = /*#__PURE__*/function () {
309
272
  value: function guildVoiceMembers(channelID) {
310
273
  var options = {
311
274
  method: 'GET',
312
- url: getURL('guildVoiceMembersURI'),
275
+ url: getURL$1('guildVoiceMembersURI'),
313
276
  rest: {
314
277
  channelID: channelID
315
278
  }
@@ -319,7 +282,7 @@ var Guild = /*#__PURE__*/function () {
319
282
  }]);
320
283
  }();
321
284
 
322
- var version = "4.7.4";
285
+ var version = "5.0.0";
323
286
 
324
287
  function getDefaultExportFromCjs (x) {
325
288
  return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
@@ -699,45 +662,6 @@ log.setLevel('info');
699
662
  log.setLevel('trace');
700
663
  var BotLogger = log;
701
664
 
702
- function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: true } : { done: false, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = true, u = false; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = true, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
703
- function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
704
- function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
705
-
706
- // 全局token刷新锁,避免并发刷新
707
- var tokenRefreshPromises = new Map();
708
-
709
- // 定期清理可能遗留的Promise(防止内存泄漏)
710
- setInterval(function () {
711
- var now = Date.now();
712
- var keysToDelete = [];
713
- var _iterator = _createForOfIteratorHelper(tokenRefreshPromises.entries()),
714
- _step;
715
- try {
716
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
717
- var _step$value = _slicedToArray(_step.value, 2),
718
- key = _step$value[0],
719
- _step$value$ = _step$value[1],
720
- promise = _step$value$.promise,
721
- timestamp = _step$value$.timestamp;
722
- // 如果Promise已经存在超过5分钟,可能出现了问题,清理掉
723
- if (now - timestamp > 5 * 60 * 1000) {
724
- keysToDelete.push(key);
725
- console.warn("\u6E05\u7406\u8D85\u65F6\u7684token\u5237\u65B0Promise (key: ".concat(key, ", \u5B58\u5728\u65F6\u95F4: ").concat((now - timestamp) / 1000, "s)"));
726
- }
727
- }
728
- } catch (err) {
729
- _iterator.e(err);
730
- } finally {
731
- _iterator.f();
732
- }
733
- keysToDelete.forEach(function (key) {
734
- return tokenRefreshPromises["delete"](key);
735
- });
736
- if (keysToDelete.length > 0) {
737
- console.log("\u6E05\u7406\u4E86 ".concat(keysToDelete.length, " \u4E2A\u8D85\u65F6\u7684token\u5237\u65B0Promise"));
738
- }
739
- }, 60000); // 每分钟清理一次
740
-
741
665
  // 转为对象
742
666
  var toObject = function toObject(data) {
743
667
  if (Buffer.isBuffer(data)) return JSON.parse(data.toString());
@@ -753,255 +677,15 @@ var getTimeStampNumber = function getTimeStampNumber() {
753
677
  };
754
678
 
755
679
  // 添加 User-Agent
756
- var addUserAgent = function addUserAgent(header, appID, apiVersion) {
757
- var sdkVersion = version;
758
- header['User-Agent'] = "BotNodeSDK/v".concat(sdkVersion);
759
- if (apiVersion == 'v2') {
760
- header['X-Union-Appid'] = "".concat(appID);
680
+ var addUserAgent = function addUserAgent(header) {
681
+ header['User-Agent'] = "BotNodeSDK/v".concat(version);
682
+ };
683
+ var addV1Authorization = function addV1Authorization(header, appID, token) {
684
+ if (!token) {
685
+ throw new Error('QQ OpenAPI v1 需要配置 token');
761
686
  }
687
+ header['Authorization'] = "Bot ".concat(appID, ".").concat(token);
762
688
  };
763
- function getAccessToken(access_token_file, url, data, appID) {
764
- var now_time = getTimeStampNumber();
765
- var requestData = JSON.stringify(data);
766
- var options = {
767
- method: 'POST',
768
- headers: {
769
- 'Content-Type': 'application/json',
770
- 'Content-Length': requestData.length
771
- }
772
- };
773
- return new Promise(function (resolve, reject) {
774
- var req = https.request(url, options, function (res) {
775
- var responseData = '';
776
- res.on('data', function (chunk) {
777
- responseData += chunk;
778
- });
779
- res.on('end', function () {
780
- if (res.statusCode >= 200 && res.statusCode <= 299) {
781
- try {
782
- var parsedData = JSON.parse(responseData);
783
- console.log('response_access_token', JSON.stringify(parsedData));
784
- var access_token = parsedData.access_token;
785
- var expires_in = now_time + parseInt(parsedData.expires_in);
786
- var access_token_json = JSON.parse(fs.readFileSync(access_token_file).toString());
787
- // 确保appID在token['bot']中存在
788
- if (!access_token_json['bot']) {
789
- access_token_json['bot'] = {};
790
- }
791
- if (!access_token_json['bot'][appID]) {
792
- access_token_json['bot'][appID] = {};
793
- }
794
- // 修改access_token字段的值
795
- access_token_json['bot'][appID]['access_token'] = access_token;
796
- access_token_json['bot'][appID]['expires_in'] = expires_in.toString();
797
- // 将修改后的配置写入json文件,保留原有格式
798
- var token_new = JSON.stringify(access_token_json, null, 2);
799
- // 写入配置文件,utf-8格式,如果文件不存在会自动创建
800
- fs.writeFileSync(access_token_file, token_new, 'utf-8');
801
- console.log('配置已成功写入到access_token.json文件中。');
802
- resolve(access_token);
803
- } catch (error) {
804
- reject(error);
805
- }
806
- } else {
807
- reject(new Error("Request failed with status code ".concat(res.statusCode)));
808
- }
809
- });
810
- });
811
- req.on('error', function (error) {
812
- reject(error);
813
- });
814
- req.write(requestData);
815
- req.end();
816
- });
817
- }
818
-
819
- // 等待Promise完成,带超时机制
820
- var waitForPromiseWithTimeout = /*#__PURE__*/function () {
821
- var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(promise) {
822
- var timeoutMs,
823
- timeoutPromise,
824
- _args = arguments;
825
- return _regeneratorRuntime.wrap(function (_context) {
826
- while (1) switch (_context.prev = _context.next) {
827
- case 0:
828
- timeoutMs = _args.length > 1 && _args[1] !== undefined ? _args[1] : 10000;
829
- timeoutPromise = new Promise(function (_, reject) {
830
- setTimeout(function () {
831
- return reject(new Error("Token refresh timeout after ".concat(timeoutMs, "ms")));
832
- }, timeoutMs);
833
- });
834
- return _context.abrupt("return", Promise.race([promise, timeoutPromise]));
835
- case 1:
836
- case "end":
837
- return _context.stop();
838
- }
839
- }, _callee);
840
- }));
841
- return function waitForPromiseWithTimeout(_x) {
842
- return _ref.apply(this, arguments);
843
- };
844
- }();
845
-
846
- // 获取或刷新token(带并发控制和超时保护)
847
- var getOrRefreshToken = /*#__PURE__*/function () {
848
- var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee3(appID, clientSecret) {
849
- var now_time, url, data, access_token_file, access_token, expires_in, needsRefresh, access_token_json, expiresStr, parsed, default_token_json, key, existingEntry, refreshPromise, _t2;
850
- return _regeneratorRuntime.wrap(function (_context3) {
851
- while (1) switch (_context3.prev = _context3.next) {
852
- case 0:
853
- now_time = getTimeStampNumber();
854
- url = 'https://bots.qq.com/app/getAppAccessToken';
855
- data = {
856
- appId: appID,
857
- clientSecret: clientSecret
858
- };
859
- access_token_file = './access_token.json';
860
- access_token = '';
861
- expires_in = 0;
862
- needsRefresh = false; // 首先读取当前token状态
863
- try {
864
- if (fs.existsSync(access_token_file)) {
865
- access_token_json = JSON.parse(fs.readFileSync(access_token_file).toString());
866
- if (access_token_json.hasOwnProperty('bot') && access_token_json['bot'].hasOwnProperty(appID)) {
867
- access_token = access_token_json['bot'][appID]['access_token'];
868
- expiresStr = access_token_json['bot'][appID]['expires_in'];
869
- if (expiresStr && typeof expiresStr === 'string') {
870
- parsed = parseInt(expiresStr);
871
- if (!isNaN(parsed) && parsed > 0) {
872
- expires_in = parsed;
873
- } else {
874
- console.log('expires_in解析失败,重置为0:', expiresStr);
875
- expires_in = 0;
876
- }
877
- } else {
878
- expires_in = 0;
879
- }
880
- }
881
- } else {
882
- default_token_json = {
883
- bot: _defineProperty({}, appID, {
884
- access_token: '',
885
- expires_in: ''
886
- })
887
- };
888
- fs.writeFileSync(access_token_file, JSON.stringify(default_token_json, null, 2), 'utf-8');
889
- needsRefresh = true;
890
- }
891
- } catch (err) {
892
- console.error('读取文件时发生错误:', err);
893
- expires_in = 0;
894
- needsRefresh = true;
895
- }
896
-
897
- // 如果token有效且不需要刷新,直接返回
898
- if (!(access_token !== '' && now_time <= expires_in - 50 && !needsRefresh)) {
899
- _context3.next = 1;
900
- break;
901
- }
902
- return _context3.abrupt("return", access_token);
903
- case 1:
904
- // 需要刷新token,进入并发控制逻辑
905
- key = "".concat(appID, ":").concat(clientSecret);
906
- existingEntry = tokenRefreshPromises.get(key);
907
- if (!existingEntry) {
908
- _context3.next = 5;
909
- break;
910
- }
911
- _context3.prev = 2;
912
- // 等待已有的刷新完成,但设置超时防止无限等待
913
- console.log("\u7B49\u5F85\u5DF2\u6709\u7684token\u5237\u65B0\u5B8C\u6210 (appID: ".concat(appID, ")"));
914
- _context3.next = 3;
915
- return waitForPromiseWithTimeout(existingEntry.promise, 10000);
916
- case 3:
917
- return _context3.abrupt("return", _context3.sent);
918
- case 4:
919
- _context3.prev = 4;
920
- _t2 = _context3["catch"](2);
921
- console.warn("\u7B49\u5F85token\u5237\u65B0\u8D85\u65F6\u6216\u5931\u8D25\uFF0C\u91CD\u65B0\u53D1\u8D77\u5237\u65B0 (appID: ".concat(appID, "):"), _t2);
922
- // 移除失败的Promise,让新的请求可以重新发起刷新
923
- tokenRefreshPromises["delete"](key);
924
- case 5:
925
- // 创建新的刷新Promise
926
- refreshPromise = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
927
- var new_token, _t;
928
- return _regeneratorRuntime.wrap(function (_context2) {
929
- while (1) switch (_context2.prev = _context2.next) {
930
- case 0:
931
- _context2.prev = 0;
932
- console.log('开始刷新access_token - 当前token:', access_token, '过期时间:', expires_in, '当前时间:', now_time);
933
- _context2.next = 1;
934
- return getAccessToken(access_token_file, url, data, appID);
935
- case 1:
936
- new_token = _context2.sent;
937
- console.log('access_token刷新成功,新token:', new_token);
938
- return _context2.abrupt("return", new_token);
939
- case 2:
940
- _context2.prev = 2;
941
- _t = _context2["catch"](0);
942
- console.error("Token\u5237\u65B0\u5931\u8D25 (appID: ".concat(appID, "):"), _t);
943
- throw _t;
944
- case 3:
945
- _context2.prev = 3;
946
- // 刷新完成后移除Promise
947
- tokenRefreshPromises["delete"](key);
948
- return _context2.finish(3);
949
- case 4:
950
- case "end":
951
- return _context2.stop();
952
- }
953
- }, _callee2, null, [[0, 2, 3, 4]]);
954
- }))(); // 存储Promise和时间戳以便其他并发请求使用和超时清理
955
- tokenRefreshPromises.set(key, {
956
- promise: refreshPromise,
957
- timestamp: Date.now()
958
- });
959
- _context3.next = 6;
960
- return refreshPromise;
961
- case 6:
962
- return _context3.abrupt("return", _context3.sent);
963
- case 7:
964
- case "end":
965
- return _context3.stop();
966
- }
967
- }, _callee3, null, [[2, 4]]);
968
- }));
969
- return function getOrRefreshToken(_x2, _x3) {
970
- return _ref2.apply(this, arguments);
971
- };
972
- }();
973
-
974
- // 添加 User-Agent
975
- var addAuthorization = /*#__PURE__*/function () {
976
- var _ref4 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee4(header, appID, token, clientSecret, apiVersion) {
977
- var access_token;
978
- return _regeneratorRuntime.wrap(function (_context4) {
979
- while (1) switch (_context4.prev = _context4.next) {
980
- case 0:
981
- if (!(apiVersion == 'v2')) {
982
- _context4.next = 2;
983
- break;
984
- }
985
- _context4.next = 1;
986
- return getOrRefreshToken(appID, clientSecret);
987
- case 1:
988
- access_token = _context4.sent;
989
- // 更新header['Authorization']
990
- header['Authorization'] = "QQBot ".concat(access_token);
991
- _context4.next = 3;
992
- break;
993
- case 2:
994
- header['Authorization'] = "Bot ".concat(appID, ".").concat(token);
995
- case 3:
996
- case "end":
997
- return _context4.stop();
998
- }
999
- }, _callee4);
1000
- }));
1001
- return function addAuthorization(_x4, _x5, _x6, _x7, _x8) {
1002
- return _ref4.apply(this, arguments);
1003
- };
1004
- }();
1005
689
  // 组装完整Url
1006
690
  var buildUrl = function buildUrl() {
1007
691
  var path = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
@@ -1023,7 +707,7 @@ var Channel = /*#__PURE__*/function () {
1023
707
  value: function channel(channelID) {
1024
708
  var options = {
1025
709
  method: 'GET',
1026
- url: getURL('channelURI'),
710
+ url: getURL$1('channelURI'),
1027
711
  rest: {
1028
712
  channelID: channelID
1029
713
  }
@@ -1037,7 +721,7 @@ var Channel = /*#__PURE__*/function () {
1037
721
  value: function channels(guildID) {
1038
722
  var options = {
1039
723
  method: 'GET',
1040
- url: getURL('channelsURI'),
724
+ url: getURL$1('channelsURI'),
1041
725
  rest: {
1042
726
  guildID: guildID
1043
727
  }
@@ -1054,7 +738,7 @@ var Channel = /*#__PURE__*/function () {
1054
738
  }
1055
739
  var options = {
1056
740
  method: 'POST',
1057
- url: getURL('channelsURI'),
741
+ url: getURL$1('channelsURI'),
1058
742
  rest: {
1059
743
  guildID: guildID
1060
744
  },
@@ -1072,7 +756,7 @@ var Channel = /*#__PURE__*/function () {
1072
756
  }
1073
757
  var options = {
1074
758
  method: 'PATCH',
1075
- url: getURL('channelURI'),
759
+ url: getURL$1('channelURI'),
1076
760
  rest: {
1077
761
  channelID: channelID
1078
762
  },
@@ -1087,7 +771,7 @@ var Channel = /*#__PURE__*/function () {
1087
771
  value: function deleteChannel(channelID) {
1088
772
  var options = {
1089
773
  method: 'DELETE',
1090
- url: getURL('channelURI'),
774
+ url: getURL$1('channelURI'),
1091
775
  rest: {
1092
776
  channelID: channelID
1093
777
  }
@@ -1112,7 +796,7 @@ var Me = /*#__PURE__*/function () {
1112
796
  value: function me() {
1113
797
  var options = {
1114
798
  method: 'GET',
1115
- url: getURL('userMeURI')
799
+ url: getURL$1('userMeURI')
1116
800
  };
1117
801
  return this.request(options);
1118
802
  }
@@ -1123,7 +807,7 @@ var Me = /*#__PURE__*/function () {
1123
807
  value: function meGuilds(options) {
1124
808
  var reqOptions = {
1125
809
  method: 'GET',
1126
- url: getURL('userMeGuildsURI'),
810
+ url: getURL$1('userMeGuildsURI'),
1127
811
  params: options
1128
812
  };
1129
813
  return this.request(reqOptions);
@@ -1131,7 +815,7 @@ var Me = /*#__PURE__*/function () {
1131
815
  }]);
1132
816
  }();
1133
817
 
1134
- var Message = /*#__PURE__*/function () {
818
+ var Message$1 = /*#__PURE__*/function () {
1135
819
  function Message(request, config) {
1136
820
  _classCallCheck(this, Message);
1137
821
  _defineProperty(this, "request", void 0);
@@ -1146,7 +830,7 @@ var Message = /*#__PURE__*/function () {
1146
830
  value: function message(channelID, messageID) {
1147
831
  var options = {
1148
832
  method: 'GET',
1149
- url: getURL('messageURI'),
833
+ url: getURL$1('messageURI'),
1150
834
  rest: {
1151
835
  channelID: channelID,
1152
836
  messageID: messageID
@@ -1166,7 +850,7 @@ var Message = /*#__PURE__*/function () {
1166
850
  }
1167
851
  var options = {
1168
852
  method: 'GET',
1169
- url: getURL('messagesURI'),
853
+ url: getURL$1('messagesURI'),
1170
854
  rest: {
1171
855
  channelID: channelID
1172
856
  },
@@ -1181,7 +865,7 @@ var Message = /*#__PURE__*/function () {
1181
865
  value: function postMessage(channelID, message) {
1182
866
  var options = {
1183
867
  method: 'POST',
1184
- url: getURL('messagesURI'),
868
+ url: getURL$1('messagesURI'),
1185
869
  rest: {
1186
870
  channelID: channelID
1187
871
  },
@@ -1196,7 +880,7 @@ var Message = /*#__PURE__*/function () {
1196
880
  value: function patchMessage(channelID, messageID, message) {
1197
881
  var options = {
1198
882
  method: 'PATCH',
1199
- url: getURL('messageURI'),
883
+ url: getURL$1('messageURI'),
1200
884
  rest: {
1201
885
  channelID: channelID,
1202
886
  messageID: messageID
@@ -1216,7 +900,7 @@ var Message = /*#__PURE__*/function () {
1216
900
  }
1217
901
  var options = {
1218
902
  method: 'DELETE',
1219
- url: getURL('messageURI'),
903
+ url: getURL$1('messageURI'),
1220
904
  rest: {
1221
905
  channelID: channelID,
1222
906
  messageID: messageID
@@ -1236,7 +920,7 @@ var Message = /*#__PURE__*/function () {
1236
920
  }
1237
921
  var options = {
1238
922
  method: 'DELETE',
1239
- url: getURL('dmMessageURI'),
923
+ url: getURL$1('dmMessageURI'),
1240
924
  rest: {
1241
925
  guildID: guildID,
1242
926
  messageID: messageID
@@ -1245,108 +929,6 @@ var Message = /*#__PURE__*/function () {
1245
929
  };
1246
930
  return this.request(options);
1247
931
  }
1248
-
1249
- // C2C撤回消息
1250
- }, {
1251
- key: "deleteC2CMessage",
1252
- value: function deleteC2CMessage(userID, messageID, hideTip) {
1253
- var params = Object.create(null);
1254
- if (typeof hideTip === 'boolean') {
1255
- params.hidetip = hideTip;
1256
- }
1257
- var options = {
1258
- method: 'DELETE',
1259
- url: getURL('c2cMessageURI'),
1260
- rest: {
1261
- userID: userID,
1262
- messageID: messageID
1263
- },
1264
- params: params,
1265
- apiVersion: 'v2'
1266
- };
1267
- return this.request(options);
1268
- }
1269
-
1270
- // 群组撤回消息
1271
- }, {
1272
- key: "deleteGroupMessage",
1273
- value: function deleteGroupMessage(groupOpenid, messageID) {
1274
- var options = {
1275
- method: 'DELETE',
1276
- url: getURL('groupMessageURI'),
1277
- rest: {
1278
- groupOpenid: groupOpenid,
1279
- messageID: messageID
1280
- },
1281
- apiVersion: 'v2'
1282
- };
1283
- return this.request(options);
1284
- }
1285
-
1286
- // 发送群消息
1287
- }, {
1288
- key: "postGroupMessage",
1289
- value: function postGroupMessage(groupOpenid, message) {
1290
- var options = {
1291
- method: 'POST',
1292
- url: getURL('groupMessagesURI'),
1293
- rest: {
1294
- groupOpenid: groupOpenid
1295
- },
1296
- data: message,
1297
- apiVersion: 'v2'
1298
- };
1299
- return this.request(options);
1300
- }
1301
-
1302
- // 发送C2C消息
1303
- }, {
1304
- key: "postC2CMessage",
1305
- value: function postC2CMessage(userID, message) {
1306
- message.timestamp = Date.now();
1307
- var options = {
1308
- method: 'POST',
1309
- url: getURL('c2cMessagesURI'),
1310
- rest: {
1311
- userID: userID
1312
- },
1313
- data: message,
1314
- apiVersion: 'v2'
1315
- };
1316
- return this.request(options);
1317
- }
1318
-
1319
- // 发送群富媒体消息
1320
- }, {
1321
- key: "postGroupMedia",
1322
- value: function postGroupMedia(groupOpenid, message) {
1323
- var options = {
1324
- method: 'POST',
1325
- url: getURL('groupRichMediaURI'),
1326
- rest: {
1327
- groupOpenid: groupOpenid
1328
- },
1329
- data: message,
1330
- apiVersion: 'v2'
1331
- };
1332
- return this.request(options);
1333
- }
1334
-
1335
- // 发送C2C消息
1336
- }, {
1337
- key: "postC2CMedia",
1338
- value: function postC2CMedia(userID, message) {
1339
- var options = {
1340
- method: 'POST',
1341
- url: getURL('c2cRichMediaURI'),
1342
- rest: {
1343
- userID: userID
1344
- },
1345
- data: message,
1346
- apiVersion: 'v2'
1347
- };
1348
- return this.request(options);
1349
- }
1350
932
  }]);
1351
933
  }();
1352
934
 
@@ -1371,7 +953,7 @@ var Member = /*#__PURE__*/function () {
1371
953
  } : channel;
1372
954
  var options = {
1373
955
  method: 'PUT',
1374
- url: getURL('memberRoleURI'),
956
+ url: getURL$1('memberRoleURI'),
1375
957
  rest: {
1376
958
  guildID: guildID,
1377
959
  userID: userID,
@@ -1394,7 +976,7 @@ var Member = /*#__PURE__*/function () {
1394
976
  } : channel;
1395
977
  var options = {
1396
978
  method: 'DELETE',
1397
- url: getURL('memberRoleURI'),
979
+ url: getURL$1('memberRoleURI'),
1398
980
  rest: {
1399
981
  guildID: guildID,
1400
982
  userID: userID,
@@ -1415,7 +997,7 @@ var Member = /*#__PURE__*/function () {
1415
997
  };
1416
998
  var options = {
1417
999
  method: 'GET',
1418
- url: getURL('guildRolesMembersURI'),
1000
+ url: getURL$1('guildRolesMembersURI'),
1419
1001
  rest: {
1420
1002
  guildID: guildID,
1421
1003
  roleID: roleID
@@ -1451,7 +1033,7 @@ var Role = /*#__PURE__*/function () {
1451
1033
  value: function roles(guildID) {
1452
1034
  var options = {
1453
1035
  method: 'GET',
1454
- url: getURL('rolesURI'),
1036
+ url: getURL$1('rolesURI'),
1455
1037
  rest: {
1456
1038
  guildID: guildID
1457
1039
  }
@@ -1469,7 +1051,7 @@ var Role = /*#__PURE__*/function () {
1469
1051
  }
1470
1052
  var options = {
1471
1053
  method: 'POST',
1472
- url: getURL('rolesURI'),
1054
+ url: getURL$1('rolesURI'),
1473
1055
  rest: {
1474
1056
  guildID: guildID
1475
1057
  },
@@ -1492,7 +1074,7 @@ var Role = /*#__PURE__*/function () {
1492
1074
  }
1493
1075
  var options = {
1494
1076
  method: 'PATCH',
1495
- url: getURL('roleURI'),
1077
+ url: getURL$1('roleURI'),
1496
1078
  rest: {
1497
1079
  guildID: guildID,
1498
1080
  roleID: roleID
@@ -1512,7 +1094,7 @@ var Role = /*#__PURE__*/function () {
1512
1094
  value: function deleteRole(guildID, roleID) {
1513
1095
  var options = {
1514
1096
  method: 'DELETE',
1515
- url: getURL('roleURI'),
1097
+ url: getURL$1('roleURI'),
1516
1098
  rest: {
1517
1099
  guildID: guildID,
1518
1100
  roleID: roleID
@@ -1538,7 +1120,7 @@ var DirectMessage = /*#__PURE__*/function () {
1538
1120
  value: function createDirectMessage(dm) {
1539
1121
  var options = {
1540
1122
  method: 'POST',
1541
- url: getURL('userMeDMURI'),
1123
+ url: getURL$1('userMeDMURI'),
1542
1124
  data: dm
1543
1125
  };
1544
1126
  return this.request(options);
@@ -1550,7 +1132,7 @@ var DirectMessage = /*#__PURE__*/function () {
1550
1132
  value: function postDirectMessage(guildID, msg) {
1551
1133
  var options = {
1552
1134
  method: 'POST',
1553
- url: getURL('dmsURI'),
1135
+ url: getURL$1('dmsURI'),
1554
1136
  rest: {
1555
1137
  guildID: guildID
1556
1138
  },
@@ -1569,7 +1151,7 @@ var DirectMessage = /*#__PURE__*/function () {
1569
1151
  }
1570
1152
  var options = {
1571
1153
  method: 'DELETE',
1572
- url: getURL('dmMessageURI'),
1154
+ url: getURL$1('dmMessageURI'),
1573
1155
  rest: {
1574
1156
  guildID: guildID,
1575
1157
  messageID: messageID
@@ -1596,7 +1178,7 @@ var ChannelPermissions = /*#__PURE__*/function () {
1596
1178
  value: function channelPermissions(channelID, userID) {
1597
1179
  var options = {
1598
1180
  method: 'GET',
1599
- url: getURL('channelPermissionsURI'),
1181
+ url: getURL$1('channelPermissionsURI'),
1600
1182
  rest: {
1601
1183
  channelID: channelID,
1602
1184
  userID: userID
@@ -1618,7 +1200,7 @@ var ChannelPermissions = /*#__PURE__*/function () {
1618
1200
  }
1619
1201
  var options = {
1620
1202
  method: 'PUT',
1621
- url: getURL('channelPermissionsURI'),
1203
+ url: getURL$1('channelPermissionsURI'),
1622
1204
  rest: {
1623
1205
  channelID: channelID,
1624
1206
  userID: userID
@@ -1634,7 +1216,7 @@ var ChannelPermissions = /*#__PURE__*/function () {
1634
1216
  value: function channelRolePermissions(channelID, roleID) {
1635
1217
  var options = {
1636
1218
  method: 'GET',
1637
- url: getURL('channelRolePermissionsURI'),
1219
+ url: getURL$1('channelRolePermissionsURI'),
1638
1220
  rest: {
1639
1221
  channelID: channelID,
1640
1222
  roleID: roleID
@@ -1656,7 +1238,7 @@ var ChannelPermissions = /*#__PURE__*/function () {
1656
1238
  }
1657
1239
  var options = {
1658
1240
  method: 'PUT',
1659
- url: getURL('channelRolePermissionsURI'),
1241
+ url: getURL$1('channelRolePermissionsURI'),
1660
1242
  rest: {
1661
1243
  channelID: channelID,
1662
1244
  roleID: roleID
@@ -1683,7 +1265,7 @@ var Audio = /*#__PURE__*/function () {
1683
1265
  value: function postAudio(channelID, audioControl) {
1684
1266
  var options = {
1685
1267
  method: 'POST',
1686
- url: getURL('audioControlURI'),
1268
+ url: getURL$1('audioControlURI'),
1687
1269
  rest: {
1688
1270
  channelID: channelID
1689
1271
  },
@@ -1698,7 +1280,7 @@ var Audio = /*#__PURE__*/function () {
1698
1280
  value: function botOnMic(channelID) {
1699
1281
  var options = {
1700
1282
  method: 'PUT',
1701
- url: getURL('botMic'),
1283
+ url: getURL$1('botMic'),
1702
1284
  rest: {
1703
1285
  channelID: channelID
1704
1286
  },
@@ -1713,7 +1295,7 @@ var Audio = /*#__PURE__*/function () {
1713
1295
  value: function botOffMic(channelID) {
1714
1296
  var options = {
1715
1297
  method: 'DELETE',
1716
- url: getURL('botMic'),
1298
+ url: getURL$1('botMic'),
1717
1299
  rest: {
1718
1300
  channelID: channelID
1719
1301
  },
@@ -1724,8 +1306,8 @@ var Audio = /*#__PURE__*/function () {
1724
1306
  }]);
1725
1307
  }();
1726
1308
 
1727
- function ownKeys$1(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
1728
- function _objectSpread$1(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$1(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$1(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
1309
+ function ownKeys$4(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
1310
+ function _objectSpread$4(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$4(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$4(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
1729
1311
  var Mute = /*#__PURE__*/function () {
1730
1312
  function Mute(request, config) {
1731
1313
  _classCallCheck(this, Mute);
@@ -1744,7 +1326,7 @@ var Mute = /*#__PURE__*/function () {
1744
1326
  }
1745
1327
  var reqOptions = {
1746
1328
  method: 'PATCH',
1747
- url: getURL('muteMemberURI'),
1329
+ url: getURL$1('muteMemberURI'),
1748
1330
  rest: {
1749
1331
  guildID: guildID,
1750
1332
  userID: userID
@@ -1763,7 +1345,7 @@ var Mute = /*#__PURE__*/function () {
1763
1345
  }
1764
1346
  var reqOptions = {
1765
1347
  method: 'PATCH',
1766
- url: getURL('muteURI'),
1348
+ url: getURL$1('muteURI'),
1767
1349
  rest: {
1768
1350
  guildID: guildID
1769
1351
  },
@@ -1781,12 +1363,12 @@ var Mute = /*#__PURE__*/function () {
1781
1363
  }
1782
1364
  var reqOptions = {
1783
1365
  method: 'PATCH',
1784
- url: getURL('muteMembersURI'),
1366
+ url: getURL$1('muteMembersURI'),
1785
1367
  rest: {
1786
1368
  guildID: guildID
1787
1369
  },
1788
1370
  // 将options和userIDList合并到一起
1789
- data: _objectSpread$1(_objectSpread$1({}, options), {}, {
1371
+ data: _objectSpread$4(_objectSpread$4({}, options), {}, {
1790
1372
  user_ids: userIDList
1791
1373
  })
1792
1374
  };
@@ -1810,7 +1392,7 @@ var Announce = /*#__PURE__*/function () {
1810
1392
  value: function postGuildAnnounce(guildID, channelID, messageID) {
1811
1393
  var options = {
1812
1394
  method: 'POST',
1813
- url: getURL('guildAnnouncesURI'),
1395
+ url: getURL$1('guildAnnouncesURI'),
1814
1396
  rest: {
1815
1397
  guildID: guildID
1816
1398
  },
@@ -1828,7 +1410,7 @@ var Announce = /*#__PURE__*/function () {
1828
1410
  value: function deleteGuildAnnounce(guildID, messageID) {
1829
1411
  var options = {
1830
1412
  method: 'DELETE',
1831
- url: getURL('guildAnnounceURI'),
1413
+ url: getURL$1('guildAnnounceURI'),
1832
1414
  rest: {
1833
1415
  guildID: guildID,
1834
1416
  messageID: messageID
@@ -1843,7 +1425,7 @@ var Announce = /*#__PURE__*/function () {
1843
1425
  value: function postGuildRecommend(guildID, recommendObj) {
1844
1426
  var options = {
1845
1427
  method: 'POST',
1846
- url: getURL('guildAnnouncesURI'),
1428
+ url: getURL$1('guildAnnouncesURI'),
1847
1429
  rest: {
1848
1430
  guildID: guildID
1849
1431
  },
@@ -1858,7 +1440,7 @@ var Announce = /*#__PURE__*/function () {
1858
1440
  value: function postChannelAnnounce(channelID, messageID) {
1859
1441
  var options = {
1860
1442
  method: 'POST',
1861
- url: getURL('channelAnnouncesURI'),
1443
+ url: getURL$1('channelAnnouncesURI'),
1862
1444
  rest: {
1863
1445
  channelID: channelID
1864
1446
  },
@@ -1875,7 +1457,7 @@ var Announce = /*#__PURE__*/function () {
1875
1457
  value: function deleteChannelAnnounce(channelID, messageID) {
1876
1458
  var options = {
1877
1459
  method: 'DELETE',
1878
- url: getURL('channelAnnounceURI'),
1460
+ url: getURL$1('channelAnnounceURI'),
1879
1461
  rest: {
1880
1462
  channelID: channelID,
1881
1463
  messageID: messageID
@@ -1904,7 +1486,7 @@ var Schedule = /*#__PURE__*/function () {
1904
1486
  }
1905
1487
  var options = {
1906
1488
  method: 'GET',
1907
- url: getURL('schedulesURI'),
1489
+ url: getURL$1('schedulesURI'),
1908
1490
  rest: {
1909
1491
  channelID: channelID
1910
1492
  },
@@ -1921,7 +1503,7 @@ var Schedule = /*#__PURE__*/function () {
1921
1503
  value: function schedule(channelID, scheduleID) {
1922
1504
  var options = {
1923
1505
  method: 'GET',
1924
- url: getURL('scheduleURI'),
1506
+ url: getURL$1('scheduleURI'),
1925
1507
  rest: {
1926
1508
  channelID: channelID,
1927
1509
  scheduleID: scheduleID
@@ -1936,7 +1518,7 @@ var Schedule = /*#__PURE__*/function () {
1936
1518
  value: function postSchedule(channelID, schedule) {
1937
1519
  var options = {
1938
1520
  method: 'POST',
1939
- url: getURL('schedulesURI'),
1521
+ url: getURL$1('schedulesURI'),
1940
1522
  rest: {
1941
1523
  channelID: channelID
1942
1524
  },
@@ -1953,7 +1535,7 @@ var Schedule = /*#__PURE__*/function () {
1953
1535
  value: function patchSchedule(channelID, scheduleID, schedule) {
1954
1536
  var options = {
1955
1537
  method: 'PATCH',
1956
- url: getURL('scheduleURI'),
1538
+ url: getURL$1('scheduleURI'),
1957
1539
  rest: {
1958
1540
  channelID: channelID,
1959
1541
  scheduleID: scheduleID
@@ -1971,7 +1553,7 @@ var Schedule = /*#__PURE__*/function () {
1971
1553
  value: function deleteSchedule(channelID, scheduleID) {
1972
1554
  var options = {
1973
1555
  method: 'DELETE',
1974
- url: getURL('scheduleURI'),
1556
+ url: getURL$1('scheduleURI'),
1975
1557
  rest: {
1976
1558
  channelID: channelID,
1977
1559
  scheduleID: scheduleID
@@ -1982,6 +1564,8 @@ var Schedule = /*#__PURE__*/function () {
1982
1564
  }]);
1983
1565
  }();
1984
1566
 
1567
+ function ownKeys$3(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
1568
+ function _objectSpread$3(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$3(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$3(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
1985
1569
  var Threads = /*#__PURE__*/function () {
1986
1570
  function Threads(request, config) {
1987
1571
  _classCallCheck(this, Threads);
@@ -1994,78 +1578,78 @@ var Threads = /*#__PURE__*/function () {
1994
1578
  // 获取帖子列表
1995
1579
  return _createClass(Threads, [{
1996
1580
  key: "threads",
1997
- value: function threads(channelID) {
1998
- var options = {
1581
+ value: function threads(channelID, requestOptions) {
1582
+ var options = _objectSpread$3({
1999
1583
  method: 'GET',
2000
- url: getURL('threadsURI'),
1584
+ url: getURL$1('threadsURI'),
2001
1585
  rest: {
2002
1586
  channelID: channelID
2003
1587
  }
2004
- };
1588
+ }, requestOptions || {});
2005
1589
  return this.request(options);
2006
1590
  }
2007
1591
 
2008
1592
  // 获取帖子详情
2009
1593
  }, {
2010
1594
  key: "thread",
2011
- value: function thread(channelID, threadID) {
2012
- var options = {
1595
+ value: function thread(channelID, threadID, requestOptions) {
1596
+ var options = _objectSpread$3({
2013
1597
  method: 'GET',
2014
- url: getURL('threadURI'),
1598
+ url: getURL$1('threadURI'),
2015
1599
  rest: {
2016
1600
  channelID: channelID,
2017
1601
  threadID: threadID
2018
1602
  }
2019
- };
1603
+ }, requestOptions || {});
2020
1604
  return this.request(options);
2021
1605
  }
2022
1606
 
2023
1607
  // 发表帖子
2024
1608
  }, {
2025
1609
  key: "putThreads",
2026
- value: function putThreads(channelID, _Threads2) {
2027
- var options = {
1610
+ value: function putThreads(channelID, _Threads2, requestOptions) {
1611
+ var options = _objectSpread$3({
2028
1612
  method: 'PUT',
2029
- url: getURL('threadsURI'),
1613
+ url: getURL$1('threadsURI'),
2030
1614
  rest: {
2031
1615
  channelID: channelID
2032
1616
  },
2033
1617
  data: {
2034
1618
  Threads: _Threads2
2035
1619
  }
2036
- };
1620
+ }, requestOptions || {});
2037
1621
  return this.request(options);
2038
1622
  }
2039
1623
 
2040
1624
  // 发表帖子回复
2041
1625
  }, {
2042
1626
  key: "putPostReply",
2043
- value: function putPostReply(channelID, threadID, postID, reply) {
2044
- var options = {
1627
+ value: function putPostReply(channelID, threadID, postID, reply, requestOptions) {
1628
+ var options = _objectSpread$3({
2045
1629
  method: 'PUT',
2046
- url: getURL('threadPostRepliesURI'),
1630
+ url: getURL$1('threadPostRepliesURI'),
2047
1631
  rest: {
2048
1632
  channelID: channelID,
2049
1633
  threadID: threadID,
2050
1634
  postID: postID
2051
1635
  },
2052
1636
  data: reply
2053
- };
1637
+ }, requestOptions || {});
2054
1638
  return this.request(options);
2055
1639
  }
2056
1640
 
2057
1641
  // 删除帖子
2058
1642
  }, {
2059
1643
  key: "deleteThreads",
2060
- value: function deleteThreads(channelID, threadID) {
2061
- var options = {
1644
+ value: function deleteThreads(channelID, threadID, requestOptions) {
1645
+ var options = _objectSpread$3({
2062
1646
  method: 'DELETE',
2063
- url: getURL('threadURI'),
1647
+ url: getURL$1('threadURI'),
2064
1648
  rest: {
2065
1649
  channelID: channelID,
2066
1650
  threadID: threadID
2067
1651
  }
2068
- };
1652
+ }, requestOptions || {});
2069
1653
  return this.request(options);
2070
1654
  }
2071
1655
  }]);
@@ -2086,7 +1670,7 @@ var GuildPermissions = /*#__PURE__*/function () {
2086
1670
  value: function permissions(guildID) {
2087
1671
  var options = {
2088
1672
  method: 'GET',
2089
- url: getURL('guildPermissionURI'),
1673
+ url: getURL$1('guildPermissionURI'),
2090
1674
  rest: {
2091
1675
  guildID: guildID
2092
1676
  }
@@ -2100,7 +1684,7 @@ var GuildPermissions = /*#__PURE__*/function () {
2100
1684
  value: function postPermissionDemand(guildID, permissionDemandObj) {
2101
1685
  var options = {
2102
1686
  method: 'POST',
2103
- url: getURL('guildPermissionDemandURI'),
1687
+ url: getURL$1('guildPermissionDemandURI'),
2104
1688
  rest: {
2105
1689
  guildID: guildID
2106
1690
  },
@@ -2126,7 +1710,7 @@ var Interaction = /*#__PURE__*/function () {
2126
1710
  value: function putInteraction(interactionID, interactionData) {
2127
1711
  var options = {
2128
1712
  method: 'PUT',
2129
- url: getURL('interactionURI'),
1713
+ url: getURL$1('interactionURI'),
2130
1714
  headers: {
2131
1715
  'Content-Type': 'none'
2132
1716
  },
@@ -2140,178 +1724,549 @@ var Interaction = /*#__PURE__*/function () {
2140
1724
  }]);
2141
1725
  }();
2142
1726
 
2143
- var Group = /*#__PURE__*/function () {
2144
- function Group(request, config) {
2145
- _classCallCheck(this, Group);
2146
- _defineProperty(this, "request", void 0);
2147
- _defineProperty(this, "config", void 0);
2148
- this.request = request;
1727
+ function ownKeys$2(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
1728
+ function _objectSpread$2(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$2(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$2(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
1729
+ var OpenAPI$1 = /*#__PURE__*/function () {
1730
+ function OpenAPI(config) {
1731
+ var _this = this;
1732
+ _classCallCheck(this, OpenAPI);
1733
+ _defineProperty(this, "config", {
1734
+ appID: '',
1735
+ token: ''
1736
+ });
1737
+ _defineProperty(this, "guildApi", void 0);
1738
+ _defineProperty(this, "channelApi", void 0);
1739
+ _defineProperty(this, "meApi", void 0);
1740
+ _defineProperty(this, "messageApi", void 0);
1741
+ _defineProperty(this, "memberApi", void 0);
1742
+ _defineProperty(this, "roleApi", void 0);
1743
+ _defineProperty(this, "muteApi", void 0);
1744
+ _defineProperty(this, "announceApi", void 0);
1745
+ _defineProperty(this, "scheduleApi", void 0);
1746
+ _defineProperty(this, "threadsApi", void 0);
1747
+ _defineProperty(this, "directMessageApi", void 0);
1748
+ _defineProperty(this, "channelPermissionsApi", void 0);
1749
+ _defineProperty(this, "audioApi", void 0);
1750
+ _defineProperty(this, "reactionApi", void 0);
1751
+ _defineProperty(this, "interactionApi", void 0);
1752
+ _defineProperty(this, "pinsMessageApi", void 0);
1753
+ _defineProperty(this, "guildPermissionsApi", void 0);
1754
+ // 基础rest请求
1755
+ _defineProperty(this, "request", /*#__PURE__*/function () {
1756
+ var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(options) {
1757
+ var _this$config, appID, token, botUrl, client;
1758
+ return _regeneratorRuntime.wrap(function (_context) {
1759
+ while (1) switch (_context.prev = _context.next) {
1760
+ case 0:
1761
+ _this$config = _this.config, appID = _this$config.appID, token = _this$config.token;
1762
+ options.headers = _objectSpread$2({}, options.headers);
1763
+
1764
+ // 添加 UA
1765
+ addUserAgent(options.headers);
1766
+ // 添加鉴权信息
1767
+ addV1Authorization(options.headers, appID, token);
1768
+ // 组装完整Url
1769
+ botUrl = buildUrl(options.url, _this.config.sandbox); // 简化错误信息,后续可考虑通过中间件形式暴露给用户自行处理
1770
+ resty.useRes(function (result) {
1771
+ return result;
1772
+ }, function (error) {
1773
+ var _error$response, _error$response2;
1774
+ var traceid = error === null || error === void 0 || (_error$response = error.response) === null || _error$response === void 0 || (_error$response = _error$response.headers) === null || _error$response === void 0 ? void 0 : _error$response['x-tps-trace-id'];
1775
+ if (error !== null && error !== void 0 && (_error$response2 = error.response) !== null && _error$response2 !== void 0 && _error$response2.data) {
1776
+ return Promise.reject(_objectSpread$2(_objectSpread$2({}, error.response.data), {}, {
1777
+ traceid: traceid
1778
+ }));
1779
+ }
1780
+ if (error !== null && error !== void 0 && error.response) {
1781
+ return Promise.reject(_objectSpread$2(_objectSpread$2({}, error.response), {}, {
1782
+ traceid: traceid
1783
+ }));
1784
+ }
1785
+ return Promise.reject(error);
1786
+ });
1787
+ client = resty.create(options);
1788
+ return _context.abrupt("return", client.request(botUrl, options));
1789
+ case 1:
1790
+ case "end":
1791
+ return _context.stop();
1792
+ }
1793
+ }, _callee);
1794
+ }));
1795
+ return function (_x) {
1796
+ return _ref.apply(this, arguments);
1797
+ };
1798
+ }());
2149
1799
  this.config = config;
1800
+ this.initializeApis(this);
2150
1801
  }
2151
- return _createClass(Group, [{
2152
- key: "getGroupInfo",
2153
- value: function getGroupInfo(groupOpenid) {
2154
- return this.request({
2155
- method: 'GET',
2156
- url: getURL('groupInfoURI'),
2157
- rest: {
2158
- groupOpenid: groupOpenid
2159
- },
2160
- apiVersion: 'v2'
1802
+ return _createClass(OpenAPI, [{
1803
+ key: "initializeApis",
1804
+ value: function initializeApis(client) {
1805
+ client.guildApi = new Guild(this.request, this.config);
1806
+ client.channelApi = new Channel(this.request, this.config);
1807
+ client.meApi = new Me(this.request, this.config);
1808
+ client.messageApi = new Message$1(this.request, this.config);
1809
+ client.memberApi = new Member(this.request, this.config);
1810
+ client.roleApi = new Role(this.request, this.config);
1811
+ client.muteApi = new Mute(this.request, this.config);
1812
+ client.announceApi = new Announce(this.request, this.config);
1813
+ client.scheduleApi = new Schedule(this.request, this.config);
1814
+ client.threadsApi = new Threads(this.request, this.config);
1815
+ client.directMessageApi = new DirectMessage(this.request, this.config);
1816
+ client.channelPermissionsApi = new ChannelPermissions(this.request, this.config);
1817
+ client.audioApi = new Audio(this.request, this.config);
1818
+ client.guildPermissionsApi = new GuildPermissions(this.request, this.config);
1819
+ client.reactionApi = new Reaction(this.request, this.config);
1820
+ client.interactionApi = new Interaction(this.request, this.config);
1821
+ client.pinsMessageApi = new PinsMessage(this.request, this.config);
1822
+ }
1823
+ }], [{
1824
+ key: "newClient",
1825
+ value: function newClient(config) {
1826
+ return new OpenAPI(config);
1827
+ }
1828
+ }]);
1829
+ }();
1830
+
1831
+ function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: true } : { done: false, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = true, u = false; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = true, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
1832
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
1833
+ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
1834
+ var ACCESS_TOKEN_URL = 'https://api.bot.qq.com/app/getAppAccessToken';
1835
+ var REFRESH_AHEAD_MS = 60000;
1836
+ var REQUEST_TIMEOUT_MS = 10000;
1837
+ var accessTokenCache = new Map();
1838
+ var accessTokenRequests = new Map();
1839
+ var getCacheKey = function getCacheKey(appID, clientSecret) {
1840
+ return "".concat(appID, ":").concat(clientSecret);
1841
+ };
1842
+ var requestAccessToken = function requestAccessToken(appID, clientSecret) {
1843
+ var body = JSON.stringify({
1844
+ appId: appID,
1845
+ clientSecret: clientSecret
1846
+ });
1847
+ return new Promise(function (resolve, reject) {
1848
+ var request = https.request(ACCESS_TOKEN_URL, {
1849
+ method: 'POST',
1850
+ headers: {
1851
+ 'Content-Type': 'application/json',
1852
+ 'Content-Length': Buffer.byteLength(body)
1853
+ }
1854
+ }, function (response) {
1855
+ var responseBody = '';
1856
+ response.setEncoding('utf8');
1857
+ response.on('data', function (chunk) {
1858
+ responseBody += chunk;
1859
+ });
1860
+ response.on('end', function () {
1861
+ var data;
1862
+ try {
1863
+ data = JSON.parse(responseBody);
1864
+ } catch (_unused) {
1865
+ reject(new Error("\u83B7\u53D6 QQ access_token \u5931\u8D25\uFF1A\u54CD\u5E94\u4E0D\u662F\u6709\u6548 JSON\uFF08HTTP ".concat(response.statusCode, "\uFF09")));
1866
+ return;
1867
+ }
1868
+ if (!response.statusCode || response.statusCode < 200 || response.statusCode >= 300) {
1869
+ reject(Object.assign(new Error(data.message || "\u83B7\u53D6 QQ access_token \u5931\u8D25\uFF08HTTP ".concat(response.statusCode, "\uFF09")), data));
1870
+ return;
1871
+ }
1872
+ if (!data.access_token || !Number.isFinite(Number(data.expires_in))) {
1873
+ reject(new Error('获取 QQ access_token 失败:响应缺少 access_token 或 expires_in'));
1874
+ return;
1875
+ }
1876
+ resolve(data);
2161
1877
  });
1878
+ });
1879
+ request.setTimeout(REQUEST_TIMEOUT_MS, function () {
1880
+ request.destroy(new Error("\u83B7\u53D6 QQ access_token \u8D85\u65F6\uFF08".concat(REQUEST_TIMEOUT_MS, "ms\uFF09")));
1881
+ });
1882
+ request.on('error', reject);
1883
+ request.end(body);
1884
+ });
1885
+ };
1886
+ var invalidateV2AccessToken = function invalidateV2AccessToken(appID) {
1887
+ var _iterator = _createForOfIteratorHelper(accessTokenCache.keys()),
1888
+ _step;
1889
+ try {
1890
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
1891
+ var key = _step.value;
1892
+ if (key.startsWith("".concat(appID, ":"))) accessTokenCache["delete"](key);
1893
+ }
1894
+ } catch (err) {
1895
+ _iterator.e(err);
1896
+ } finally {
1897
+ _iterator.f();
1898
+ }
1899
+ };
1900
+ var getV2AccessToken = /*#__PURE__*/function () {
1901
+ var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(config) {
1902
+ var forceRefresh,
1903
+ configuredAccessToken,
1904
+ cacheKey,
1905
+ cached,
1906
+ pending,
1907
+ tokenRequest,
1908
+ _args = arguments;
1909
+ return _regeneratorRuntime.wrap(function (_context) {
1910
+ while (1) switch (_context.prev = _context.next) {
1911
+ case 0:
1912
+ forceRefresh = _args.length > 1 && _args[1] !== undefined ? _args[1] : false;
1913
+ configuredAccessToken = config.accessToken || config.access_token;
1914
+ if (!configuredAccessToken) {
1915
+ _context.next = 1;
1916
+ break;
1917
+ }
1918
+ return _context.abrupt("return", configuredAccessToken);
1919
+ case 1:
1920
+ if (config.clientSecret) {
1921
+ _context.next = 2;
1922
+ break;
1923
+ }
1924
+ throw new Error('QQ OpenAPI v2 需要配置 clientSecret(AppSecret)或 accessToken');
1925
+ case 2:
1926
+ cacheKey = getCacheKey(config.appID, config.clientSecret);
1927
+ cached = accessTokenCache.get(cacheKey);
1928
+ if (!(!forceRefresh && cached && Date.now() < cached.expiresAt - REFRESH_AHEAD_MS)) {
1929
+ _context.next = 3;
1930
+ break;
1931
+ }
1932
+ return _context.abrupt("return", cached.accessToken);
1933
+ case 3:
1934
+ pending = accessTokenRequests.get(cacheKey);
1935
+ if (!pending) {
1936
+ _context.next = 4;
1937
+ break;
1938
+ }
1939
+ return _context.abrupt("return", pending);
1940
+ case 4:
1941
+ tokenRequest = requestAccessToken(config.appID, config.clientSecret).then(function (response) {
1942
+ var expiresInSeconds = Number(response.expires_in);
1943
+ accessTokenCache.set(cacheKey, {
1944
+ accessToken: response.access_token,
1945
+ expiresAt: Date.now() + expiresInSeconds * 1000
1946
+ });
1947
+ return response.access_token;
1948
+ })["finally"](function () {
1949
+ accessTokenRequests["delete"](cacheKey);
1950
+ });
1951
+ accessTokenRequests.set(cacheKey, tokenRequest);
1952
+ return _context.abrupt("return", tokenRequest);
1953
+ case 5:
1954
+ case "end":
1955
+ return _context.stop();
1956
+ }
1957
+ }, _callee);
1958
+ }));
1959
+ return function getV2AccessToken(_x) {
1960
+ return _ref.apply(this, arguments);
1961
+ };
1962
+ }();
1963
+ var addV2Authorization = /*#__PURE__*/function () {
1964
+ var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2(headers, config) {
1965
+ var forceRefresh,
1966
+ _args2 = arguments,
1967
+ _t;
1968
+ return _regeneratorRuntime.wrap(function (_context2) {
1969
+ while (1) switch (_context2.prev = _context2.next) {
1970
+ case 0:
1971
+ forceRefresh = _args2.length > 2 && _args2[2] !== undefined ? _args2[2] : false;
1972
+ _t = "QQBot ";
1973
+ _context2.next = 1;
1974
+ return getV2AccessToken(config, forceRefresh);
1975
+ case 1:
1976
+ headers.Authorization = _t.concat.call(_t, _context2.sent);
1977
+ case 2:
1978
+ case "end":
1979
+ return _context2.stop();
1980
+ }
1981
+ }, _callee2);
1982
+ }));
1983
+ return function addV2Authorization(_x2, _x3) {
1984
+ return _ref2.apply(this, arguments);
1985
+ };
1986
+ }();
1987
+
1988
+ var apiMap = {
1989
+ gatewayBotURI: '/gateway/bot',
1990
+ groupMessagesURI: '/v2/groups/:groupOpenid/messages',
1991
+ groupRichMediaURI: '/v2/groups/:groupOpenid/files',
1992
+ groupMessageURI: '/v2/groups/:groupOpenid/messages/:messageID',
1993
+ groupInfoURI: '/v2/groups/:groupOpenid/info',
1994
+ groupBotStateURI: '/v2/groups/:groupOpenid/bot_state',
1995
+ groupJoinRequestListURI: '/v2/groups/:groupOpenid/join_request_list',
1996
+ groupJoinRequestApprovalURI: '/v2/groups/:groupOpenid/approval_join_request/:memberOpenid',
1997
+ groupRestrictChatSettingURI: '/v2/groups/:groupOpenid/restrict_chat_setting',
1998
+ groupJoinApprovalStrategiesURI: '/v2/groups/join_approval_strategy',
1999
+ groupJoinApprovalStrategyURI: '/v2/groups/join_approval_strategy/:strategyID',
2000
+ groupJoinApprovalStrategyExecuteURI: '/v2/groups/join_approval_strategy/:strategyID/execute',
2001
+ groupJoinApprovalStrategyWhitelistURI: '/v2/groups/join_approval_strategy/:strategyID/whitelist_users',
2002
+ c2cMessagesURI: '/v2/users/:userOpenid/messages',
2003
+ c2cStreamMessagesURI: '/v2/users/:userOpenid/stream_messages',
2004
+ c2cRichMediaURI: '/v2/users/:userOpenid/files',
2005
+ c2cMessageURI: '/v2/users/:userOpenid/messages/:messageID'
2006
+ };
2007
+ var getURL = function getURL(endpoint) {
2008
+ return apiMap[endpoint];
2009
+ };
2010
+
2011
+ function ownKeys$1(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
2012
+ function _objectSpread$1(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$1(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$1(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
2013
+ var Group = /*#__PURE__*/function () {
2014
+ function Group(request, config) {
2015
+ _classCallCheck(this, Group);
2016
+ _defineProperty(this, "request", void 0);
2017
+ _defineProperty(this, "config", void 0);
2018
+ this.request = request;
2019
+ this.config = config;
2020
+ }
2021
+ return _createClass(Group, [{
2022
+ key: "getGroupInfo",
2023
+ value: function getGroupInfo(groupOpenid, requestOptions) {
2024
+ return this.request(_objectSpread$1({
2025
+ method: 'GET',
2026
+ url: getURL('groupInfoURI'),
2027
+ rest: {
2028
+ groupOpenid: groupOpenid
2029
+ }
2030
+ }, requestOptions || {}));
2162
2031
  }
2163
2032
  }, {
2164
2033
  key: "getGroupBotState",
2165
- value: function getGroupBotState(groupOpenid) {
2166
- return this.request({
2034
+ value: function getGroupBotState(groupOpenid, requestOptions) {
2035
+ return this.request(_objectSpread$1({
2167
2036
  method: 'GET',
2168
2037
  url: getURL('groupBotStateURI'),
2169
2038
  rest: {
2170
2039
  groupOpenid: groupOpenid
2171
- },
2172
- apiVersion: 'v2'
2173
- });
2040
+ }
2041
+ }, requestOptions || {}));
2174
2042
  }
2175
2043
  }, {
2176
2044
  key: "getGroupJoinRequests",
2177
- value: function getGroupJoinRequests(groupOpenid, pager) {
2178
- return this.request({
2045
+ value: function getGroupJoinRequests(groupOpenid, pager, requestOptions) {
2046
+ return this.request(_objectSpread$1({
2179
2047
  method: 'GET',
2180
2048
  url: getURL('groupJoinRequestListURI'),
2181
2049
  rest: {
2182
2050
  groupOpenid: groupOpenid
2183
2051
  },
2184
- params: pager || {},
2185
- apiVersion: 'v2'
2186
- });
2052
+ params: pager || {}
2053
+ }, requestOptions || {}));
2187
2054
  }
2188
2055
  }, {
2189
2056
  key: "approveGroupJoinRequest",
2190
- value: function approveGroupJoinRequest(groupOpenid, memberOpenid, options) {
2191
- return this.request({
2057
+ value: function approveGroupJoinRequest(groupOpenid, memberOpenid, options, requestOptions) {
2058
+ return this.request(_objectSpread$1({
2192
2059
  method: 'POST',
2193
2060
  url: getURL('groupJoinRequestApprovalURI'),
2194
2061
  rest: {
2195
2062
  groupOpenid: groupOpenid,
2196
2063
  memberOpenid: memberOpenid
2197
2064
  },
2198
- data: options,
2199
- apiVersion: 'v2'
2200
- });
2065
+ data: options
2066
+ }, requestOptions || {}));
2201
2067
  }
2202
2068
  }, {
2203
2069
  key: "getGroupRestrictChatSetting",
2204
- value: function getGroupRestrictChatSetting(groupOpenid) {
2205
- return this.request({
2070
+ value: function getGroupRestrictChatSetting(groupOpenid, requestOptions) {
2071
+ return this.request(_objectSpread$1({
2206
2072
  method: 'GET',
2207
2073
  url: getURL('groupRestrictChatSettingURI'),
2208
2074
  rest: {
2209
2075
  groupOpenid: groupOpenid
2210
- },
2211
- apiVersion: 'v2'
2212
- });
2076
+ }
2077
+ }, requestOptions || {}));
2213
2078
  }
2214
2079
  }, {
2215
2080
  key: "setGroupRestrictChatSetting",
2216
- value: function setGroupRestrictChatSetting(groupOpenid, options) {
2217
- return this.request({
2081
+ value: function setGroupRestrictChatSetting(groupOpenid, options, requestOptions) {
2082
+ return this.request(_objectSpread$1({
2218
2083
  method: 'POST',
2219
2084
  url: getURL('groupRestrictChatSettingURI'),
2220
2085
  rest: {
2221
2086
  groupOpenid: groupOpenid
2222
2087
  },
2223
- data: options,
2224
- apiVersion: 'v2'
2225
- });
2088
+ data: options
2089
+ }, requestOptions || {}));
2226
2090
  }
2227
2091
  }, {
2228
2092
  key: "getGroupJoinApprovalStrategies",
2229
- value: function getGroupJoinApprovalStrategies(pager) {
2230
- return this.request({
2093
+ value: function getGroupJoinApprovalStrategies(pager, requestOptions) {
2094
+ return this.request(_objectSpread$1({
2231
2095
  method: 'GET',
2232
2096
  url: getURL('groupJoinApprovalStrategiesURI'),
2233
- params: pager || {},
2234
- apiVersion: 'v2'
2235
- });
2097
+ params: pager || {}
2098
+ }, requestOptions || {}));
2236
2099
  }
2237
2100
  }, {
2238
2101
  key: "createGroupJoinApprovalStrategy",
2239
- value: function createGroupJoinApprovalStrategy(options) {
2240
- return this.request({
2102
+ value: function createGroupJoinApprovalStrategy(options, requestOptions) {
2103
+ return this.request(_objectSpread$1({
2241
2104
  method: 'POST',
2242
2105
  url: getURL('groupJoinApprovalStrategiesURI'),
2243
- data: options,
2244
- apiVersion: 'v2'
2245
- });
2106
+ data: options
2107
+ }, requestOptions || {}));
2246
2108
  }
2247
2109
  }, {
2248
2110
  key: "updateGroupJoinApprovalStrategy",
2249
- value: function updateGroupJoinApprovalStrategy(strategyID, options) {
2250
- return this.request({
2111
+ value: function updateGroupJoinApprovalStrategy(strategyID, options, requestOptions) {
2112
+ return this.request(_objectSpread$1({
2251
2113
  method: 'PATCH',
2252
2114
  url: getURL('groupJoinApprovalStrategyURI'),
2253
2115
  rest: {
2254
2116
  strategyID: strategyID
2255
2117
  },
2256
- data: options,
2257
- apiVersion: 'v2'
2258
- });
2118
+ data: options
2119
+ }, requestOptions || {}));
2259
2120
  }
2260
2121
  }, {
2261
2122
  key: "deleteGroupJoinApprovalStrategy",
2262
- value: function deleteGroupJoinApprovalStrategy(strategyID) {
2263
- return this.request({
2123
+ value: function deleteGroupJoinApprovalStrategy(strategyID, requestOptions) {
2124
+ return this.request(_objectSpread$1({
2264
2125
  method: 'DELETE',
2265
2126
  url: getURL('groupJoinApprovalStrategyURI'),
2266
2127
  rest: {
2267
2128
  strategyID: strategyID
2268
- },
2269
- apiVersion: 'v2'
2270
- });
2129
+ }
2130
+ }, requestOptions || {}));
2271
2131
  }
2272
2132
  }, {
2273
2133
  key: "executeGroupJoinApprovalStrategy",
2274
- value: function executeGroupJoinApprovalStrategy(strategyID) {
2275
- return this.request({
2134
+ value: function executeGroupJoinApprovalStrategy(strategyID, requestOptions) {
2135
+ return this.request(_objectSpread$1({
2276
2136
  method: 'POST',
2277
2137
  url: getURL('groupJoinApprovalStrategyExecuteURI'),
2278
2138
  rest: {
2279
2139
  strategyID: strategyID
2280
2140
  },
2281
- data: {},
2282
- apiVersion: 'v2'
2283
- });
2141
+ data: {}
2142
+ }, requestOptions || {}));
2284
2143
  }
2285
2144
  }, {
2286
2145
  key: "updateGroupJoinApprovalStrategyWhitelist",
2287
- value: function updateGroupJoinApprovalStrategyWhitelist(strategyID, options) {
2288
- return this.request({
2146
+ value: function updateGroupJoinApprovalStrategyWhitelist(strategyID, options, requestOptions) {
2147
+ return this.request(_objectSpread$1({
2289
2148
  method: 'POST',
2290
2149
  url: getURL('groupJoinApprovalStrategyWhitelistURI'),
2291
2150
  rest: {
2292
2151
  strategyID: strategyID
2293
2152
  },
2294
- data: options,
2295
- apiVersion: 'v2'
2296
- });
2153
+ data: options
2154
+ }, requestOptions || {}));
2297
2155
  }
2298
2156
  }]);
2299
2157
  }();
2300
2158
 
2159
+ function _callSuper$1(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct$1() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
2160
+ function _isNativeReflectConstruct$1() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct$1 = function _isNativeReflectConstruct() { return !!t; })(); }
2161
+ var Message = /*#__PURE__*/function (_V1Message) {
2162
+ function Message() {
2163
+ _classCallCheck(this, Message);
2164
+ return _callSuper$1(this, Message, arguments);
2165
+ }
2166
+ _inherits(Message, _V1Message);
2167
+ return _createClass(Message, [{
2168
+ key: "postGroupMessage",
2169
+ value: function postGroupMessage(groupOpenid, message) {
2170
+ return this.request({
2171
+ method: 'POST',
2172
+ url: getURL('groupMessagesURI'),
2173
+ rest: {
2174
+ groupOpenid: groupOpenid
2175
+ },
2176
+ data: message
2177
+ });
2178
+ }
2179
+ }, {
2180
+ key: "postC2CMessage",
2181
+ value: function postC2CMessage(userOpenid, message) {
2182
+ return this.request({
2183
+ method: 'POST',
2184
+ url: getURL('c2cMessagesURI'),
2185
+ rest: {
2186
+ userOpenid: userOpenid
2187
+ },
2188
+ data: message
2189
+ });
2190
+ }
2191
+ }, {
2192
+ key: "postC2CStreamMessage",
2193
+ value: function postC2CStreamMessage(userOpenid, message) {
2194
+ return this.request({
2195
+ method: 'POST',
2196
+ url: getURL('c2cStreamMessagesURI'),
2197
+ rest: {
2198
+ userOpenid: userOpenid
2199
+ },
2200
+ data: message
2201
+ });
2202
+ }
2203
+ }, {
2204
+ key: "deleteGroupMessage",
2205
+ value: function deleteGroupMessage(groupOpenid, messageID) {
2206
+ return this.request({
2207
+ method: 'DELETE',
2208
+ url: getURL('groupMessageURI'),
2209
+ rest: {
2210
+ groupOpenid: groupOpenid,
2211
+ messageID: messageID
2212
+ }
2213
+ });
2214
+ }
2215
+ }, {
2216
+ key: "deleteC2CMessage",
2217
+ value: function deleteC2CMessage(userOpenid, messageID) {
2218
+ return this.request({
2219
+ method: 'DELETE',
2220
+ url: getURL('c2cMessageURI'),
2221
+ rest: {
2222
+ userOpenid: userOpenid,
2223
+ messageID: messageID
2224
+ }
2225
+ });
2226
+ }
2227
+ }, {
2228
+ key: "postGroupMedia",
2229
+ value: function postGroupMedia(groupOpenid, media) {
2230
+ return this.request({
2231
+ method: 'POST',
2232
+ url: getURL('groupRichMediaURI'),
2233
+ rest: {
2234
+ groupOpenid: groupOpenid
2235
+ },
2236
+ data: media
2237
+ });
2238
+ }
2239
+ }, {
2240
+ key: "postC2CMedia",
2241
+ value: function postC2CMedia(userOpenid, media) {
2242
+ return this.request({
2243
+ method: 'POST',
2244
+ url: getURL('c2cRichMediaURI'),
2245
+ rest: {
2246
+ userOpenid: userOpenid
2247
+ },
2248
+ data: media
2249
+ });
2250
+ }
2251
+ }]);
2252
+ }(Message$1);
2253
+
2301
2254
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
2302
2255
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
2303
2256
  var apiVersion = 'v2';
2257
+ var isAuthenticationError = function isAuthenticationError(error) {
2258
+ return (error === null || error === void 0 ? void 0 : error.status) === 401 || (error === null || error === void 0 ? void 0 : error.statusCode) === 401 || (error === null || error === void 0 ? void 0 : error.code) === 11201 || (error === null || error === void 0 ? void 0 : error.err_code) === 40012001;
2259
+ };
2304
2260
  var OpenAPI = /*#__PURE__*/function () {
2305
2261
  function OpenAPI(config) {
2262
+ var _this = this;
2306
2263
  _classCallCheck(this, OpenAPI);
2307
- _defineProperty(this, "config", {
2308
- appID: '',
2309
- token: ''
2310
- });
2264
+ _defineProperty(this, "config", void 0);
2265
+ _defineProperty(this, "groupApi", void 0);
2266
+ _defineProperty(this, "messageApi", void 0);
2311
2267
  _defineProperty(this, "guildApi", void 0);
2312
2268
  _defineProperty(this, "channelApi", void 0);
2313
2269
  _defineProperty(this, "meApi", void 0);
2314
- _defineProperty(this, "messageApi", void 0);
2315
2270
  _defineProperty(this, "memberApi", void 0);
2316
2271
  _defineProperty(this, "roleApi", void 0);
2317
2272
  _defineProperty(this, "muteApi", void 0);
@@ -2321,123 +2276,122 @@ var OpenAPI = /*#__PURE__*/function () {
2321
2276
  _defineProperty(this, "directMessageApi", void 0);
2322
2277
  _defineProperty(this, "channelPermissionsApi", void 0);
2323
2278
  _defineProperty(this, "audioApi", void 0);
2279
+ _defineProperty(this, "guildPermissionsApi", void 0);
2324
2280
  _defineProperty(this, "reactionApi", void 0);
2325
2281
  _defineProperty(this, "interactionApi", void 0);
2326
2282
  _defineProperty(this, "pinsMessageApi", void 0);
2327
- _defineProperty(this, "guildPermissionsApi", void 0);
2328
- _defineProperty(this, "groupApi", void 0);
2329
- this.config = config;
2330
- this.register(this);
2331
- }
2332
- return _createClass(OpenAPI, [{
2333
- key: "register",
2334
- value: function register(client) {
2335
- // 注册聚合client
2336
- client.guildApi = new Guild(this.request, this.config);
2337
- client.channelApi = new Channel(this.request, this.config);
2338
- client.meApi = new Me(this.request, this.config);
2339
- client.messageApi = new Message(this.request, this.config);
2340
- client.memberApi = new Member(this.request, this.config);
2341
- client.roleApi = new Role(this.request, this.config);
2342
- client.muteApi = new Mute(this.request, this.config);
2343
- client.announceApi = new Announce(this.request, this.config);
2344
- client.scheduleApi = new Schedule(this.request, this.config);
2345
- client.threadsApi = new Threads(this.request, this.config);
2346
- client.directMessageApi = new DirectMessage(this.request, this.config);
2347
- client.channelPermissionsApi = new ChannelPermissions(this.request, this.config);
2348
- client.audioApi = new Audio(this.request, this.config);
2349
- client.guildPermissionsApi = new GuildPermissions(this.request, this.config);
2350
- client.reactionApi = new Reaction(this.request, this.config);
2351
- client.interactionApi = new Interaction(this.request, this.config);
2352
- client.pinsMessageApi = new PinsMessage(this.request, this.config);
2353
- client.groupApi = new Group(this.request, this.config);
2354
- }
2355
-
2356
- // 基础rest请求
2357
- }, {
2358
- key: "request",
2359
- value: function () {
2360
- var _request = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(options) {
2361
- var _this$config, appID, token, clientSecret, apiVersion, botUrl, client, retryClient, _t, _t2;
2283
+ _defineProperty(this, "prepareOptions", /*#__PURE__*/function () {
2284
+ var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(options) {
2285
+ var forceRefresh,
2286
+ preparedOptions,
2287
+ _args = arguments;
2362
2288
  return _regeneratorRuntime.wrap(function (_context) {
2363
2289
  while (1) switch (_context.prev = _context.next) {
2364
2290
  case 0:
2365
- _this$config = this.config, appID = _this$config.appID, token = _this$config.token, clientSecret = _this$config.clientSecret;
2366
- options.headers = _objectSpread({}, options.headers);
2367
- apiVersion = options.apiVersion || 'v2'; // 添加 UA
2368
- addUserAgent(options.headers, appID, apiVersion);
2369
- // 添加鉴权信息
2291
+ forceRefresh = _args.length > 1 && _args[1] !== undefined ? _args[1] : false;
2292
+ preparedOptions = _objectSpread(_objectSpread({}, options), {}, {
2293
+ headers: _objectSpread({}, options.headers)
2294
+ });
2295
+ addUserAgent(preparedOptions.headers);
2370
2296
  _context.next = 1;
2371
- return addAuthorization(options.headers, appID, token, clientSecret, apiVersion);
2297
+ return addV2Authorization(preparedOptions.headers, _this.config, forceRefresh);
2372
2298
  case 1:
2373
- // 组装完整Url
2374
- botUrl = buildUrl(options.url, this.config.sandbox); // 简化错误信息,后续可考虑通过中间件形式暴露给用户自行处理
2299
+ return _context.abrupt("return", preparedOptions);
2300
+ case 2:
2301
+ case "end":
2302
+ return _context.stop();
2303
+ }
2304
+ }, _callee);
2305
+ }));
2306
+ return function (_x) {
2307
+ return _ref.apply(this, arguments);
2308
+ };
2309
+ }());
2310
+ _defineProperty(this, "request", /*#__PURE__*/function () {
2311
+ var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2(options) {
2312
+ var botUrl, preparedOptions, _t;
2313
+ return _regeneratorRuntime.wrap(function (_context2) {
2314
+ while (1) switch (_context2.prev = _context2.next) {
2315
+ case 0:
2375
2316
  resty.useRes(function (result) {
2376
2317
  return result;
2377
2318
  }, function (error) {
2378
2319
  var _error$response, _error$response2;
2379
- var traceid = error === null || error === void 0 || (_error$response = error.response) === null || _error$response === void 0 || (_error$response = _error$response.headers) === null || _error$response === void 0 ? void 0 : _error$response['x-tps-trace-id'];
2320
+ var traceID = error === null || error === void 0 || (_error$response = error.response) === null || _error$response === void 0 || (_error$response = _error$response.headers) === null || _error$response === void 0 ? void 0 : _error$response['x-tps-trace-id'];
2380
2321
  if (error !== null && error !== void 0 && (_error$response2 = error.response) !== null && _error$response2 !== void 0 && _error$response2.data) {
2381
2322
  return Promise.reject(_objectSpread(_objectSpread({}, error.response.data), {}, {
2382
- traceid: traceid
2323
+ trace_id: error.response.data.trace_id || traceID
2383
2324
  }));
2384
2325
  }
2385
2326
  if (error !== null && error !== void 0 && error.response) {
2386
2327
  return Promise.reject(_objectSpread(_objectSpread({}, error.response), {}, {
2387
- traceid: traceid
2328
+ trace_id: traceID
2388
2329
  }));
2389
2330
  }
2390
2331
  return Promise.reject(error);
2391
2332
  });
2392
- client = resty.create(options);
2393
- _context.prev = 2;
2394
- _context.next = 3;
2395
- return client.request(botUrl, options);
2333
+ botUrl = buildUrl(options.url, _this.config.sandbox);
2334
+ _context2.next = 1;
2335
+ return _this.prepareOptions(options);
2336
+ case 1:
2337
+ preparedOptions = _context2.sent;
2338
+ _context2.prev = 2;
2339
+ _context2.next = 3;
2340
+ return resty.create(preparedOptions).request(botUrl, preparedOptions);
2396
2341
  case 3:
2397
- return _context.abrupt("return", _context.sent);
2342
+ return _context2.abrupt("return", _context2.sent);
2398
2343
  case 4:
2399
- _context.prev = 4;
2400
- _t = _context["catch"](2);
2401
- if (!((_t === null || _t === void 0 ? void 0 : _t.code) === 11201 || (_t === null || _t === void 0 ? void 0 : _t.err_code) === 40012001)) {
2402
- _context.next = 8;
2344
+ _context2.prev = 4;
2345
+ _t = _context2["catch"](2);
2346
+ if (!(!isAuthenticationError(_t) || _this.config.accessToken || _this.config.access_token)) {
2347
+ _context2.next = 5;
2403
2348
  break;
2404
2349
  }
2405
- console.log('检测到认证失败,尝试重试请求...');
2406
- _context.prev = 5;
2407
- // 由于addAuthorization现在是并发安全的,重试时会自动获取最新token
2408
- retryClient = resty.create(options);
2409
- _context.next = 6;
2410
- return retryClient.request(botUrl, options);
2350
+ throw _t;
2351
+ case 5:
2352
+ invalidateV2AccessToken(_this.config.appID);
2353
+ _context2.next = 6;
2354
+ return _this.prepareOptions(options, true);
2411
2355
  case 6:
2412
- return _context.abrupt("return", _context.sent);
2356
+ preparedOptions = _context2.sent;
2357
+ return _context2.abrupt("return", resty.create(preparedOptions).request(botUrl, preparedOptions));
2413
2358
  case 7:
2414
- _context.prev = 7;
2415
- _t2 = _context["catch"](5);
2416
- console.log('重试请求仍然失败:', _t2);
2417
- throw _t2;
2418
- case 8:
2419
- throw _t;
2420
- case 9:
2421
2359
  case "end":
2422
- return _context.stop();
2360
+ return _context2.stop();
2423
2361
  }
2424
- }, _callee, this, [[2, 4], [5, 7]]);
2362
+ }, _callee2, null, [[2, 4]]);
2425
2363
  }));
2426
- function request(_x) {
2427
- return _request.apply(this, arguments);
2428
- }
2429
- return request;
2430
- }()
2431
- }], [{
2364
+ return function (_x2) {
2365
+ return _ref2.apply(this, arguments);
2366
+ };
2367
+ }());
2368
+ this.config = config;
2369
+ this.guildApi = new Guild(this.request, config);
2370
+ this.channelApi = new Channel(this.request, config);
2371
+ this.meApi = new Me(this.request, config);
2372
+ this.groupApi = new Group(this.request, config);
2373
+ this.messageApi = new Message(this.request, config);
2374
+ this.memberApi = new Member(this.request, config);
2375
+ this.roleApi = new Role(this.request, config);
2376
+ this.muteApi = new Mute(this.request, config);
2377
+ this.announceApi = new Announce(this.request, config);
2378
+ this.scheduleApi = new Schedule(this.request, config);
2379
+ this.threadsApi = new Threads(this.request, config);
2380
+ this.directMessageApi = new DirectMessage(this.request, config);
2381
+ this.channelPermissionsApi = new ChannelPermissions(this.request, config);
2382
+ this.audioApi = new Audio(this.request, config);
2383
+ this.guildPermissionsApi = new GuildPermissions(this.request, config);
2384
+ this.reactionApi = new Reaction(this.request, config);
2385
+ this.interactionApi = new Interaction(this.request, config);
2386
+ this.pinsMessageApi = new PinsMessage(this.request, config);
2387
+ }
2388
+ return _createClass(OpenAPI, null, [{
2432
2389
  key: "newClient",
2433
2390
  value: function newClient(config) {
2434
2391
  return new OpenAPI(config);
2435
2392
  }
2436
2393
  }]);
2437
2394
  }();
2438
- function v1Setup() {
2439
- register(apiVersion, OpenAPI);
2440
- }
2441
2395
 
2442
2396
  // websocket建立成功回包
2443
2397
 
@@ -2778,7 +2732,7 @@ var SessionEvents = {
2778
2732
  var WsObjRequestOptions = function WsObjRequestOptions(sandbox) {
2779
2733
  return {
2780
2734
  method: 'GET',
2781
- url: buildUrl(getURL('wsInfo'), sandbox),
2735
+ url: buildUrl(getURL('gatewayBotURI'), sandbox),
2782
2736
  headers: {
2783
2737
  Accept: '*/*',
2784
2738
  'Accept-Encoding': 'utf-8',
@@ -3151,26 +3105,51 @@ var Session = /*#__PURE__*/function () {
3151
3105
  // 新建会话
3152
3106
  return _createClass(Session, [{
3153
3107
  key: "createSession",
3154
- value: function createSession() {
3155
- var _this = this;
3156
- this.ws = new Ws(this.config, this.event, this.sessionRecord || undefined);
3157
- // 拿到 ws地址等信息
3158
- var reqOptions = WsObjRequestOptions(this.config.sandbox);
3159
- addAuthorization(reqOptions.headers, this.config.appID, this.config.token, this.config.clientSecret);
3160
- resty.create(reqOptions).get(reqOptions.url, {}).then(function (r) {
3161
- var wsData = r.data;
3162
- if (!wsData) throw new Error('获取ws连接信息异常');
3163
- _this.ws.createWebsocket(wsData);
3164
- })["catch"](function (e) {
3165
- BotLogger.info('[ERROR] createSession: ', e);
3166
- _this.event.emit(SessionEvents.EVENT_WS, {
3167
- eventType: SessionEvents.DISCONNECT,
3168
- eventMsg: _this.sessionRecord
3169
- });
3170
- });
3171
- }
3172
-
3173
- // 关闭会话
3108
+ value: function () {
3109
+ var _createSession = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
3110
+ var reqOptions, response, wsData, _t;
3111
+ return _regeneratorRuntime.wrap(function (_context) {
3112
+ while (1) switch (_context.prev = _context.next) {
3113
+ case 0:
3114
+ _context.prev = 0;
3115
+ this.ws = new Ws(this.config, this.event, this.sessionRecord || undefined);
3116
+ reqOptions = WsObjRequestOptions(this.config.sandbox);
3117
+ _context.next = 1;
3118
+ return addV2Authorization(reqOptions.headers, this.config);
3119
+ case 1:
3120
+ _context.next = 2;
3121
+ return resty.create(reqOptions).get(reqOptions.url, {});
3122
+ case 2:
3123
+ response = _context.sent;
3124
+ wsData = response.data;
3125
+ if (wsData) {
3126
+ _context.next = 3;
3127
+ break;
3128
+ }
3129
+ throw new Error('获取ws连接信息异常');
3130
+ case 3:
3131
+ this.ws.createWebsocket(wsData);
3132
+ _context.next = 5;
3133
+ break;
3134
+ case 4:
3135
+ _context.prev = 4;
3136
+ _t = _context["catch"](0);
3137
+ BotLogger.info('[ERROR] createSession: ', _t);
3138
+ this.event.emit(SessionEvents.EVENT_WS, {
3139
+ eventType: SessionEvents.DISCONNECT,
3140
+ eventMsg: this.sessionRecord
3141
+ });
3142
+ case 5:
3143
+ case "end":
3144
+ return _context.stop();
3145
+ }
3146
+ }, _callee, this, [[0, 4]]);
3147
+ }));
3148
+ function createSession() {
3149
+ return _createSession.apply(this, arguments);
3150
+ }
3151
+ return createSession;
3152
+ }() // 关闭会话
3174
3153
  }, {
3175
3154
  key: "closeSession",
3176
3155
  value: function closeSession() {
@@ -3241,21 +3220,11 @@ var WebsocketClient = /*#__PURE__*/function (_EventEmitter) {
3241
3220
  }]);
3242
3221
  }(EventEmitter);
3243
3222
 
3244
- // 注册v1接口
3245
- v1Setup();
3246
- var defaultImpl = versionMapping[apiVersion];
3247
-
3248
- // SelectOpenAPIVersion 指定使用哪个版本的 api 实现,如果不指定,sdk将默认使用第一个 setup 的 api 实现
3249
- function selectOpenAPIVersion(version) {
3250
- if (!versionMapping[version]) {
3251
- return false;
3252
- }
3253
- defaultImpl = versionMapping[version];
3223
+ function createOpenAPIV1(config) {
3224
+ return OpenAPI$1.newClient(config);
3254
3225
  }
3255
-
3256
- // 如果需要使用其他版本的实现,需要在调用这个方法之前调用 SelectOpenAPIVersion 方法
3257
- function createOpenAPI(config) {
3258
- return defaultImpl.newClient(config);
3226
+ function createOpenAPIV2(config) {
3227
+ return OpenAPI.newClient(config);
3259
3228
  }
3260
3229
 
3261
3230
  // ws连接新建
@@ -3263,4 +3232,4 @@ function createWebsocket(config) {
3263
3232
  return new WebsocketClient(config);
3264
3233
  }
3265
3234
 
3266
- export { AvailableIntentsEventsEnum, IntentEvents, Intents, OpCode, SessionEvents, WSCodes, WebsocketCloseReason, WebsocketCode, WsEventType, WsObjRequestOptions, createOpenAPI, createWebsocket, selectOpenAPIVersion };
3235
+ export { AvailableIntentsEventsEnum, IntentEvents, Intents, OpCode, SessionEvents, WSCodes, WebsocketCloseReason, WebsocketCode, WsEventType, WsObjRequestOptions, createOpenAPIV1, createOpenAPIV2, createWebsocket };