mirai-js 2.2.0 → 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (107) hide show
  1. package/.github/FUNDING.yml +1 -1
  2. package/demo.html +1 -1
  3. package/demo.js +19 -73
  4. package/dist/browser/mirai-js.js +1 -1
  5. package/dist/node/Bot.d.ts +16 -4
  6. package/dist/node/Bot.js +67 -11
  7. package/dist/node/FileManager.js +15 -6
  8. package/dist/node/core/auth.js +6 -2
  9. package/dist/node/core/fs/deleteGroupFile.js +77 -0
  10. package/dist/node/core/fs/getGroupFileInfo.js +83 -0
  11. package/dist/node/core/fs/getGroupFileList.js +88 -0
  12. package/dist/node/core/fs/makeGroupDir.js +79 -0
  13. package/dist/node/core/fs/moveGroupFile.js +83 -0
  14. package/dist/node/core/fs/renameGroupFile.js +79 -0
  15. package/dist/node/core/fs/uploadGroupFIle.js +87 -0
  16. package/dist/node/core/getFriendList.js +6 -2
  17. package/dist/node/core/getGroupConfig.js +6 -2
  18. package/dist/node/core/getGroupFileInfo.js +6 -2
  19. package/dist/node/core/getGroupFileList.js +6 -2
  20. package/dist/node/core/getGroupList.js +6 -2
  21. package/dist/node/core/getMemberInfo.js +6 -2
  22. package/dist/node/core/getMemberList.js +6 -2
  23. package/dist/node/core/getSessionConfig.js +6 -2
  24. package/dist/node/core/groupFileDelete.js +6 -2
  25. package/dist/node/core/groupFileMove.js +6 -2
  26. package/dist/node/core/groupFileRename.js +6 -2
  27. package/dist/node/core/mute.js +6 -2
  28. package/dist/node/core/muteAll.js +6 -2
  29. package/dist/node/core/quitGroup.js +6 -2
  30. package/dist/node/core/recall.js +6 -2
  31. package/dist/node/core/releaseSession.js +7 -2
  32. package/dist/node/core/removeFriend.js +70 -0
  33. package/dist/node/core/removeMember.js +6 -2
  34. package/dist/node/core/responseBotInvitedJoinGroupRequest.js +6 -2
  35. package/dist/node/core/responseFirendRequest.js +6 -2
  36. package/dist/node/core/responseMemberJoinRequest.js +6 -2
  37. package/dist/node/core/sendCommand.js +6 -2
  38. package/dist/node/core/sendFirendMessage.js +6 -2
  39. package/dist/node/core/sendGroupMessage.js +6 -2
  40. package/dist/node/core/sendNudge.js +6 -2
  41. package/dist/node/core/sendTempMessage.js +6 -2
  42. package/dist/node/core/setEssence.js +6 -2
  43. package/dist/node/core/setGroupConfig.js +6 -2
  44. package/dist/node/core/setMemberAdmin.js +76 -0
  45. package/dist/node/core/setMemberInfo.js +6 -2
  46. package/dist/node/core/setSessionConfig.js +6 -2
  47. package/dist/node/core/startListeningBrowser.js +5 -1
  48. package/dist/node/core/startListeningNode.js +5 -1
  49. package/dist/node/core/stopListeningBrowser.js +5 -1
  50. package/dist/node/core/stopListeningNode.js +5 -1
  51. package/dist/node/core/unmute.js +6 -2
  52. package/dist/node/core/unmuteAll.js +6 -2
  53. package/dist/node/core/uploadFileAndSend.js +6 -1
  54. package/dist/node/core/uploadImage.js +6 -1
  55. package/dist/node/core/uploadVoice.js +6 -1
  56. package/dist/node/core/verify.js +6 -2
  57. package/package.json +2 -2
  58. package/src/Bot.d.ts +16 -4
  59. package/src/Bot.js +48 -7
  60. package/src/FileManager.js +10 -6
  61. package/src/core/auth.js +4 -1
  62. package/src/core/fs/deleteGroupFile.js +49 -0
  63. package/src/core/fs/getGroupFileInfo.js +50 -0
  64. package/src/core/fs/getGroupFileList.js +51 -0
  65. package/src/core/fs/makeGroupDir.js +49 -0
  66. package/src/core/fs/moveGroupFile.js +51 -0
  67. package/src/core/{groupFileRename.js → fs/renameGroupFile.js} +10 -7
  68. package/src/core/{uploadFileAndSend.js → fs/uploadGroupFIle.js} +8 -5
  69. package/src/core/getFriendList.js +4 -1
  70. package/src/core/getGroupConfig.js +4 -1
  71. package/src/core/getGroupList.js +4 -1
  72. package/src/core/getMemberInfo.js +4 -1
  73. package/src/core/getMemberList.js +4 -1
  74. package/src/core/getSessionConfig.js +4 -1
  75. package/src/core/mute.js +4 -1
  76. package/src/core/muteAll.js +4 -1
  77. package/src/core/quitGroup.js +4 -1
  78. package/src/core/recall.js +4 -1
  79. package/src/core/releaseSession.js +5 -1
  80. package/src/core/{groupFileDelete.js → removeFriend.js} +10 -11
  81. package/src/core/removeMember.js +4 -1
  82. package/src/core/responseBotInvitedJoinGroupRequest.js +4 -1
  83. package/src/core/responseFirendRequest.js +4 -1
  84. package/src/core/responseMemberJoinRequest.js +4 -1
  85. package/src/core/sendCommand.js +4 -1
  86. package/src/core/sendFirendMessage.js +4 -1
  87. package/src/core/sendGroupMessage.js +4 -1
  88. package/src/core/sendNudge.js +4 -1
  89. package/src/core/sendTempMessage.js +4 -1
  90. package/src/core/setEssence.js +4 -1
  91. package/src/core/setGroupConfig.js +4 -1
  92. package/src/core/setMemberAdmin.js +48 -0
  93. package/src/core/setMemberInfo.js +4 -1
  94. package/src/core/setSessionConfig.js +4 -1
  95. package/src/core/startListeningBrowser.js +3 -0
  96. package/src/core/startListeningNode.js +3 -0
  97. package/src/core/stopListeningBrowser.js +3 -0
  98. package/src/core/stopListeningNode.js +3 -0
  99. package/src/core/unmute.js +4 -1
  100. package/src/core/unmuteAll.js +4 -1
  101. package/src/core/uploadImage.js +4 -1
  102. package/src/core/uploadVoice.js +4 -1
  103. package/src/core/verify.js +4 -1
  104. package/webpack.config.js +4 -0
  105. package/src/core/getGroupFileInfo.js +0 -44
  106. package/src/core/getGroupFileList.js +0 -40
  107. package/src/core/groupFileMove.js +0 -46
