mirai-js 2.3.0 → 2.4.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.
Files changed (104) hide show
  1. package/README.md +17 -283
  2. package/demo.js +13 -17
  3. package/dist/browser/mirai-js.js +1 -1
  4. package/dist/node/BaseType.d.ts +3 -0
  5. package/dist/node/Bot.d.ts +79 -4
  6. package/dist/node/Bot.js +171 -4
  7. package/dist/node/core/anno/deleteAnno.js +67 -0
  8. package/dist/node/core/anno/getAnno.js +70 -0
  9. package/dist/node/core/anno/publishAnno.js +70 -0
  10. package/dist/node/core/auth.js +3 -9
  11. package/dist/node/core/fs/deleteGroupFile.js +3 -9
  12. package/dist/node/core/fs/getGroupFileInfo.js +3 -9
  13. package/dist/node/core/fs/getGroupFileList.js +3 -9
  14. package/dist/node/core/fs/makeGroupDir.js +3 -9
  15. package/dist/node/core/fs/moveGroupFile.js +3 -9
  16. package/dist/node/core/fs/renameGroupFile.js +3 -9
  17. package/dist/node/core/fs/uploadGroupFIle.js +3 -9
  18. package/dist/node/core/getFriendList.js +3 -9
  19. package/dist/node/core/getGroupConfig.js +3 -9
  20. package/dist/node/core/getGroupList.js +3 -9
  21. package/dist/node/core/getMemberInfo.js +7 -17
  22. package/dist/node/core/getMemberList.js +3 -9
  23. package/dist/node/core/getSessionConfig.js +3 -9
  24. package/dist/node/core/getUserProfile.js +78 -0
  25. package/dist/node/core/mute.js +3 -9
  26. package/dist/node/core/muteAll.js +3 -9
  27. package/dist/node/core/quitGroup.js +3 -9
  28. package/dist/node/core/recall.js +3 -9
  29. package/dist/node/core/releaseSession.js +3 -9
  30. package/dist/node/core/removeFriend.js +3 -9
  31. package/dist/node/core/removeMember.js +3 -9
  32. package/dist/node/core/responseBotInvitedJoinGroupRequest.js +3 -9
  33. package/dist/node/core/responseFirendRequest.js +3 -9
  34. package/dist/node/core/responseMemberJoinRequest.js +3 -9
  35. package/dist/node/core/sendCommand.js +3 -9
  36. package/dist/node/core/sendFirendMessage.js +3 -9
  37. package/dist/node/core/sendGroupMessage.js +3 -9
  38. package/dist/node/core/sendNudge.js +3 -9
  39. package/dist/node/core/sendTempMessage.js +3 -9
  40. package/dist/node/core/setEssence.js +3 -9
  41. package/dist/node/core/setGroupConfig.js +3 -9
  42. package/dist/node/core/setMemberAdmin.js +3 -9
  43. package/dist/node/core/setMemberInfo.js +3 -9
  44. package/dist/node/core/setSessionConfig.js +3 -9
  45. package/dist/node/core/startListeningBrowser.js +3 -8
  46. package/dist/node/core/startListeningNode.js +3 -9
  47. package/dist/node/core/unmute.js +3 -9
  48. package/dist/node/core/unmuteAll.js +3 -9
  49. package/dist/node/core/uploadImage.js +3 -9
  50. package/dist/node/core/uploadVoice.js +3 -9
  51. package/dist/node/core/verify.js +3 -9
  52. package/dist/node/polyfill/URL.js +5 -0
  53. package/dist/node/polyfill/wsListener.js +6 -0
  54. package/package.json +1 -1
  55. package/src/BaseType.d.ts +3 -0
  56. package/src/Bot.d.ts +79 -4
  57. package/src/Bot.js +107 -3
  58. package/src/core/anno/deleteAnno.js +42 -0
  59. package/src/core/anno/getAnno.js +43 -0
  60. package/src/core/anno/publishAnno.js +43 -0
  61. package/src/core/auth.js +1 -6
  62. package/src/core/fs/deleteGroupFile.js +1 -6
  63. package/src/core/fs/getGroupFileInfo.js +1 -6
  64. package/src/core/fs/getGroupFileList.js +1 -6
  65. package/src/core/fs/makeGroupDir.js +1 -6
  66. package/src/core/fs/moveGroupFile.js +1 -6
  67. package/src/core/fs/renameGroupFile.js +1 -6
  68. package/src/core/fs/uploadGroupFIle.js +1 -6
  69. package/src/core/getFriendList.js +1 -6
  70. package/src/core/getGroupConfig.js +1 -6
  71. package/src/core/getGroupList.js +1 -6
  72. package/src/core/getMemberInfo.js +4 -9
  73. package/src/core/getMemberList.js +1 -6
  74. package/src/core/getSessionConfig.js +1 -6
  75. package/src/core/getUserProfile.js +39 -0
  76. package/src/core/mute.js +1 -6
  77. package/src/core/muteAll.js +1 -6
  78. package/src/core/quitGroup.js +1 -6
  79. package/src/core/recall.js +1 -6
  80. package/src/core/releaseSession.js +1 -6
  81. package/src/core/removeFriend.js +1 -6
  82. package/src/core/removeMember.js +1 -6
  83. package/src/core/responseBotInvitedJoinGroupRequest.js +1 -6
  84. package/src/core/responseFirendRequest.js +1 -6
  85. package/src/core/responseMemberJoinRequest.js +1 -6
  86. package/src/core/sendCommand.js +1 -6
  87. package/src/core/sendFirendMessage.js +1 -6
  88. package/src/core/sendGroupMessage.js +1 -6
  89. package/src/core/sendNudge.js +1 -6
  90. package/src/core/sendTempMessage.js +1 -6
  91. package/src/core/setEssence.js +1 -6
  92. package/src/core/setGroupConfig.js +1 -6
  93. package/src/core/setMemberAdmin.js +1 -6
  94. package/src/core/setMemberInfo.js +1 -6
  95. package/src/core/setSessionConfig.js +1 -6
  96. package/src/core/startListeningBrowser.js +1 -6
  97. package/src/core/startListeningNode.js +1 -6
  98. package/src/core/unmute.js +1 -6
  99. package/src/core/unmuteAll.js +1 -6
  100. package/src/core/uploadImage.js +1 -6
  101. package/src/core/uploadVoice.js +1 -6
  102. package/src/core/verify.js +1 -6
  103. package/src/polyfill/URL.js +3 -0
  104. package/src/polyfill/wsListener.js +4 -0
