mirai-js 2.2.0 → 2.4.1

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 (122) hide show
  1. package/.github/FUNDING.yml +1 -1
  2. package/README.md +17 -283
  3. package/demo.html +1 -1
  4. package/demo.js +13 -71
  5. package/dist/browser/mirai-js.js +1 -1
  6. package/dist/node/BaseType.d.ts +5 -2
  7. package/dist/node/Bot.d.ts +95 -8
  8. package/dist/node/Bot.js +233 -10
  9. package/dist/node/FileManager.js +15 -6
  10. package/dist/node/core/anno/deleteAnno.js +67 -0
  11. package/dist/node/core/anno/getAnno.js +70 -0
  12. package/dist/node/core/anno/publishAnno.js +70 -0
  13. package/dist/node/core/auth.js +9 -11
  14. package/dist/node/core/fs/deleteGroupFile.js +71 -0
  15. package/dist/node/core/fs/getGroupFileInfo.js +77 -0
  16. package/dist/node/core/fs/getGroupFileList.js +82 -0
  17. package/dist/node/core/fs/makeGroupDir.js +73 -0
  18. package/dist/node/core/fs/moveGroupFile.js +77 -0
  19. package/dist/node/core/fs/renameGroupFile.js +73 -0
  20. package/dist/node/core/fs/uploadGroupFIle.js +81 -0
  21. package/dist/node/core/getFriendList.js +9 -11
  22. package/dist/node/core/getGroupConfig.js +9 -11
  23. package/dist/node/core/getGroupFileInfo.js +6 -2
  24. package/dist/node/core/getGroupFileList.js +6 -2
  25. package/dist/node/core/getGroupList.js +9 -11
  26. package/dist/node/core/getMemberInfo.js +13 -19
  27. package/dist/node/core/getMemberList.js +9 -11
  28. package/dist/node/core/getSessionConfig.js +9 -11
  29. package/dist/node/core/getUserProfile.js +78 -0
  30. package/dist/node/core/groupFileDelete.js +6 -2
  31. package/dist/node/core/groupFileMove.js +6 -2
  32. package/dist/node/core/groupFileRename.js +6 -2
  33. package/dist/node/core/mute.js +9 -11
  34. package/dist/node/core/muteAll.js +9 -11
  35. package/dist/node/core/quitGroup.js +9 -11
  36. package/dist/node/core/recall.js +9 -11
  37. package/dist/node/core/releaseSession.js +10 -11
  38. package/dist/node/core/removeFriend.js +64 -0
  39. package/dist/node/core/removeMember.js +9 -11
  40. package/dist/node/core/responseBotInvitedJoinGroupRequest.js +9 -11
  41. package/dist/node/core/responseFirendRequest.js +9 -11
  42. package/dist/node/core/responseMemberJoinRequest.js +9 -11
  43. package/dist/node/core/sendCommand.js +9 -11
  44. package/dist/node/core/sendFirendMessage.js +9 -11
  45. package/dist/node/core/sendGroupMessage.js +9 -11
  46. package/dist/node/core/sendNudge.js +9 -11
  47. package/dist/node/core/sendTempMessage.js +9 -11
  48. package/dist/node/core/setEssence.js +9 -11
  49. package/dist/node/core/setGroupConfig.js +9 -11
  50. package/dist/node/core/setMemberAdmin.js +70 -0
  51. package/dist/node/core/setMemberInfo.js +9 -11
  52. package/dist/node/core/setSessionConfig.js +9 -11
  53. package/dist/node/core/startListeningBrowser.js +8 -9
  54. package/dist/node/core/startListeningNode.js +8 -10
  55. package/dist/node/core/stopListeningBrowser.js +5 -1
  56. package/dist/node/core/stopListeningNode.js +5 -1
  57. package/dist/node/core/unmute.js +9 -11
  58. package/dist/node/core/unmuteAll.js +9 -11
  59. package/dist/node/core/uploadFileAndSend.js +6 -1
  60. package/dist/node/core/uploadImage.js +9 -10
  61. package/dist/node/core/uploadVoice.js +9 -10
  62. package/dist/node/core/verify.js +9 -11
  63. package/dist/node/polyfill/URL.js +5 -0
  64. package/dist/node/polyfill/wsListener.js +6 -0
  65. package/package.json +2 -2
  66. package/src/BaseType.d.ts +5 -2
  67. package/src/Bot.d.ts +95 -8
  68. package/src/Bot.js +154 -9
  69. package/src/FileManager.js +10 -6
  70. package/src/core/anno/deleteAnno.js +42 -0
  71. package/src/core/anno/getAnno.js +43 -0
  72. package/src/core/anno/publishAnno.js +43 -0
  73. package/src/core/auth.js +5 -7
  74. package/src/core/fs/deleteGroupFile.js +44 -0
  75. package/src/core/fs/getGroupFileInfo.js +45 -0
  76. package/src/core/fs/getGroupFileList.js +46 -0
  77. package/src/core/fs/makeGroupDir.js +44 -0
  78. package/src/core/fs/moveGroupFile.js +46 -0
  79. package/src/core/{groupFileRename.js → fs/renameGroupFile.js} +11 -13
  80. package/src/core/{uploadFileAndSend.js → fs/uploadGroupFIle.js} +9 -11
  81. package/src/core/getFriendList.js +5 -7
  82. package/src/core/getGroupConfig.js +5 -7
  83. package/src/core/getGroupList.js +5 -7
  84. package/src/core/getMemberInfo.js +8 -10
  85. package/src/core/getMemberList.js +5 -7
  86. package/src/core/getSessionConfig.js +5 -7
  87. package/src/core/getUserProfile.js +39 -0
  88. package/src/core/mute.js +5 -7
  89. package/src/core/muteAll.js +5 -7
  90. package/src/core/quitGroup.js +5 -7
  91. package/src/core/recall.js +5 -7
  92. package/src/core/releaseSession.js +6 -7
  93. package/src/core/{groupFileDelete.js → removeFriend.js} +11 -17
  94. package/src/core/removeMember.js +5 -7
  95. package/src/core/responseBotInvitedJoinGroupRequest.js +5 -7
  96. package/src/core/responseFirendRequest.js +5 -7
  97. package/src/core/responseMemberJoinRequest.js +5 -7
  98. package/src/core/sendCommand.js +5 -7
  99. package/src/core/sendFirendMessage.js +5 -7
  100. package/src/core/sendGroupMessage.js +5 -7
  101. package/src/core/sendNudge.js +5 -7
  102. package/src/core/sendTempMessage.js +5 -7
  103. package/src/core/setEssence.js +5 -7
  104. package/src/core/setGroupConfig.js +5 -7
  105. package/src/core/setMemberAdmin.js +43 -0
  106. package/src/core/setMemberInfo.js +5 -7
  107. package/src/core/setSessionConfig.js +5 -7
  108. package/src/core/startListeningBrowser.js +4 -6
  109. package/src/core/startListeningNode.js +4 -6
  110. package/src/core/stopListeningBrowser.js +3 -0
  111. package/src/core/stopListeningNode.js +3 -0
  112. package/src/core/unmute.js +5 -7
  113. package/src/core/unmuteAll.js +5 -7
  114. package/src/core/uploadImage.js +5 -7
  115. package/src/core/uploadVoice.js +5 -7
  116. package/src/core/verify.js +5 -7
  117. package/src/polyfill/URL.js +3 -0
  118. package/src/polyfill/wsListener.js +4 -0
  119. package/webpack.config.js +4 -0
  120. package/src/core/getGroupFileInfo.js +0 -44
  121. package/src/core/getGroupFileList.js +0 -40
  122. package/src/core/groupFileMove.js +0 -46
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+
3
+ const {
4
+ errCodeMap
5
+ } = require('../../util/errCode');
6
+
7
+ const axios = require('axios').default;
8
+
9
+ const {
10
+ URL
11
+ } = require('../../polyfill/URL');
12
+
13
+ const errorHandler = require('../../util/errorHandler');
14
+
15
+ const path = require('path');
16
+
17
+ const locationStr = `core.${path.basename(__filename, path.extname(__filename))}`;
18
+ /**
19
+ * @description 获取群文件详细信息
20
+ * @param {string} baseUrl mirai-api-http server 的地址
21
+ * @param {string} sessionKey 会话标识
22
+ * @param {string} id 文件夹id, 空串为根目录
23
+ * @param {string} path 文件夹路径, 文件夹允许重名, 不保证准确, 准确定位使用 id
24
+ * @param {number} group 群号
25
+ * @param {boolean} withDownloadInfo 是否携带下载信息,额外请求,无必要不要携带
26
+ * @returns {Object}
27
+ * 结构 { id, name, path, parent, contact, isFile, isDirectory, downloadInfo }
28
+ */
29
+
30
+ module.exports = async ({
31
+ baseUrl,
32
+ sessionKey,
33
+ id,
34
+ path,
35
+ group
36
+ /*, qq 字段保留 */
37
+ ,
38
+ withDownloadInfo
39
+ }) => {
40
+ try {
41
+ // 拼接 url
42
+ const url = new URL('/file/info', baseUrl).toString(); // 请求
43
+
44
+ const responseData = await axios.get(url, {
45
+ params: {
46
+ sessionKey,
47
+ id,
48
+ path,
49
+ target: group,
50
+ group,
51
+ withDownloadInfo
52
+ }
53
+ });
54
+
55
+ try {
56
+ var {
57
+ data: {
58
+ msg: message,
59
+ code,
60
+ data
61
+ }
62
+ } = responseData;
63
+ } catch (error) {
64
+ throw new Error('请求返回格式出错,请检查 mirai-console');
65
+ } // 抛出 mirai 的异常,到 catch 中处理后再抛出
66
+
67
+
68
+ if (code in errCodeMap) {
69
+ throw new Error(message);
70
+ }
71
+
72
+ return data;
73
+ } catch (error) {
74
+ console.error(`mirai-js: error ${locationStr}`);
75
+ errorHandler(error);
76
+ }
77
+ };
@@ -0,0 +1,82 @@
1
+ "use strict";
2
+
3
+ const {
4
+ errCodeMap
5
+ } = require('../../util/errCode');
6
+
7
+ const axios = require('axios').default;
8
+
9
+ const {
10
+ URL
11
+ } = require('../../polyfill/URL');
12
+
13
+ const errorHandler = require('../../util/errorHandler');
14
+
15
+ const path = require('path');
16
+
17
+ const locationStr = `core.${path.basename(__filename, path.extname(__filename))}`;
18
+ /**
19
+ * @description 获取群文件列表
20
+ * @param {string} baseUrl mirai-api-http server 的地址
21
+ * @param {string} sessionKey 会话标识
22
+ * @param {string} id 文件夹id, 空串为根目录
23
+ * @param {string} path 文件夹路径, 文件夹允许重名, 不保证准确, 准确定位使用 id
24
+ * @param {number} group 群号
25
+ * @param {boolern} withDownloadInfo 是否携带下载信息,额外请求,无必要不要携带
26
+ * @param {number} offset 分页偏移
27
+ * @param {number} size 分页大小
28
+ * @returns {Object[]} 结构 array[...{ id, name, path, parent, contact, isFile, isDirectory, downloadInfo }]
29
+ */
30
+
31
+ module.exports = async ({
32
+ baseUrl,
33
+ sessionKey,
34
+ id,
35
+ path,
36
+ group
37
+ /*, qq 字段保留 */
38
+ ,
39
+ withDownloadInfo,
40
+ offset,
41
+ size
42
+ }) => {
43
+ try {
44
+ // 拼接 url
45
+ const url = new URL('/file/list', baseUrl).toString(); // 请求
46
+
47
+ const responseData = await axios.get(url, {
48
+ params: {
49
+ sessionKey,
50
+ id,
51
+ path,
52
+ target: group,
53
+ group,
54
+ withDownloadInfo,
55
+ offset,
56
+ size
57
+ }
58
+ });
59
+
60
+ try {
61
+ var {
62
+ data: {
63
+ msg: message,
64
+ code,
65
+ data
66
+ }
67
+ } = responseData;
68
+ } catch (error) {
69
+ throw new Error('请求返回格式出错,请检查 mirai-console');
70
+ } // 抛出 mirai 的异常,到 catch 中处理后再抛出
71
+
72
+
73
+ if (code in errCodeMap) {
74
+ throw new Error(message);
75
+ }
76
+
77
+ return data;
78
+ } catch (error) {
79
+ console.error(`mirai-js: error ${locationStr}`);
80
+ errorHandler(error);
81
+ }
82
+ };
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+
3
+ const {
4
+ errCodeMap
5
+ } = require('../../util/errCode');
6
+
7
+ const axios = require('axios');
8
+
9
+ const {
10
+ URL
11
+ } = require('../../polyfill/URL');
12
+
13
+ const errorHandler = require('../../util/errorHandler');
14
+
15
+ const path = require('path');
16
+
17
+ const locationStr = `core.${path.basename(__filename, path.extname(__filename))}`;
18
+ /**
19
+ * @description 新建群文件夹
20
+ * @param {string} baseUrl mirai-api-http server 的地址
21
+ * @param {string} sessionKey 会话标识
22
+ * @param {string} id 文件夹id, 空串为根目录
23
+ * @param {string} path 文件夹路径, 文件夹允许重名, 不保证准确, 准确定位使用 id
24
+ * @param {number} group 群号
25
+ * @param {boolern} withDownloadInfo 是否携带下载信息,额外请求,无必要不要携带
26
+ * @returns {Object} 结构 { id, name, path, parent, contact, isFile, isDirectory, downloadInfo }
27
+ */
28
+
29
+ module.exports = async ({
30
+ baseUrl,
31
+ sessionKey,
32
+ id,
33
+ rename,
34
+ path,
35
+ group,
36
+ withDownloadInfo
37
+ }) => {
38
+ try {
39
+ // 拼接 url
40
+ const url = new URL('/file/mkdir', baseUrl).toString(); // 请求
41
+
42
+ const responseData = await axios.post(url, {
43
+ sessionKey,
44
+ id,
45
+ rename,
46
+ path,
47
+ group,
48
+ withDownloadInfo
49
+ });
50
+
51
+ try {
52
+ var {
53
+ data: {
54
+ msg: message,
55
+ code,
56
+ data
57
+ }
58
+ } = responseData;
59
+ } catch (error) {
60
+ throw new Error('请求返回格式出错,请检查 mirai-console');
61
+ } // 抛出 mirai 的异常,到 catch 中处理后再抛出
62
+
63
+
64
+ if (code in errCodeMap) {
65
+ throw new Error(message);
66
+ }
67
+
68
+ return data;
69
+ } catch (error) {
70
+ console.error(`mirai-js: error ${locationStr}`);
71
+ errorHandler(error);
72
+ }
73
+ };
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+
3
+ const {
4
+ errCodeMap
5
+ } = require('../../util/errCode');
6
+
7
+ const axios = require('axios');
8
+
9
+ const {
10
+ URL
11
+ } = require('../../polyfill/URL');
12
+
13
+ const errorHandler = require('../../util/errorHandler');
14
+
15
+ const path = require('path');
16
+
17
+ const locationStr = `core.${path.basename(__filename, path.extname(__filename))}`;
18
+ /**
19
+ * @description 移动群文件
20
+ * @param {string} baseUrl mirai-api-http server 的地址
21
+ * @param {string} sessionKey 会话标识
22
+ * @param {string} id 文件夹id, 空串为根目录
23
+ * @param {string} path 文件夹路径, 文件夹允许重名, 不保证准确, 准确定位使用 id
24
+ * @param {number} group 群号
25
+ * @param {string} moveTo 移动目标文件夹id
26
+ * @param {string} moveToPath 移动目标文件夹path
27
+ * @returns {Object} 结构 { message, code }
28
+ */
29
+
30
+ module.exports = async ({
31
+ baseUrl,
32
+ sessionKey,
33
+ id,
34
+ path,
35
+ group,
36
+ moveTo,
37
+ moveToPath
38
+ }) => {
39
+ try {
40
+ // 拼接 url
41
+ const url = new URL('/file/move', baseUrl).toString(); // 请求
42
+
43
+ const responseData = await axios.post(url, {
44
+ sessionKey,
45
+ id,
46
+ path,
47
+ target: group,
48
+ group,
49
+ moveTo,
50
+ moveToPath
51
+ });
52
+
53
+ try {
54
+ var {
55
+ data: {
56
+ msg: message,
57
+ code
58
+ }
59
+ } = responseData;
60
+ } catch (error) {
61
+ throw new Error('请求返回格式出错,请检查 mirai-console');
62
+ } // 抛出 mirai 的异常,到 catch 中处理后再抛出
63
+
64
+
65
+ if (code in errCodeMap) {
66
+ throw new Error(message);
67
+ }
68
+
69
+ return {
70
+ message,
71
+ code
72
+ };
73
+ } catch (error) {
74
+ console.error(`mirai-js: error ${locationStr}`);
75
+ errorHandler(error);
76
+ }
77
+ };
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+
3
+ const {
4
+ errCodeMap
5
+ } = require('../../util/errCode');
6
+
7
+ const axios = require('axios');
8
+
9
+ const {
10
+ URL
11
+ } = require('../../polyfill/URL');
12
+
13
+ const errorHandler = require('../../util/errorHandler');
14
+
15
+ const path = require('path');
16
+
17
+ const locationStr = `core.${path.basename(__filename, path.extname(__filename))}`;
18
+ /**
19
+ * @description 重命名群文件
20
+ * @param {string} baseUrl mirai-api-http server 的地址
21
+ * @param {string} sessionKey 会话标识
22
+ * @param {number} id 文件 id
23
+ * @param {number} group 群号
24
+ * @param {string} rename 重命名
25
+ * @returns {Object} 结构 { message, code }
26
+ */
27
+
28
+ module.exports = async ({
29
+ baseUrl,
30
+ sessionKey,
31
+ id,
32
+ path,
33
+ group,
34
+ renameTo
35
+ }) => {
36
+ try {
37
+ // 拼接 url
38
+ const url = new URL('/file/rename', baseUrl).toString(); // 请求
39
+
40
+ const responseData = await axios.post(url, {
41
+ sessionKey,
42
+ id,
43
+ path,
44
+ target: group,
45
+ group,
46
+ renameTo
47
+ });
48
+
49
+ try {
50
+ var {
51
+ data: {
52
+ msg: message,
53
+ code
54
+ }
55
+ } = responseData;
56
+ } catch (error) {
57
+ throw new Error('请求返回格式出错,请检查 mirai-console');
58
+ } // 抛出 mirai 的异常,到 catch 中处理后再抛出
59
+
60
+
61
+ if (code in errCodeMap) {
62
+ throw new Error(message);
63
+ }
64
+
65
+ return {
66
+ message,
67
+ code
68
+ };
69
+ } catch (error) {
70
+ console.error(`mirai-js: error ${locationStr}`);
71
+ errorHandler(error);
72
+ }
73
+ };
@@ -0,0 +1,81 @@
1
+ "use strict";
2
+
3
+ const {
4
+ errCodeMap
5
+ } = require('../../util/errCode');
6
+
7
+ const axios = require('axios').default;
8
+
9
+ const {
10
+ URL
11
+ } = require('../../polyfill/URL');
12
+
13
+ const errorHandler = require('../../util/errorHandler');
14
+
15
+ const path = require('path');
16
+
17
+ const locationStr = `core.${path.basename(__filename, path.extname(__filename))}`;
18
+
19
+ const FormData = require('form-data');
20
+ /**
21
+ * @description 上传文件至服务器并发送,返回文件 id
22
+ * @param {string} baseUrl mirai-api-http server 的地址
23
+ * @param {string} sessionKey 会话标识
24
+ * @param {string} type "friend" 或 "group",目前仅支持 group
25
+ * @param {string} target 群/好友号
26
+ * @param {string} path 上传目录id
27
+ * @param {Buffer} file 文件二进制数据
28
+ * @returns {string} 文件 id
29
+ */
30
+
31
+
32
+ module.exports = async ({
33
+ baseUrl,
34
+ sessionKey,
35
+ type,
36
+ target,
37
+ path,
38
+ file
39
+ }) => {
40
+ try {
41
+ // 拼接 url
42
+ const targetUrl = new URL('/file/upload', baseUrl).toString(); // 构造 fromdata
43
+
44
+ const form = new FormData();
45
+ form.append('sessionKey', sessionKey);
46
+ form.append('type', type);
47
+ form.append('target', target);
48
+ form.append('path', path);
49
+ form.append('file', file, {
50
+ filename: 'payload'
51
+ }); // 请求
52
+
53
+ const responseData = await axios.post(targetUrl, form, {
54
+ // formdata.getHeaders 将会指定 content-type,同时给定随
55
+ // 机生成的 boundary,即分隔符,用以分隔多个表单项而不会造成混乱
56
+ headers: form.getHeaders()
57
+ });
58
+
59
+ try {
60
+ var {
61
+ data: {
62
+ msg: message,
63
+ code,
64
+ id
65
+ }
66
+ } = responseData;
67
+ } catch (error) {
68
+ throw new Error('请求返回格式出错,请检查 mirai-console');
69
+ } // 抛出 mirai 的异常,到 catch 中处理后再抛出
70
+
71
+
72
+ if (code in errCodeMap) {
73
+ throw new Error(message);
74
+ }
75
+
76
+ return id;
77
+ } catch (error) {
78
+ console.error(`mirai-js: error ${locationStr}`);
79
+ errorHandler(error);
80
+ }
81
+ };
@@ -6,17 +6,15 @@ const {
6
6
 
7
7
  const axios = require('axios').default;
8
8
 
9
- let URL;
10
-
11
- if (!process.browser) {
12
- ({
13
- URL
14
- } = require('url'));
15
- } else {
16
- URL = window.URL;
17
- }
9
+ const {
10
+ URL
11
+ } = require('../polyfill/URL');
18
12
 
19
13
  const errorHandler = require('../util/errorHandler');
14
+
15
+ const path = require('path');
16
+
17
+ const locationStr = `core.${path.basename(__filename, path.extname(__filename))}`;
20
18
  /**
21
19
  * @description 获取好友列表
22
20
  * @param {string} baseUrl mirai-api-http server 的地址
@@ -24,7 +22,6 @@ const errorHandler = require('../util/errorHandler');
24
22
  * @returns {Object[]} 结构 array[...{ id, nickname, remark }]
25
23
  */
26
24
 
27
-
28
25
  module.exports = async ({
29
26
  baseUrl,
30
27
  sessionKey
@@ -48,7 +45,7 @@ module.exports = async ({
48
45
  }
49
46
  } = responseData;
50
47
  } catch (error) {
51
- throw new Error('core.getFriendList 请求返回格式出错,请检查 mirai-console');
48
+ throw new Error('请求返回格式出错,请检查 mirai-console');
52
49
  } // 抛出 mirai 的异常,到 catch 中处理后再抛出
53
50
 
54
51
 
@@ -58,6 +55,7 @@ module.exports = async ({
58
55
 
59
56
  return data;
60
57
  } catch (error) {
58
+ console.error(`mirai-js: error ${locationStr}`);
61
59
  errorHandler(error);
62
60
  }
63
61
  };
@@ -6,17 +6,15 @@ const {
6
6
 
7
7
  const axios = require('axios').default;
8
8
 
9
- let URL;
10
-
11
- if (!process.browser) {
12
- ({
13
- URL
14
- } = require('url'));
15
- } else {
16
- URL = window.URL;
17
- }
9
+ const {
10
+ URL
11
+ } = require('../polyfill/URL');
18
12
 
19
13
  const errorHandler = require('../util/errorHandler');
14
+
15
+ const path = require('path');
16
+
17
+ const locationStr = `core.${path.basename(__filename, path.extname(__filename))}`;
20
18
  /**
21
19
  * @description 获取群配置
22
20
  * @param {string} baseUrl mirai-api-http server 的地址
@@ -25,7 +23,6 @@ const errorHandler = require('../util/errorHandler');
25
23
  * @returns {Object}
26
24
  */
27
25
 
28
-
29
26
  module.exports = async ({
30
27
  baseUrl,
31
28
  sessionKey,
@@ -51,7 +48,7 @@ module.exports = async ({
51
48
  }
52
49
  } = responseData;
53
50
  } catch (error) {
54
- throw new Error('core.getGroupConfig 请求返回格式出错,请检查 mirai-console');
51
+ throw new Error('请求返回格式出错,请检查 mirai-console');
55
52
  } // 抛出 mirai 的异常,到 catch 中处理后再抛出
56
53
 
57
54
 
@@ -61,6 +58,7 @@ module.exports = async ({
61
58
 
62
59
  return data;
63
60
  } catch (error) {
61
+ console.error(`mirai-js: error ${locationStr}`);
64
62
  errorHandler(error);
65
63
  }
66
64
  };
@@ -17,6 +17,10 @@ if (!process.browser) {
17
17
  }
18
18
 
19
19
  const errorHandler = require('../util/errorHandler');
20
+
21
+ const path = require('path');
22
+
23
+ const locationStr = `core.${path.basename(__filename, path.extname(__filename))}`;
20
24
  /**
21
25
  * @description 获取群文件详细信息
22
26
  * @param {string} baseUrl mirai-api-http server 的地址
@@ -30,7 +34,6 @@ const errorHandler = require('../util/errorHandler');
30
34
  * }
31
35
  */
32
36
 
33
-
34
37
  module.exports = async ({
35
38
  baseUrl,
36
39
  sessionKey,
@@ -58,7 +61,7 @@ module.exports = async ({
58
61
  }
59
62
  } = responseData;
60
63
  } catch (error) {
61
- throw new Error('core.getGroupFileInfo 请求返回格式出错,请检查 mirai-console');
64
+ throw new Error('请求返回格式出错,请检查 mirai-console');
62
65
  } // 抛出 mirai 的异常,到 catch 中处理后再抛出
63
66
 
64
67
 
@@ -68,6 +71,7 @@ module.exports = async ({
68
71
 
69
72
  return data;
70
73
  } catch (error) {
74
+ console.error(`mirai-js: error ${locationStr}`);
71
75
  errorHandler(error);
72
76
  }
73
77
  };
@@ -17,6 +17,10 @@ if (!process.browser) {
17
17
  }
18
18
 
19
19
  const errorHandler = require('../util/errorHandler');
20
+
21
+ const path = require('path');
22
+
23
+ const locationStr = `core.${path.basename(__filename, path.extname(__filename))}`;
20
24
  /**
21
25
  * @description 获取群文件列表
22
26
  * @param {string} baseUrl mirai-api-http server 的地址
@@ -26,7 +30,6 @@ const errorHandler = require('../util/errorHandler');
26
30
  * @returns {Object[]} 结构 array[...{ id, name, path, isFile }]
27
31
  */
28
32
 
29
-
30
33
  module.exports = async ({
31
34
  baseUrl,
32
35
  sessionKey,
@@ -54,7 +57,7 @@ module.exports = async ({
54
57
  }
55
58
  } = responseData;
56
59
  } catch (error) {
57
- throw new Error('core.getGroupFileList 请求返回格式出错,请检查 mirai-console');
60
+ throw new Error('请求返回格式出错,请检查 mirai-console');
58
61
  } // 抛出 mirai 的异常,到 catch 中处理后再抛出
59
62
 
60
63
 
@@ -64,6 +67,7 @@ module.exports = async ({
64
67
 
65
68
  return data;
66
69
  } catch (error) {
70
+ console.error(`mirai-js: error ${locationStr}`);
67
71
  errorHandler(error);
68
72
  }
69
73
  };
@@ -6,17 +6,15 @@ const {
6
6
 
7
7
  const axios = require('axios').default;
8
8
 
9
- let URL;
10
-
11
- if (!process.browser) {
12
- ({
13
- URL
14
- } = require('url'));
15
- } else {
16
- URL = window.URL;
17
- }
9
+ const {
10
+ URL
11
+ } = require('../polyfill/URL');
18
12
 
19
13
  const errorHandler = require('../util/errorHandler');
14
+
15
+ const path = require('path');
16
+
17
+ const locationStr = `core.${path.basename(__filename, path.extname(__filename))}`;
20
18
  /**
21
19
  * @description 获取群列表
22
20
  * @param {string} baseUrl mirai-api-http server 的地址
@@ -24,7 +22,6 @@ const errorHandler = require('../util/errorHandler');
24
22
  * @returns {Object[]} 结构 array[...{ id, name, permission }]
25
23
  */
26
24
 
27
-
28
25
  module.exports = async ({
29
26
  baseUrl,
30
27
  sessionKey
@@ -48,7 +45,7 @@ module.exports = async ({
48
45
  }
49
46
  } = responseData;
50
47
  } catch (error) {
51
- throw new Error('core.getGroupList 请求返回格式出错,请检查 mirai-console');
48
+ throw new Error('请求返回格式出错,请检查 mirai-console');
52
49
  } // 抛出 mirai 的异常,到 catch 中处理后再抛出
53
50
 
54
51
 
@@ -58,6 +55,7 @@ module.exports = async ({
58
55
 
59
56
  return data;
60
57
  } catch (error) {
58
+ console.error(`mirai-js: error ${locationStr}`);
61
59
  errorHandler(error);
62
60
  }
63
61
  };