@@ -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 的主机地址
@@ -25,7 +29,6 @@ const errorHandler = require('../util/errorHandler');
25
29
  * @returns {Object} 结构 { message, code }
26
30
  */
27
31
 
28
-
29
32
  module.exports = async ({
30
33
  baseUrl,
31
34
  sessionKey,
@@ -48,7 +51,7 @@ module.exports = async ({
48
51
  }
49
52
  } = responseData;
50
53
  } catch (error) {
51
- throw new Error('core.releaseSession 请求返回格式出错,请检查 mirai-console');
54
+ throw new Error('请求返回格式出错,请检查 mirai-console');
52
55
  } // 抛出 mirai 的异常,到 catch 中处理后再抛出
53
56
 
54
57
 
@@ -61,6 +64,8 @@ module.exports = async ({
61
64
  code
62
65
  };
63
66
  } catch (error) {
67
+ console.error(`mirai-js: error ${locationStr}`);
68
+ console.error(`mirai-js: error ${locationStr}`);
64
69
  errorHandler(error);
65
70
  }
66
71
  };
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+
3
+ const {
4
+ errCodeMap
5
+ } = require('../util/errCode');
6
+
7
+ const axios = require('axios').default;
8
+
9
+ let URL;
10
+
11
+ if (!process.browser) {
12
+ ({
13
+ URL
14
+ } = require('url'));
15
+ } else {
16
+ URL = window.URL;
17
+ }
18
+
19
+ const errorHandler = require('../util/errorHandler');
20
+
21
+ const path = require('path');
22
+
23
+ const locationStr = `core.${path.basename(__filename, path.extname(__filename))}`;
24
+ /**
25
+ * @description 删除好友
26
+ * @param {string} baseUrl mirai-api-http server 的地址
27
+ * @param {string} sessionKey 会话标识
28
+ * @param {number} target 欲删除好友的 qq 号
29
+ * @returns {Object} 结构 { message, code }
30
+ */
31
+
32
+ module.exports = async ({
33
+ baseUrl,
34
+ sessionKey,
35
+ target
36
+ }) => {
37
+ try {
38
+ // 拼接 url
39
+ const url = new URL('/deleteFriend', baseUrl).toString(); // 请求
40
+
41
+ const responseData = await axios.post(url, {
42
+ sessionKey,
43
+ target
44
+ });
45
+
46
+ try {
47
+ var {
48
+ data: {
49
+ msg: message,
50
+ code
51
+ }
52
+ } = responseData;
53
+ } catch (error) {
54
+ throw new Error('请求返回格式出错,请检查 mirai-console');
55
+ } // 抛出 mirai 的异常,到 catch 中处理后再抛出
56
+
57
+
58
+ if (code in errCodeMap) {
59
+ throw new Error(message);
60
+ }
61
+
62
+ return {
63
+ message,
64
+ code
65
+ };
66
+ } catch (error) {
67
+ console.error(`mirai-js: error ${locationStr}`);
68
+ errorHandler(error);
69
+ }
70
+ };
@@ -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.removeMember 请求返回格式出错,请检查 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
  * ! 自动同意时,不会触发该事件
