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
@@ -0,0 +1,51 @@
1
+ const { errCodeMap } = require('../../util/errCode');
2
+ const axios = require('axios');
3
+ let URL;
4
+ if (!process.browser) {
5
+ ({ URL } = require('url'));
6
+ } else {
7
+ URL = window.URL;
8
+ }
9
+ const errorHandler = require('../../util/errorHandler');
10
+ const path = require('path');
11
+ const locationStr = `core.${path.basename(__filename, path.extname(__filename))}`;
12
+
13
+ /**
14
+ * @description 移动群文件
15
+ * @param {string} baseUrl mirai-api-http server 的地址
16
+ * @param {string} sessionKey 会话标识
17
+ * @param {string} id 文件夹id, 空串为根目录
18
+ * @param {string} path 文件夹路径, 文件夹允许重名, 不保证准确, 准确定位使用 id
19
+ * @param {number} group 群号
20
+ * @param {string} moveTo 移动目标文件夹id
21
+ * @param {string} moveToPath 移动目标文件夹path
22
+ * @returns {Object} 结构 { message, code }
23
+ */
24
+ module.exports = async ({ baseUrl, sessionKey, id, path, group, moveTo, moveToPath }) => {
25
+ try {
26
+ // 拼接 url
27
+ const url = new URL('/file/move', baseUrl).toString();
28
+
29
+ // 请求
30
+ const responseData = await axios.post(url, {
31
+ sessionKey, id, path, target: group, group, moveTo, moveToPath
32
+ });
33
+
34
+ try {
35
+ var {
36
+ data: { msg: message, code }
37
+ } = responseData;
38
+ } catch (error) {
39
+ throw new Error(('请求返回格式出错,请检查 mirai-console'));
40
+ }
41
+ // 抛出 mirai 的异常,到 catch 中处理后再抛出
42
+ if (code in errCodeMap) {
43
+ throw new Error(message);
44
+ }
45
+ return { message, code };
46
+ } catch (error) {
47
+ console.error(`mirai-js: error ${locationStr}`);
48
+ errorHandler(error);
49
+ }
50
+
51
+ };
@@ -1,4 +1,4 @@
1
- const { errCodeMap } = require('../util/errCode');
1
+ const { errCodeMap } = require('../../util/errCode');
2
2
  const axios = require('axios');
3
3
  let URL;
