mirai-js 2.1.0 → 2.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (130) hide show
  1. package/.eslintrc.json +45 -45
  2. package/.github/FUNDING.yml +12 -12
  3. package/.github/dependabot.yml +14 -14
  4. package/.github/workflows/codeql-analysis.yml +70 -0
  5. package/.husky/pre-commit +5 -5
  6. package/LICENSE +661 -661
  7. package/README.md +17 -283
  8. package/demo.html +1 -1
  9. package/demo.js +14 -92
  10. package/dist/browser/mirai-js.js +1 -1
  11. package/dist/node/BaseType.d.ts +3 -0
  12. package/dist/node/Bot.d.ts +95 -8
  13. package/dist/node/Bot.js +241 -18
  14. package/dist/node/FileManager.js +15 -6
  15. package/dist/node/Middleware.js +90 -16
  16. package/dist/node/core/anno/deleteAnno.js +67 -0
  17. package/dist/node/core/anno/getAnno.js +70 -0
  18. package/dist/node/core/anno/publishAnno.js +70 -0
  19. package/dist/node/core/auth.js +9 -11
  20. package/dist/node/core/fs/deleteGroupFile.js +71 -0
  21. package/dist/node/core/fs/getGroupFileInfo.js +77 -0
  22. package/dist/node/core/fs/getGroupFileList.js +82 -0
  23. package/dist/node/core/fs/makeGroupDir.js +73 -0
  24. package/dist/node/core/fs/moveGroupFile.js +77 -0
  25. package/dist/node/core/fs/renameGroupFile.js +73 -0
  26. package/dist/node/core/fs/uploadGroupFIle.js +81 -0
  27. package/dist/node/core/getFriendList.js +9 -11
  28. package/dist/node/core/getGroupConfig.js +9 -11
  29. package/dist/node/core/getGroupFileInfo.js +6 -2
  30. package/dist/node/core/getGroupFileList.js +6 -2
  31. package/dist/node/core/getGroupList.js +9 -11
  32. package/dist/node/core/getMemberInfo.js +13 -19
  33. package/dist/node/core/getMemberList.js +9 -11
  34. package/dist/node/core/getSessionConfig.js +9 -11
  35. package/dist/node/core/getUserProfile.js +78 -0
  36. package/dist/node/core/groupFileDelete.js +6 -2
  37. package/dist/node/core/groupFileMove.js +6 -2
  38. package/dist/node/core/groupFileRename.js +6 -2
  39. package/dist/node/core/mute.js +9 -11
  40. package/dist/node/core/muteAll.js +9 -11
  41. package/dist/node/core/quitGroup.js +9 -11
  42. package/dist/node/core/recall.js +9 -11
  43. package/dist/node/core/releaseSession.js +10 -11
  44. package/dist/node/core/removeFriend.js +64 -0
  45. package/dist/node/core/removeMember.js +9 -11
  46. package/dist/node/core/responseBotInvitedJoinGroupRequest.js +9 -11
  47. package/dist/node/core/responseFirendRequest.js +9 -11
  48. package/dist/node/core/responseMemberJoinRequest.js +9 -11
  49. package/dist/node/core/sendCommand.js +9 -11
  50. package/dist/node/core/sendFirendMessage.js +9 -11
  51. package/dist/node/core/sendGroupMessage.js +9 -11
  52. package/dist/node/core/sendNudge.js +9 -11
  53. package/dist/node/core/sendTempMessage.js +9 -11
  54. package/dist/node/core/setEssence.js +9 -11
  55. package/dist/node/core/setGroupConfig.js +9 -11
  56. package/dist/node/core/setMemberAdmin.js +70 -0
  57. package/dist/node/core/setMemberInfo.js +9 -11
  58. package/dist/node/core/setSessionConfig.js +9 -11
  59. package/dist/node/core/startListeningBrowser.js +8 -9
  60. package/dist/node/core/startListeningNode.js +8 -10
  61. package/dist/node/core/stopListeningBrowser.js +5 -1
  62. package/dist/node/core/stopListeningNode.js +5 -1
  63. package/dist/node/core/unmute.js +9 -11
  64. package/dist/node/core/unmuteAll.js +9 -11
  65. package/dist/node/core/uploadFileAndSend.js +6 -1
  66. package/dist/node/core/uploadImage.js +9 -10
  67. package/dist/node/core/uploadVoice.js +9 -10
  68. package/dist/node/core/verify.js +9 -11
  69. package/dist/node/polyfill/URL.js +5 -0
  70. package/dist/node/polyfill/wsListener.js +6 -0
  71. package/docs/checkDocShouldBuild.sh +4 -4
  72. package/package.json +51 -51
  73. package/src/BaseType.d.ts +3 -0
  74. package/src/Bot.d.ts +95 -8
  75. package/src/Bot.js +154 -9
  76. package/src/FileManager.js +10 -6
  77. package/src/Middleware.js +51 -3
  78. package/src/core/anno/deleteAnno.js +42 -0
  79. package/src/core/anno/getAnno.js +43 -0
  80. package/src/core/anno/publishAnno.js +43 -0
  81. package/src/core/auth.js +5 -7
  82. package/src/core/fs/deleteGroupFile.js +44 -0
  83. package/src/core/fs/getGroupFileInfo.js +45 -0
  84. package/src/core/fs/getGroupFileList.js +46 -0
  85. package/src/core/fs/makeGroupDir.js +44 -0
  86. package/src/core/fs/moveGroupFile.js +46 -0
  87. package/src/core/{groupFileRename.js → fs/renameGroupFile.js} +11 -13
  88. package/src/core/{uploadFileAndSend.js → fs/uploadGroupFIle.js} +9 -11
  89. package/src/core/getFriendList.js +5 -7
  90. package/src/core/getGroupConfig.js +5 -7
  91. package/src/core/getGroupList.js +5 -7
  92. package/src/core/getMemberInfo.js +8 -10
  93. package/src/core/getMemberList.js +5 -7
  94. package/src/core/getSessionConfig.js +5 -7
  95. package/src/core/getUserProfile.js +39 -0
  96. package/src/core/mute.js +5 -7
  97. package/src/core/muteAll.js +5 -7
  98. package/src/core/quitGroup.js +5 -7
  99. package/src/core/recall.js +5 -7
  100. package/src/core/releaseSession.js +6 -7
  101. package/src/core/{groupFileDelete.js → removeFriend.js} +11 -17
  102. package/src/core/removeMember.js +5 -7
  103. package/src/core/responseBotInvitedJoinGroupRequest.js +5 -7
  104. package/src/core/responseFirendRequest.js +5 -7
  105. package/src/core/responseMemberJoinRequest.js +5 -7
  106. package/src/core/sendCommand.js +5 -7
  107. package/src/core/sendFirendMessage.js +5 -7
  108. package/src/core/sendGroupMessage.js +5 -7
  109. package/src/core/sendNudge.js +5 -7
  110. package/src/core/sendTempMessage.js +5 -7
  111. package/src/core/setEssence.js +5 -7
  112. package/src/core/setGroupConfig.js +5 -7
  113. package/src/core/setMemberAdmin.js +43 -0
  114. package/src/core/setMemberInfo.js +5 -7
  115. package/src/core/setSessionConfig.js +5 -7
  116. package/src/core/startListeningBrowser.js +4 -6
  117. package/src/core/startListeningNode.js +4 -6
  118. package/src/core/stopListeningBrowser.js +3 -0
  119. package/src/core/stopListeningNode.js +3 -0
  120. package/src/core/unmute.js +5 -7
  121. package/src/core/unmuteAll.js +5 -7
  122. package/src/core/uploadImage.js +5 -7
  123. package/src/core/uploadVoice.js +5 -7
  124. package/src/core/verify.js +5 -7
  125. package/src/polyfill/URL.js +3 -0
  126. package/src/polyfill/wsListener.js +4 -0
  127. package/webpack.config.js +4 -0
  128. package/src/core/getGroupFileInfo.js +0 -44
  129. package/src/core/getGroupFileList.js +0 -40
  130. package/src/core/groupFileMove.js +0 -46