22
26
  * @description 响应机器人被邀请入群请求
@@ -30,7 +34,6 @@ const errorHandler = require('../util/errorHandler');
30
34
  * @returns {void}
31
35
  */
32
36
 
33
-
34
37
  module.exports = async ({
35
38
  baseUrl,
36
39
  sessionKey,
@@ -61,7 +64,7 @@ module.exports = async ({
61
64
  }
62
65
  } = responseData;
63
66
  } catch (error) {
64
- throw new Error('core.responseBotlnviedJoinGroupRequest 请求返回格式出错,请检查 mirai-console');
67
+ throw new Error('请求返回格式出错,请检查 mirai-console');
65
68
  } // 抛出 mirai 的异常,到 catch 中处理后再抛出
66
69
 
67
70
 
@@ -69,6 +72,7 @@ module.exports = async ({
69
72
  throw new Error(serverMessage);
70
73
  }
71
74
  } catch (error) {
75
+ console.error(`mirai-js: error ${locationStr}`);
72
76
  errorHandler(error);
73
77
  }
74
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 的地址
@@ -29,7 +33,6 @@ const errorHandler = require('../util/errorHandler');
29
33
  * @returns {void}
30
34
  */
31
35
 
32
-
33
36
  module.exports = async ({
34
37
  baseUrl,
35
38
  sessionKey,
@@ -60,7 +63,7 @@ module.exports = async ({
60
63
  }
61
64
  } = responseData;
62
65
  } catch (error) {
63
- throw new Error('core.responseFirendRequest 请求返回格式出错,请检查 mirai-console');
66
+ throw new Error('请求返回格式出错,请检查 mirai-console');
64
67
  } // 抛出 mirai 的异常,到 catch 中处理后再抛出
65
68
 
66
69
 
@@ -68,6 +71,7 @@ module.exports = async ({
68
71
  throw new Error(serverMessage);
69
72
  }
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
  * FIXME: mirai-core 的问题,有时候收不到 MemberJoinRequestEvent 事件
22
26
  * 该功能未经测试
@@ -31,7 +35,6 @@ const errorHandler = require('../util/errorHandler');
31
35
  * @returns {void}
32
36
  */
33
37
 
34
-
35
38
  module.exports = async ({
36
39
  baseUrl,
37
40
  sessionKey,
@@ -62,7 +65,7 @@ module.exports = async ({
62
65
  }
63
66
  } = responseData;
64
67
  } catch (error) {
65
- throw new Error('core.responseMember 请求返回格式出错,请检查 mirai-console');
68
+ throw new Error('请求返回格式出错,请检查 mirai-console');
66
69
  } // 抛出 mirai 的异常,到 catch 中处理后再抛出
67
70
 
68
71
 
@@ -70,6 +73,7 @@ module.exports = async ({
70
73
  throw new Error(serverMessage);
71
74
  }
72
75
  } catch (error) {
76
+ console.error(`mirai-js: error ${locationStr}`);
73
77
  errorHandler(error);
74
78
  }
75
79
  };
@@ -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 向 mirai-console 发送指令
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,
@@ -49,7 +52,7 @@ module.exports = async ({
49
52
  }
50
53
  } = responseData;
51
54
  } catch (error) {
52
- throw new Error('core.sendCommand 请求返回格式出错,请检查 mirai-console');
55
+ throw new Error('请求返回格式出错,请检查 mirai-console');
53
56
  } // 抛出 mirai 的异常,到 catch 中处理后再抛出
54
57
 
55
58
 
@@ -62,6 +65,7 @@ module.exports = async ({
62
65
  code
63
66
  };
64
67
  } catch (error) {
68
+ console.error(`mirai-js: error ${locationStr}`);
65
69
  errorHandler(error);
66
70
  }
67
71
  };
@@ -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 向 qq 好友发送消息
22
26
  * @param {string} baseUrl mirai-api-http server 的地址
@@ -27,7 +31,6 @@ const errorHandler = require('../util/errorHandler');
27
31
  * @returns {Object} 结构 { message, code, messageId }
28
32
  */
29
33
 
30
-
31
34
  module.exports = async ({
32
35
  baseUrl,
33
36
  sessionKey,
@@ -55,7 +58,7 @@ module.exports = async ({
55
58
  }
56
59
  } = responseData;
57
60
  } catch (error) {
58
- throw new Error('core.sendFirendMessage 请求返回格式出错,请检查 mirai-console');
61
+ throw new Error('请求返回格式出错,请检查 mirai-console');
59
62
  } // 抛出 mirai 的异常,到 catch 中处理后再抛出
60
63
 
61
64
 
@@ -65,6 +68,7 @@ module.exports = async ({
65
68
 
66
69
  return messageId;
67
70
  } catch (error) {
71
+ console.error(`mirai-js: error ${locationStr}`);
68
72
  errorHandler(error);
69
73
  }
70
74
  };
@@ -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 向 qq 群发送消息
22
26
  * @param {string} baseUrl mirai-api-http server 的地址
@@ -27,7 +31,6 @@ const errorHandler = require('../util/errorHandler');
27
31
  * @returns {Object} 结构 { message, code, messageId }
28
32
  */
29
33
 
30
-
31
34
  module.exports = async ({
32
35
  baseUrl,
33
36
  sessionKey,
@@ -55,7 +58,7 @@ module.exports = async ({
55
58
  }
56
59
  } = responseData;
57
60
  } catch (error) {
58
- throw new Error('core.sendGroupMessage 请求返回格式出错,请检查 mirai-console');
61
+ throw new Error('请求返回格式出错,请检查 mirai-console');
59
62
  } // 抛出 mirai 的异常,到 catch 中处理后再抛出
60
63
 
61
64
 
@@ -65,6 +68,7 @@ module.exports = async ({
65
68
 
66
69
  return messageId;
67
70
  } catch (error) {
71
+ console.error(`mirai-js: error ${locationStr}`);
68
72
  errorHandler(error);
69
73
  }
70
74
  };
@@ -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, messageId }
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.sendNudge 请求返回格式出错,请检查 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 的地址
@@ -28,7 +32,6 @@ const errorHandler = require('../util/errorHandler');
28
32
  * @returns {Object} 结构 { message, code, messageId }
29
33
  */
30
34
 
31
-
32
35
  module.exports = async ({
33
36
  baseUrl,
34
37
  sessionKey,
@@ -63,7 +66,7 @@ module.exports = async ({
63
66
  }
64
67
  } = responseData;
65
68
  } catch (error) {
66
- throw new Error('core.sendTempMessage 请求返回格式出错,请检查 mirai-console');
69
+ throw new Error('请求返回格式出错,请检查 mirai-console');
67
70
  } // 抛出 mirai 的异常,到 catch 中处理后再抛出
68
71
 
69
72
 
@@ -73,6 +76,7 @@ module.exports = async ({
73
76
 
74
77
  return messageId;
75
78
  } catch (error) {
79
+ console.error(`mirai-js: error ${locationStr}`);
76
80
  errorHandler(error);
77
81
  }
78
82
  };
@@ -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 的地址
@@ -25,7 +29,6 @@ const errorHandler = require('../util/errorHandler');
25
29
  * @returns {Object} 结构 { message, code }
26
30
  */
27
31
 
28
-
29
32
  module.exports = async ({
30
33
  baseUrl,
31
34
  sessionKey,
@@ -48,7 +51,7 @@ module.exports = async ({
48
51
  }
49
52
  } = responseData;
50
53
  } catch (error) {
51
- throw new Error('core.setEssence 请求返回格式出错,请检查 mirai-console');
54
+ throw new Error('请求返回格式出错,请检查 mirai-console');
52
55
  } // 抛出 mirai 的异常,到 catch 中处理后再抛出
53
56
 
54
57
 
@@ -61,6 +64,7 @@ module.exports = async ({
61
64
  code
62
65
  };
63
66
  } catch (error) {
67
+ console.error(`mirai-js: error ${locationStr}`);
64
68
  errorHandler(error);
65
69
  }
66
70
  };
@@ -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
  * @returns {Object} 结构 { message, code }
31
35
  */
32
36
 
33
-
34
37
  module.exports = async ({
35
38
  baseUrl,
36
39
  sessionKey,
@@ -67,7 +70,7 @@ module.exports = async ({
67
70
  }
68
71
  } = responseData;
69
72
  } catch (error) {
70
- throw new Error('core.setGroupConfig 请求返回格式出错,请检查 mirai-console');
73
+ throw new Error('请求返回格式出错,请检查 mirai-console');
71
74
  } // 抛出 mirai 的异常,到 catch 中处理后再抛出
72
75
 
73
76
 
@@ -80,6 +83,7 @@ module.exports = async ({
80
83
  code
81
84
  };
82
85
  } catch (error) {
86
+ console.error(`mirai-js: error ${locationStr}`);
83
87
  errorHandler(error);
84
88
  }
85
89
  };
@@ -0,0 +1,76 @@
1
+ "use strict";
2
+
3
+ const {
4
+ errCodeMap
5
+ } = require('../util/errCode');
6
+
7
+ const axios = require('axios');
8
+
9
+ let URL;
10
+
11
+ if (!process.browser) {
12
+ ({
13
+ URL
14
+ } = require('url'));
15
+ } else {
16
+ URL = window.URL;
17
+ }
18
+
19
+ const errorHandler = require('../util/errorHandler');
20
+
21
+ const path = require('path');
22
+
23
+ const locationStr = `core.${path.basename(__filename, path.extname(__filename))}`;
24
+ /**
25
+ * @description 设置群成员权限
26
+ * @param {string} baseUrl mirai-api-http server 的地址
27
+ * @param {string} sessionKey 会话标识
28
+ * @param {number} target 群成员所在群号
29
+ * @param {number} memberId 群成员的 qq 号
30
+ * @param {string} assign 是否设置为管理员
31
+ * @returns {Object} 结构 { message, code }
32
+ */
33
+
34
+ module.exports = async ({
35
+ baseUrl,
36
+ sessionKey,
37
+ target,
38
+ memberId,
39
+ assign
40
+ }) => {
41
+ try {
42
+ // 拼接 url
43
+ const url = new URL('/memberAdmin', baseUrl).toString(); // 请求
44
+
45
+ const responseData = await axios.post(url, {
46
+ sessionKey,
47
+ target,
48
+ memberId,
49
+ assign
50
+ });
51
+
52
+ try {
53
+ var {
54
+ data: {
55
+ msg: message,
56
+ code
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 {
69
+ message,
70
+ code
71
+ };
72
+ } catch (error) {
73
+ console.error(`mirai-js: error ${locationStr}`);
74
+ errorHandler(error);
75
+ }
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 的地址
@@ -28,7 +32,6 @@ const errorHandler = require('../util/errorHandler');
28
32
  * @returns {Object} 结构 { message, code }
29
33
  */
30
34
 
31
-
32
35
  module.exports = async ({
33
36
  baseUrl,
34
37
  sessionKey,
@@ -59,7 +62,7 @@ module.exports = async ({
59
62
  }
60
63
  } = responseData;
61
64
  } catch (error) {
62
- throw new Error('core.setMemberInfo 请求返回格式出错,请检查 mirai-console');
65
+ throw new Error('请求返回格式出错,请检查 mirai-console');
63
66
  } // 抛出 mirai 的异常,到 catch 中处理后再抛出
64
67
 
65
68
 
@@ -72,6 +75,7 @@ module.exports = async ({
72
75
  code
73
76
  };
74
77
  } catch (error) {
78
+ console.error(`mirai-js: error ${locationStr}`);
75
79
  errorHandler(error);
76
80
  }
77
81
  };
@@ -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 设置指定 session 的 config
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.setSessionConfig 请求返回格式出错,请检查 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
  };
@@ -12,6 +12,10 @@ if (!process.browser) {
12
12
  }
13
13
 
14
14
  const errorHandler = require('../util/errorHandler');
15
+
16
+ const path = require('path');
17
+
18
+ const locationStr = `core.${path.basename(__filename, path.extname(__filename))}`;
15
19
  /**
16
20
  * @description 开始侦听事件
17
21
  * @param {string} baseUrl mirai-api-http server 的地址
@@ -22,7 +26,6 @@ const errorHandler = require('../util/errorHandler');
22
26
  * @returns {WebSocket} 建立连接的 WebSocket 实例
23
27
  */
24
28
 
25
-
26
29
  module.exports = async ({
27
30
  baseUrl,
28
31
  sessionKey,
@@ -82,6 +85,7 @@ module.exports = async ({
82
85
 
83
86
  return ws;
84
87
  } catch (error) {
88
+ console.error(`mirai-js: error ${locationStr}`);
85
89
  errorHandler(error);
86
90
  }
87
91
  };
@@ -13,6 +13,10 @@ if (!process.browser) {
13
13
  }
14
14
 
15
15
  const errorHandler = require('../util/errorHandler');
16
+
17
+ const path = require('path');
18
+
19
+ const locationStr = `core.${path.basename(__filename, path.extname(__filename))}`;
16
20
  /**
17
21
  * @description 开始侦听事件
18
22
  * @param {string} baseUrl mirai-api-http server 的地址
@@ -24,7 +28,6 @@ const errorHandler = require('../util/errorHandler');
24
28
  * @returns {WebSocket} 建立连接的 WebSocket 实例
25
29
  */
26
30
 
27
-
28
31
  module.exports = async ({
29
32
  baseUrl,
30
33
  sessionKey,
@@ -92,6 +95,7 @@ module.exports = async ({
92
95
  });
93
96
  return ws;
94
97
  } catch (error) {
98
+ console.error(`mirai-js: error ${locationStr}`);
95
99
  errorHandler(error);
96
100
  }
97
101
  };