4
4
  if (!process.browser) {
@@ -6,25 +6,27 @@ if (!process.browser) {
6
6
  } else {
7
7
  URL = window.URL;
8
8
  }
9
- const errorHandler = require('../util/errorHandler');
9
+ const errorHandler = require('../../util/errorHandler');
10
+ const path = require('path');
11
+ const locationStr = `core.${path.basename(__filename, path.extname(__filename))}`;
10
12
 
11
13
  /**
12
14
  * @description 重命名群文件
13
15
  * @param {string} baseUrl mirai-api-http server 的地址
14
16
  * @param {string} sessionKey 会话标识
15
- * @param {number} target 群号
16
17
  * @param {number} id 文件 id
18
+ * @param {number} group 群号
17
19
  * @param {string} rename 重命名
18
20
  * @returns {Object} 结构 { message, code }
19
21
  */
20
- module.exports = async ({ baseUrl, sessionKey, target, id, rename }) => {
22
+ module.exports = async ({ baseUrl, sessionKey, id, path, group, renameTo }) => {
21
23
  try {
22
24
  // 拼接 url
23
- const url = new URL('/groupFileRename', baseUrl).toString();
25
+ const url = new URL('/file/rename', baseUrl).toString();
24
26
 
25
27
  // 请求
26
28
  const responseData = await axios.post(url, {
27
- sessionKey, target, id, rename
29
+ sessionKey, id, path, target: group, group, renameTo
28
30
  });
29
31
 
30
32
  try {
@@ -32,7 +34,7 @@ module.exports = async ({ baseUrl, sessionKey, target, id, rename }) => {
32
34
  data: { msg: message, code }
33
35
  } = responseData;
34
36
  } catch (error) {
35
- throw new Error('core.groupFileRename 请求返回格式出错,请检查 mirai-console');
37
+ throw new Error(('请求返回格式出错,请检查 mirai-console'));
36
38
  }
37
39
  // 抛出 mirai 的异常,到 catch 中处理后再抛出
38
40
  if (code in errCodeMap) {
@@ -40,6 +42,7 @@ module.exports = async ({ baseUrl, sessionKey, target, id, rename }) => {
40
42
  }
41
43
  return { message, code };
42
44
  } catch (error) {
45
+ console.error(`mirai-js: error ${locationStr}`);
43
46
  errorHandler(error);
44
47
  }
45
48
  };
@@ -1,4 +1,4 @@
1
- const { errCodeMap } = require('../util/errCode');
1
+ const { errCodeMap } = require('../../util/errCode');
2
2
  const axios = require('axios').default;
3
3
  let URL;
4
4
  if (!process.browser) {
@@ -6,7 +6,9 @@ if (!process.browser) {
6
6
  } else {
7
7
  URL = window.URL;
8
8
  }
9
- const errorHandler = require('../util/errorHandler');
9
+ const errorHandler = require('../../util/errorHandler');
10
+ const path = require('path');
11
+ const locationStr = `core.${path.basename(__filename, path.extname(__filename))}`;
10
12
  const FormData = require('form-data');
11
13
 
12
14
 
@@ -16,14 +18,14 @@ const FormData = require('form-data');
16
18
  * @param {string} sessionKey 会话标识
17
19
  * @param {string} type "friend" 或 "group",目前仅支持 group
18
20
  * @param {string} target 群/好友号
19
- * @param {string} path 上传目录
21
+ * @param {string} path 上传目录id
20
22
  * @param {Buffer} file 文件二进制数据
21
23
  * @returns {string} 文件 id
22
24
  */
23
25
  module.exports = async ({ baseUrl, sessionKey, type, target, path, file }) => {
24
26
  try {
25
27
  // 拼接 url
26
- const targetUrl = new URL('/uploadFileAndSend', baseUrl).toString();
28
+ const targetUrl = new URL('/file/upload', baseUrl).toString();
27
29
 
28
30
  // 构造 fromdata
29
31
  const form = new FormData();
@@ -45,7 +47,7 @@ module.exports = async ({ baseUrl, sessionKey, type, target, path, file }) => {
45
47
  data: { msg: message, code, id }
46
48
  } = responseData;
47
49
  } catch (error) {
48
- throw new Error('core.uploadFileAndSend 请求返回格式出错,请检查 mirai-console');
50
+ throw new Error(('请求返回格式出错,请检查 mirai-console'));
49
51
  }
50
52
 
51
53
  // 抛出 mirai 的异常,到 catch 中处理后再抛出
@@ -54,6 +56,7 @@ module.exports = async ({ baseUrl, sessionKey, type, target, path, file }) => {
54
56
  }
55
57
  return id;
56
58
  } catch (error) {
59
+ console.error(`mirai-js: error ${locationStr}`);
57
60
  errorHandler(error);
58
61
  }
59
62
  };
@@ -7,6 +7,8 @@ if (!process.browser) {
7
7
  URL = window.URL;
8
8
  }
9
9
  const errorHandler = require('../util/errorHandler');
10
+ const path = require('path');
11
+ const locationStr = `core.${path.basename(__filename, path.extname(__filename))}`;
10
12
 
11
13
  /**
12
14
  * @description 获取好友列表
@@ -24,7 +26,7 @@ module.exports = async ({ baseUrl, sessionKey }) => {
24
26
  try {
25
27
  var { data: { msg: message, code, data } } = responseData;
26
28
  } catch (error) {
27
- throw new Error('core.getFriendList 请求返回格式出错,请检查 mirai-console');
29
+ throw new Error(('请求返回格式出错,请检查 mirai-console'));
28
30
  }
29
31
 
30
32
  // 抛出 mirai 的异常,到 catch 中处理后再抛出
@@ -33,6 +35,7 @@ module.exports = async ({ baseUrl, sessionKey }) => {
33
35
  }
34
36
  return data;
35
37
  } catch (error) {
38
+ console.error(`mirai-js: error ${locationStr}`);
36
39
  errorHandler(error);
37
40
  }
38
41
  };
@@ -7,6 +7,8 @@ if (!process.browser) {
7
7
  URL = window.URL;
8
8
  }
9
9
  const errorHandler = require('../util/errorHandler');
10
+ const path = require('path');
11
+ const locationStr = `core.${path.basename(__filename, path.extname(__filename))}`;
10
12
 
11
13
  /**
12
14
  * @description 获取群配置
@@ -25,7 +27,7 @@ module.exports = async ({ baseUrl, sessionKey, target }) => {
25
27
  try {
26
28
  var { data, data: { msg: message, code } } = responseData;
27
29
  } catch (error) {
28
- throw new Error('core.getGroupConfig 请求返回格式出错,请检查 mirai-console');
30
+ throw new Error(('请求返回格式出错,请检查 mirai-console'));
29
31
  }
30
32
  // 抛出 mirai 的异常,到 catch 中处理后再抛出
31
33
  if (code in errCodeMap) {
@@ -33,6 +35,7 @@ module.exports = async ({ baseUrl, sessionKey, target }) => {
33
35
  }
34
36
  return data;
35
37
  } catch (error) {
38
+ console.error(`mirai-js: error ${locationStr}`);
36
39
  errorHandler(error);
37
40
  }
38
41
  };
@@ -7,6 +7,8 @@ if (!process.browser) {
7
7
  URL = window.URL;
8
8
  }
9
9
  const errorHandler = require('../util/errorHandler');
10
+ const path = require('path');
11
+ const locationStr = `core.${path.basename(__filename, path.extname(__filename))}`;
10
12
 
11
13
  /**
12
14
  * @description 获取群列表
@@ -24,7 +26,7 @@ module.exports = async ({ baseUrl, sessionKey }) => {
24
26
  try {
25
27
  var { data, data: { msg: message, code } } = responseData;
26
28
  } catch (error) {
27
- throw new Error('core.getGroupList 请求返回格式出错,请检查 mirai-console');
29
+ throw new Error(('请求返回格式出错,请检查 mirai-console'));
28
30
  }
29
31
 
30
32
  // 抛出 mirai 的异常,到 catch 中处理后再抛出
@@ -33,6 +35,7 @@ module.exports = async ({ baseUrl, sessionKey }) => {
33
35
  }
34
36
  return data;
35
37
  } catch (error) {
38
+ console.error(`mirai-js: error ${locationStr}`);
36
39
  errorHandler(error);
37
40
  }
38
41
  };
@@ -7,6 +7,8 @@ if (!process.browser) {
7
7
  URL = window.URL;
8
8
  }
9
9
  const errorHandler = require('../util/errorHandler');
10
+ const path = require('path');
11
+ const locationStr = `core.${path.basename(__filename, path.extname(__filename))}`;
10
12
 
11
13
  /**
12
14
  * @description 获取群成员信息
@@ -28,7 +30,7 @@ module.exports = async ({ baseUrl, sessionKey, target, memberId }) => {
28
30
  data: { msg: message, code, name, specialTitle }
29
31
  } = responseData;
30
32
  } catch (error) {
31
- throw new Error('core.getMemberInfo 请求返回格式出错,请检查 mirai-console');
33
+ throw new Error(('请求返回格式出错,请检查 mirai-console'));
32
34
  }
33
35
  // 抛出 mirai 的异常,到 catch 中处理后再抛出
34
36
  if (code in errCodeMap) {
@@ -36,6 +38,7 @@ module.exports = async ({ baseUrl, sessionKey, target, memberId }) => {
36
38
  }
37
39
  return { name, specialTitle };
38
40
  } catch (error) {
41
+ console.error(`mirai-js: error ${locationStr}`);
39
42
  errorHandler(error);
40
43
  }
41
44
 
@@ -7,6 +7,8 @@ if (!process.browser) {
7
7
  URL = window.URL;
8
8
  }
9
9
  const errorHandler = require('../util/errorHandler');
10
+ const path = require('path');
11
+ const locationStr = `core.${path.basename(__filename, path.extname(__filename))}`;
10
12
 
11
13
  /**
12
14
  * @description 获取指定群的成员列表
@@ -31,7 +33,7 @@ module.exports = async ({ baseUrl, sessionKey, target }) => {
31
33
  try {
32
34
  var { data, data: { msg: message, code } } = responseData;
33
35
  } catch (error) {
34
- throw new Error('core.getMemberList 请求返回格式出错,请检查 mirai-console');
36
+ throw new Error(('请求返回格式出错,请检查 mirai-console'));
35
37
  }
36
38
 
37
39
  // 抛出 mirai 的异常,到 catch 中处理后再抛出
@@ -40,6 +42,7 @@ module.exports = async ({ baseUrl, sessionKey, target }) => {
40
42
  }
41
43
  return data;
42
44
  } catch (error) {
45
+ console.error(`mirai-js: error ${locationStr}`);
43
46
  errorHandler(error);
44
47
  }
45
48
  };
@@ -7,6 +7,8 @@ if (!process.browser) {
7
7
  URL = window.URL;
8
8
  }
9
9
  const errorHandler = require('../util/errorHandler');
10
+ const path = require('path');
11
+ const locationStr = `core.${path.basename(__filename, path.extname(__filename))}`;
10
12
 
11
13
  /**
12
14
  * @description 获取指定 session 的 config
@@ -26,7 +28,7 @@ module.exports = async ({ baseUrl, sessionKey }) => {
26
28
  data: { data: { msg: message, code, cacheSize, enableWebsocket } },
27
29
  } = responseData;
28
30
  } catch (error) {
29
- throw new Error('core.getSessionConfig 请求返回格式出错,请检查 mirai-console');
31
+ throw new Error(('请求返回格式出错,请检查 mirai-console'));
30
32
  }
31
33
  // 抛出 mirai 的异常,到 catch 中处理后再抛出
32
34
  if (code in errCodeMap) {
@@ -34,6 +36,7 @@ module.exports = async ({ baseUrl, sessionKey }) => {
34
36
  }
35
37
  return { cacheSize, enableWebsocket };
36
38
  } catch (error) {
39
+ console.error(`mirai-js: error ${locationStr}`);
37
40
  errorHandler(error);
38
41
  }
39
42
 
package/src/core/mute.js CHANGED
@@ -7,6 +7,8 @@ if (!process.browser) {
7
7
  URL = window.URL;
8
8
  }
9
9
  const errorHandler = require('../util/errorHandler');
10
+ const path = require('path');
11
+ const locationStr = `core.${path.basename(__filename, path.extname(__filename))}`;
10
12
 
11
13
  /**
12
14
  * @description 禁言群成员
@@ -29,7 +31,7 @@ module.exports = async ({ baseUrl, sessionKey, target, memberId, time }) => {
29
31
  data: { code, msg: message }
30
32
  } = responseData;
31
33
  } catch (error) {
32
- throw new Error('core.mute 请求返回格式出错,请检查 mirai-console');
34
+ throw new Error(('请求返回格式出错,请检查 mirai-console'));
33
35
  }
34
36
  // 抛出 mirai 的异常,到 catch 中处理后再抛出
35
37
  if (code in errCodeMap) {
@@ -37,6 +39,7 @@ module.exports = async ({ baseUrl, sessionKey, target, memberId, time }) => {
37
39
  }
38
40
  return { message, code };
39
41
  } catch (error) {
42
+ console.error(`mirai-js: error ${locationStr}`);
40
43
  errorHandler(error);
41
44
  }
42
45
  };
@@ -7,6 +7,8 @@ if (!process.browser) {
7
7
  URL = window.URL;
8
8
  }
9
9
  const errorHandler = require('../util/errorHandler');
10
+ const path = require('path');
11
+ const locationStr = `core.${path.basename(__filename, path.extname(__filename))}`;
10
12
 
11
13
  /**
12
14
  * @description 全员禁言
@@ -27,7 +29,7 @@ module.exports = async ({ baseUrl, sessionKey, target }) => {
27
29
  data: { code, msg: message }
28
30
  } = responseData;
29
31
  } catch (error) {
30
- throw new Error('core.muteAll 请求返回格式出错,请检查 mirai-console');
32
+ throw new Error(('请求返回格式出错,请检查 mirai-console'));
31
33
  }
32
34
  // 抛出 mirai 的异常,到 catch 中处理后再抛出
33
35
  if (code in errCodeMap) {
@@ -35,6 +37,7 @@ module.exports = async ({ baseUrl, sessionKey, target }) => {
35
37
  }
36
38
  return { message, code };
37
39
  } catch (error) {
40
+ console.error(`mirai-js: error ${locationStr}`);
38
41
  errorHandler(error);
39
42
  }
40
43
  };
@@ -7,6 +7,8 @@ if (!process.browser) {
7
7
  URL = window.URL;
8
8
  }
9
9
  const errorHandler = require('../util/errorHandler');
10
+ const path = require('path');
11
+ const locationStr = `core.${path.basename(__filename, path.extname(__filename))}`;
10
12
 
11
13
  /**
12
14
  * @description 退出群聊
@@ -27,7 +29,7 @@ module.exports = async ({ baseUrl, sessionKey, target }) => {
27
29
  data: { msg: message, code }
28
30
  } = responseData;
29
31
  } catch (error) {
30
- throw new Error('core.quitGroup 请求返回格式出错,请检查 mirai-console');
32
+ throw new Error(('请求返回格式出错,请检查 mirai-console'));
31
33
  }
32
34
  // 抛出 mirai 的异常,到 catch 中处理后再抛出
33
35
  if (code in errCodeMap) {
@@ -35,6 +37,7 @@ module.exports = async ({ baseUrl, sessionKey, target }) => {
35
37
  }
36
38
  return { message, code };
37
39
  } catch (error) {
40
+ console.error(`mirai-js: error ${locationStr}`);
38
41
  errorHandler(error);
39
42
  }
40
43
 
@@ -7,6 +7,8 @@ if (!process.browser) {
7
7
  URL = window.URL;
8
8
  }
9
9
  const errorHandler = require('../util/errorHandler');
10
+ const path = require('path');
11
+ const locationStr = `core.${path.basename(__filename, path.extname(__filename))}`;
10
12
 
11
13
  /**
12
14
  * @description 撤回由 messageId 确定的消息
@@ -27,7 +29,7 @@ module.exports = async ({ baseUrl, sessionKey, target }) => {
27
29
  data: { code, msg: message }
28
30
  } = responseData;
29
31
  } catch (error) {
30
- throw new Error('core.recall 请求返回格式出错,请检查 mirai-console');
32
+ throw new Error(('请求返回格式出错,请检查 mirai-console'));
31
33
  }
32
34
  // 抛出 mirai 的异常,到 catch 中处理后再抛出
33
35
  if (code in errCodeMap) {
@@ -35,6 +37,7 @@ module.exports = async ({ baseUrl, sessionKey, target }) => {
35
37
  }
36
38
  return { message, code };
37
39
  } catch (error) {
40
+ console.error(`mirai-js: error ${locationStr}`);
38
41
  errorHandler(error);
39
42
  }
40
43
  };
@@ -7,6 +7,8 @@ if (!process.browser) {
7
7
  URL = window.URL;
8
8
  }
9
9
  const errorHandler = require('../util/errorHandler');
10
+ const path = require('path');
11
+ const locationStr = `core.${path.basename(__filename, path.extname(__filename))}`;
10
12
 
11
13
  /**
12
14
  * @description 关闭一个会话
@@ -27,7 +29,7 @@ module.exports = async ({ baseUrl, sessionKey, qq }) => {
27
29
  data: { msg: message, code }
28
30
  } = responseData;
29
31
  } catch (error) {
30
- throw new Error('core.releaseSession 请求返回格式出错,请检查 mirai-console');
32
+ throw new Error(('请求返回格式出错,请检查 mirai-console'));
31
33
  }
32
34
  // 抛出 mirai 的异常,到 catch 中处理后再抛出
33
35
  if (code in errCodeMap) {
@@ -35,6 +37,8 @@ module.exports = async ({ baseUrl, sessionKey, qq }) => {
35
37
  }
36
38
  return { message, code };
37
39
  } catch (error) {
40
+ console.error(`mirai-js: error ${locationStr}`);
41
+ console.error(`mirai-js: error ${locationStr}`);
38
42
  errorHandler(error);
39
43
  }
40
44
 
@@ -1,5 +1,5 @@
1
1
  const { errCodeMap } = require('../util/errCode');
2
- const axios = require('axios');
2
+ const axios = require('axios').default;
3
3
  let URL;
4
4
  if (!process.browser) {
5
5
  ({ URL } = require('url'));
@@ -7,31 +7,29 @@ if (!process.browser) {
7
7
  URL = window.URL;
8
8
  }
9
9
  const errorHandler = require('../util/errorHandler');
10
+ const path = require('path');
11
+ const locationStr = `core.${path.basename(__filename, path.extname(__filename))}`;
10
12
 
11
13
  /**
12
- * @description 删除群文件
14
+ * @description 删除好友
13
15
  * @param {string} baseUrl mirai-api-http server 的地址
14
16
  * @param {string} sessionKey 会话标识
15
- * @param {number} target 群号
16
- * @param {number} id 文件 id
17
+ * @param {number} target 欲删除好友的 qq 号
17
18
  * @returns {Object} 结构 { message, code }
18
19
  */
19
- module.exports = async ({ baseUrl, sessionKey, target, id }) => {
20
+ module.exports = async ({ baseUrl, sessionKey, target }) => {
20
21
  try {
21
22
  // 拼接 url
22
- const url = new URL('/groupFileDelete', baseUrl).toString();
23
+ const url = new URL('/deleteFriend', baseUrl).toString();
23
24
 
24
25
  // 请求
25
- const responseData = await axios.post(url, {
26
- sessionKey, target, id
27
- });
28
-
26
+ const responseData = await axios.post(url, { sessionKey, target });
29
27
  try {
30
28
  var {
31
29
  data: { msg: message, code }
32
30
  } = responseData;
33
31
  } catch (error) {
34
- throw new Error('core.groupFileDelete 请求返回格式出错,请检查 mirai-console');
32
+ throw new Error(('请求返回格式出错,请检查 mirai-console'));
35
33
  }
36
34
  // 抛出 mirai 的异常,到 catch 中处理后再抛出
37
35
  if (code in errCodeMap) {
@@ -39,6 +37,7 @@ module.exports = async ({ baseUrl, sessionKey, target, id }) => {
39
37
  }
40
38
  return { message, code };
41
39
  } catch (error) {
40
+ console.error(`mirai-js: error ${locationStr}`);
42
41
  errorHandler(error);
43
42
  }
44
43
 
@@ -7,6 +7,8 @@ if (!process.browser) {
7
7
  URL = window.URL;
8
8
  }
9
9
  const errorHandler = require('../util/errorHandler');
10
+ const path = require('path');
11
+ const locationStr = `core.${path.basename(__filename, path.extname(__filename))}`;
10
12
 
11
13
  /**
12
14
  * @description 移除群成员
@@ -29,7 +31,7 @@ module.exports = async ({ baseUrl, sessionKey, target, memberId, msg }) => {
29
31
  data: { msg: message, code }
30
32
  } = responseData;
31
33
  } catch (error) {
32
- throw new Error('core.removeMember 请求返回格式出错,请检查 mirai-console');
34
+ throw new Error(('请求返回格式出错,请检查 mirai-console'));
33
35
  }
34
36
  // 抛出 mirai 的异常,到 catch 中处理后再抛出
35
37
  if (code in errCodeMap) {
@@ -37,6 +39,7 @@ module.exports = async ({ baseUrl, sessionKey, target, memberId, msg }) => {
37
39
  }
38
40
  return { message, code };
39
41
  } catch (error) {
42
+ console.error(`mirai-js: error ${locationStr}`);
40
43
  errorHandler(error);
41
44
  }
42
45
 
@@ -7,6 +7,8 @@ if (!process.browser) {
7
7
  URL = window.URL;
8
8
  }
9
9
  const errorHandler = require('../util/errorHandler');
10
+ const path = require('path');
11
+ const locationStr = `core.${path.basename(__filename, path.extname(__filename))}`;
10
12
 
11
13
  /**
12
14
  * ! 自动同意时,不会触发该事件
@@ -35,13 +37,14 @@ module.exports = async ({ baseUrl, sessionKey, eventId, fromId, groupId, operate
35
37
  data: { code, msg: serverMessage }
36
38
  } = responseData;
37
39
  } catch (error) {
38
- throw new Error('core.responseBotlnviedJoinGroupRequest 请求返回格式出错,请检查 mirai-console');
40
+ throw new Error(('请求返回格式出错,请检查 mirai-console'));
39
41
  }
40
42
  // 抛出 mirai 的异常,到 catch 中处理后再抛出
41
43
  if (code in errCodeMap) {
42
44
  throw new Error(serverMessage);
43
45
  }
44
46
  } catch (error) {
47
+ console.error(`mirai-js: error ${locationStr}`);
45
48
  errorHandler(error);
46
49
  }
47
50
  };
@@ -7,6 +7,8 @@ if (!process.browser) {
7
7
  URL = window.URL;
8
8
  }
9
9
  const errorHandler = require('../util/errorHandler');
10
+ const path = require('path');
11
+ const locationStr = `core.${path.basename(__filename, path.extname(__filename))}`;
10
12
 
11
13
  /**
12
14
  * @description 响应好友请求
@@ -34,13 +36,14 @@ module.exports = async ({ baseUrl, sessionKey, eventId, fromId, groupId, operate
34
36
  data: { code, msg: serverMessage }
35
37
  } = responseData;
36
38
  } catch (error) {
37
- throw new Error('core.responseFirendRequest 请求返回格式出错,请检查 mirai-console');
39
+ throw new Error(('请求返回格式出错,请检查 mirai-console'));
38
40
  }
39
41
  // 抛出 mirai 的异常,到 catch 中处理后再抛出
40
42
  if (code in errCodeMap) {
41
43
  throw new Error(serverMessage);
42
44
  }
43
45
  } catch (error) {
46
+ console.error(`mirai-js: error ${locationStr}`);
44
47
  errorHandler(error);
45
48
  }
46
49
  };
@@ -7,6 +7,8 @@ if (!process.browser) {
7
7
  URL = window.URL;
8
8
  }
9
9
  const errorHandler = require('../util/errorHandler');
10
+ const path = require('path');
11
+ const locationStr = `core.${path.basename(__filename, path.extname(__filename))}`;
10
12
 
11
13
  /**
12
14
  * FIXME: mirai-core 的问题,有时候收不到 MemberJoinRequestEvent 事件
@@ -36,13 +38,14 @@ module.exports = async ({ baseUrl, sessionKey, eventId, fromId, groupId, operate
36
38
  data: { code, msg: serverMessage }
37
39
  } = responseData;
38
40
  } catch (error) {
39
- throw new Error('core.responseMember 请求返回格式出错,请检查 mirai-console');
41
+ throw new Error(('请求返回格式出错,请检查 mirai-console'));
40
42
  }
41
43
  // 抛出 mirai 的异常,到 catch 中处理后再抛出
42
44
  if (code in errCodeMap) {
43
45
  throw new Error(serverMessage);
44
46
  }
45
47
  } catch (error) {
48
+ console.error(`mirai-js: error ${locationStr}`);
46
49
  errorHandler(error);
47
50
  }
48
51
  };
@@ -7,6 +7,8 @@ if (!process.browser) {
7
7
  URL = window.URL;
8
8
  }
9
9
  const errorHandler = require('../util/errorHandler');
10
+ const path = require('path');
11
+ const locationStr = `core.${path.basename(__filename, path.extname(__filename))}`;
10
12
 
11
13
  /**
12
14
  * @description 向 mirai-console 发送指令
@@ -28,7 +30,7 @@ module.exports = async ({ baseUrl, sessionKey, command }) => {
28
30
  data: { msg: message, code },
29
31
  } = responseData;
30
32
  } catch (error) {
31
- throw new Error('core.sendCommand 请求返回格式出错,请检查 mirai-console');
33
+ throw new Error(('请求返回格式出错,请检查 mirai-console'));
32
34
  }
33
35
  // 抛出 mirai 的异常,到 catch 中处理后再抛出
34
36
  if (code in errCodeMap) {
@@ -36,6 +38,7 @@ module.exports = async ({ baseUrl, sessionKey, command }) => {
36
38
  }
37
39
  return { message, code };
38
40
  } catch (error) {
41
+ console.error(`mirai-js: error ${locationStr}`);
39
42
  errorHandler(error);
40
43
  }
41
44
 
@@ -7,6 +7,8 @@ if (!process.browser) {
7
7
  URL = window.URL;
8
8
  }
9
9
  const errorHandler = require('../util/errorHandler');
10
+ const path = require('path');
11
+ const locationStr = `core.${path.basename(__filename, path.extname(__filename))}`;
10
12
 
11
13
  /**
12
14
  * @description 向 qq 好友发送消息
@@ -31,7 +33,7 @@ module.exports = async ({ baseUrl, sessionKey, target, quote, messageChain }) =>
31
33
  data: { msg: message, code, messageId }
32
34
  } = responseData;
33
35
  } catch (error) {
34
- throw new Error('core.sendFirendMessage 请求返回格式出错,请检查 mirai-console');
36
+ throw new Error(('请求返回格式出错,请检查 mirai-console'));
35
37
  }
36
38
  // 抛出 mirai 的异常,到 catch 中处理后再抛出
37
39
  if (code in errCodeMap) {
@@ -39,6 +41,7 @@ module.exports = async ({ baseUrl, sessionKey, target, quote, messageChain }) =>
39
41
  }
40
42
  return messageId;
41
43
  } catch (error) {
44
+ console.error(`mirai-js: error ${locationStr}`);
42
45
  errorHandler(error);
43
46
  }
44
47
  };