@@ -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
  };
@@ -6,27 +6,24 @@ const {
6
6
 
7
7
  const axios = require('axios');
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 的地址
23
21
  * @param {string} sessionKey 会话标识
24
22
  * @param {number} target 群成员所在群号
25
23
  * @param {number} memberId 群成员的 qq 号
26
- * @returns {Object} 结构 { name, specialTitle } 群名片和群头衔
24
+ * @returns {Object}
27
25
  */
28
26
 
29
-
30
27
  module.exports = async ({
31
28
  baseUrl,
32
29
  sessionKey,
@@ -47,15 +44,14 @@ module.exports = async ({
47
44
 
48
45
  try {
49
46
  var {
47
+ data,
50
48
  data: {
51
49
  msg: message,
52
- code,
53
- name,
54
- specialTitle
50
+ code
55
51
  }
56
52
  } = responseData;
57
53
  } catch (error) {
58
- throw new Error('core.getMemberInfo 请求返回格式出错,请检查 mirai-console');
54
+ throw new Error('请求返回格式出错,请检查 mirai-console');
59
55
  } // 抛出 mirai 的异常,到 catch 中处理后再抛出
60
56
 
61
57
 
@@ -63,11 +59,9 @@ module.exports = async ({
63
59
  throw new Error(message);
64
60
  }
65
61
 
66
- return {
67
- name,
68
- specialTitle
69
- };
62
+ return data;
70
63
  } catch (error) {
64
+ console.error(`mirai-js: error ${locationStr}`);
71
65
  errorHandler(error);
72
66
  }
73
67
  };
@@ -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 的地址
@@ -31,7 +29,6 @@ const errorHandler = require('../util/errorHandler');
31
29
  * }]
32
30
  */
33
31
 
34
-
35
32
  module.exports = async ({
36
33
  baseUrl,
37
34
  sessionKey,
@@ -57,7 +54,7 @@ module.exports = async ({
57
54
  }
58
55
  } = responseData;
59
56
  } catch (error) {
60
- throw new Error('core.getMemberList 请求返回格式出错,请检查 mirai-console');
57
+ throw new Error('请求返回格式出错,请检查 mirai-console');
61
58
  } // 抛出 mirai 的异常,到 catch 中处理后再抛出
62
59
 
63
60
 
@@ -67,6 +64,7 @@ module.exports = async ({
67
64
 
68
65
  return data;
69
66
  } catch (error) {
67
+ console.error(`mirai-js: error ${locationStr}`);
70
68
  errorHandler(error);
71
69
  }
72
70
  };
@@ -6,17 +6,15 @@ const {
6
6
 
7
7
  const axios = require('axios');
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 获取指定 session 的 config
22
20
  * @param {string} baseUrl mirai-api-http server 的地址
@@ -24,7 +22,6 @@ const errorHandler = require('../util/errorHandler');
24
22
  * @returns {Object} 结构 { cacheSize, enableWebsocket }
25
23
  */
26
24
 
27
-
28
25
  module.exports = async ({
29
26
  baseUrl,
30
27
  sessionKey
@@ -51,7 +48,7 @@ module.exports = async ({
51
48
  }
52
49
  } = responseData;
53
50
  } catch (error) {
54
- throw new Error('core.getSessionConfig 请求返回格式出错,请检查 mirai-console');
51
+ throw new Error('请求返回格式出错,请检查 mirai-console');
55
52
  } // 抛出 mirai 的异常,到 catch 中处理后再抛出
56
53
 
57
54
 
@@ -64,6 +61,7 @@ module.exports = async ({
64
61
  enableWebsocket
65
62
  };
66
63
  } catch (error) {
64
+ console.error(`mirai-js: error ${locationStr}`);
67
65
  errorHandler(error);
68
66
  }
69
67
  };
@@ -0,0 +1,78 @@
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} target qq 号
23
+ * @returns {Object} 结构 { nickname, email, age, level, sign, sex }
24
+ */
25
+
26
+ module.exports = async ({
27
+ baseUrl,
28
+ sessionKey,
29
+ target,
30
+ memberId
31
+ }) => {
32
+ try {
33
+ // 拼接 url
34
+ const url = new URL('/userProfile', baseUrl).toString(); // 请求
35
+
36
+ const responseData = await axios.get(url, {
37
+ params: {
38
+ sessionKey,
39
+ target,
40
+ memberId
41
+ }
42
+ });
43
+
44
+ try {
45
+ var {
46
+ data: {
47
+ msg: message,
48
+ code,
49
+ nickname,
50
+ email,
51
+ age,
52
+ level,
53
+ sign,
54
+ sex
55
+ }
56
+ } = responseData;
57
+ } catch (error) {
58
+ throw new Error('请求返回格式出错,请检查 mirai-console');
59
+ } // 抛出 mirai 的异常,到 catch 中处理后再抛出
60
+
61
+
62
+ if (code in errCodeMap) {
63
+ throw new Error(message);
64
+ }
65
+
66
+ return {
67
+ nickname,
68
+ email,
69
+ age,
70
+ level,
71
+ sign,
72
+ sex
73
+ };
74
+ } catch (error) {
75
+ console.error(`mirai-js: error ${locationStr}`);
76
+ errorHandler(error);
77
+ }
78
+ };
@@ -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} 结构 { message, code }
27
31
  */
28
32
 
29
-
30
33
  module.exports = async ({
31
34
  baseUrl,
32
35
  sessionKey,
@@ -51,7 +54,7 @@ module.exports = async ({
51
54
  }
52
55
  } = responseData;
53
56
  } catch (error) {
54
- throw new Error('core.groupFileDelete 请求返回格式出错,请检查 mirai-console');
57
+ throw new Error('请求返回格式出错,请检查 mirai-console');
55
58
  } // 抛出 mirai 的异常,到 catch 中处理后再抛出
56
59
 
57
60
 
@@ -64,6 +67,7 @@ module.exports = async ({
64
67
  code
65
68
  };
66
69
  } catch (error) {
70
+ console.error(`mirai-js: error ${locationStr}`);
67
71
  errorHandler(error);
68
72
  }
69
73
  };
@@ -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 的地址
@@ -27,7 +31,6 @@ const errorHandler = require('../util/errorHandler');
27
31
  * @returns {Object} 结构 { message, code }
28
32
  */
29
33
 
30
-
31
34
  module.exports = async ({
32
35
  baseUrl,
33
36
  sessionKey,
@@ -54,7 +57,7 @@ module.exports = async ({
54
57
  }
55
58
  } = responseData;
56
59
  } catch (error) {
57
- throw new Error('core.groupFileRename 请求返回格式出错,请检查 mirai-console');
60
+ throw new Error('请求返回格式出错,请检查 mirai-console');
58
61
  } // 抛出 mirai 的异常,到 catch 中处理后再抛出
59
62
 
60
63
 
@@ -67,6 +70,7 @@ module.exports = async ({
67
70
  code
68
71
  };
69
72
  } catch (error) {
73
+ console.error(`mirai-js: error ${locationStr}`);
70
74
  errorHandler(error);
71
75
  }
72
76
  };
@@ -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 的地址
@@ -27,7 +31,6 @@ const errorHandler = require('../util/errorHandler');
27
31
  * @returns {Object} 结构 { message, code }
28
32
  */
29
33
 
30
-
31
34
  module.exports = async ({
32
35
  baseUrl,
33
36
  sessionKey,
@@ -54,7 +57,7 @@ module.exports = async ({
54
57
  }
55
58
  } = responseData;
56
59
  } catch (error) {
57
- throw new Error('core.groupFileRename 请求返回格式出错,请检查 mirai-console');
60
+ throw new Error('请求返回格式出错,请检查 mirai-console');
58
61
  } // 抛出 mirai 的异常,到 catch 中处理后再抛出
59
62
 
60
63
 
@@ -67,6 +70,7 @@ module.exports = async ({
67
70
  code
68
71
  };
69
72
  } catch (error) {
73
+ console.error(`mirai-js: error ${locationStr}`);
70
74
  errorHandler(error);
71
75
  }
72
76
  };
@@ -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 的主机地址
@@ -27,7 +25,6 @@ const errorHandler = require('../util/errorHandler');
27
25
  * @returns {Object} 结构 { message, code }
28
26
  */
29
27
 
30
-
31
28
  module.exports = async ({
32
29
  baseUrl,
33
30
  sessionKey,
@@ -54,7 +51,7 @@ module.exports = async ({
54
51
  }
55
52
  } = responseData;
56
53
  } catch (error) {
57
- throw new Error('core.mute 请求返回格式出错,请检查 mirai-console');
54
+ throw new Error('请求返回格式出错,请检查 mirai-console');
58
55
  } // 抛出 mirai 的异常,到 catch 中处理后再抛出
59
56
 
60
57
 
@@ -67,6 +64,7 @@ module.exports = async ({
67
64
  code
68
65
  };
69
66
  } catch (error) {
67
+ console.error(`mirai-js: error ${locationStr}`);
70
68
  errorHandler(error);
71
69
  }
72
70
  };
@@ -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} 结构 { message, code }
26
24
  */
27
25
 
28
-
29
26
  module.exports = async ({
30
27
  baseUrl,
31
28
  sessionKey,
@@ -48,7 +45,7 @@ module.exports = async ({
48
45
  }
49
46
  } = responseData;
50
47
  } catch (error) {
51
- throw new Error('core.muteAll 请求返回格式出错,请检查 mirai-console');
48
+ throw new Error('请求返回格式出错,请检查 mirai-console');
52
49
  } // 抛出 mirai 的异常,到 catch 中处理后再抛出
53
50
 
54
51
 
@@ -61,6 +58,7 @@ module.exports = async ({
61
58
  code
62
59
  };
63
60
  } catch (error) {
61
+ console.error(`mirai-js: error ${locationStr}`);
64
62
  errorHandler(error);
65
63
  }
66
64
  };
@@ -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} 结构 { message, code }
26
24
  */
27
25
 
28
-
29
26
  module.exports = async ({
30
27
  baseUrl,
31
28
  sessionKey,
@@ -48,7 +45,7 @@ module.exports = async ({
48
45
  }
49
46
  } = responseData;
50
47
  } catch (error) {
51
- throw new Error('core.quitGroup 请求返回格式出错,请检查 mirai-console');
48
+ throw new Error('请求返回格式出错,请检查 mirai-console');
52
49
  } // 抛出 mirai 的异常,到 catch 中处理后再抛出
53
50
 
54
51
 
@@ -61,6 +58,7 @@ module.exports = async ({
61
58
  code
62
59
  };
63
60
  } catch (error) {
61
+ console.error(`mirai-js: error ${locationStr}`);
64
62
  errorHandler(error);
65
63
  }
66
64
  };