@@ -6,15 +6,9 @@ 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');
20
14
 
@@ -6,15 +6,9 @@ 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');
20
14
 
@@ -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
+ };
@@ -6,15 +6,9 @@ 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');
20
14
 
@@ -6,15 +6,9 @@ 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');
20
14
 
@@ -6,15 +6,9 @@ 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');
20
14
 
@@ -6,15 +6,9 @@ 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');
20
14
 
@@ -6,15 +6,9 @@ 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');
20
14
 
@@ -6,15 +6,9 @@ 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');
20
14
 
@@ -6,15 +6,9 @@ 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');
20
14
 
@@ -6,15 +6,9 @@ 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');
20
14
 
@@ -6,15 +6,9 @@ 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');
20
14
 
@@ -6,15 +6,9 @@ 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');
20
14
 
@@ -6,15 +6,9 @@ const {
6
6
  errCodeMap
7
7
  } = require('../util/errCode');
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');
20
14
 
@@ -6,15 +6,9 @@ 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');
20
14
 
@@ -6,15 +6,9 @@ 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');
20
14
 
@@ -6,15 +6,9 @@ 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');
20
14
 
@@ -6,15 +6,9 @@ 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');
20
14
 
@@ -6,15 +6,9 @@ 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');
20
14
 
@@ -6,15 +6,9 @@ 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');
20
14
 
@@ -6,15 +6,9 @@ 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');
20
14
 
@@ -6,15 +6,9 @@ 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');
20
14
 
@@ -6,15 +6,9 @@ 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');
20
14
 
@@ -1,15 +1,10 @@
1
1
  "use strict";
2
2
 
3
3
  const WebSocket = window.WebSocket;
4
- let URL;
5
4
 
6
- if (!process.browser) {
7
- ({
8
- URL
9
- } = require('url'));
10
- } else {
11
- URL = window.URL;
12
- }
5
+ const {
6
+ URL
7
+ } = require('../polyfill/URL');
13
8
 
14
9
  const errorHandler = require('../util/errorHandler');
15
10
 
@@ -2,15 +2,9 @@
2
2
 
3
3
  const WebSocket = require('ws');
4
4
 
5
- let URL;
6
-
7
- if (!process.browser) {
8
- ({
9
- URL
10
- } = require('url'));
11
- } else {
12
- URL = window.URL;
13
- }
5
+ const {
6
+ URL
7
+ } = require('../polyfill/URL');
14
8
 
15
9
  const errorHandler = require('../util/errorHandler');
16
10
 
@@ -6,15 +6,9 @@ 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');
20
14
 
@@ -6,15 +6,9 @@ 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');
20
14
 
@@ -6,15 +6,9 @@ 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');
20
14
 
@@ -6,15 +6,9 @@ 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');
20
14
 
@@ -6,15 +6,9 @@ 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');
20
14
 
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+
3
+ module.exports = {
4
+ URL: process.browser ? window.URL : require('url').URL
5
+ };
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+
3
+ module.exports = {
4
+ wsStartListening: process.browser ? require('../core/startListeningBrowser') : require('../core/startListeningNode'),
5
+ wsStopListening: process.browser ? require('../core/stopListeningBrowser') : require('../core/stopListeningNode')
6
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mirai-js",
3
- "version": "2.3.0",
3
+ "version": "2.4.0",
4
4
  "description": "QQ robot development framework based on Mirai-api-http.",
5
5
  "main": "dist/node/index.js",
6
6
  "scripts": {