mirai-js 2.2.0 → 2.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/FUNDING.yml +1 -1
- package/README.md +17 -283
- package/demo.html +1 -1
- package/demo.js +13 -71
- package/dist/browser/mirai-js.js +1 -1
- package/dist/node/BaseType.d.ts +5 -2
- package/dist/node/Bot.d.ts +95 -8
- package/dist/node/Bot.js +233 -10
- package/dist/node/FileManager.js +15 -6
- package/dist/node/core/anno/deleteAnno.js +67 -0
- package/dist/node/core/anno/getAnno.js +70 -0
- package/dist/node/core/anno/publishAnno.js +70 -0
- package/dist/node/core/auth.js +9 -11
- package/dist/node/core/fs/deleteGroupFile.js +71 -0
- package/dist/node/core/fs/getGroupFileInfo.js +77 -0
- package/dist/node/core/fs/getGroupFileList.js +82 -0
- package/dist/node/core/fs/makeGroupDir.js +73 -0
- package/dist/node/core/fs/moveGroupFile.js +77 -0
- package/dist/node/core/fs/renameGroupFile.js +73 -0
- package/dist/node/core/fs/uploadGroupFIle.js +81 -0
- package/dist/node/core/getFriendList.js +9 -11
- package/dist/node/core/getGroupConfig.js +9 -11
- package/dist/node/core/getGroupFileInfo.js +6 -2
- package/dist/node/core/getGroupFileList.js +6 -2
- package/dist/node/core/getGroupList.js +9 -11
- package/dist/node/core/getMemberInfo.js +13 -19
- package/dist/node/core/getMemberList.js +9 -11
- package/dist/node/core/getSessionConfig.js +9 -11
- package/dist/node/core/getUserProfile.js +78 -0
- package/dist/node/core/groupFileDelete.js +6 -2
- package/dist/node/core/groupFileMove.js +6 -2
- package/dist/node/core/groupFileRename.js +6 -2
- package/dist/node/core/mute.js +9 -11
- package/dist/node/core/muteAll.js +9 -11
- package/dist/node/core/quitGroup.js +9 -11
- package/dist/node/core/recall.js +9 -11
- package/dist/node/core/releaseSession.js +10 -11
- package/dist/node/core/removeFriend.js +64 -0
- package/dist/node/core/removeMember.js +9 -11
- package/dist/node/core/responseBotInvitedJoinGroupRequest.js +9 -11
- package/dist/node/core/responseFirendRequest.js +9 -11
- package/dist/node/core/responseMemberJoinRequest.js +9 -11
- package/dist/node/core/sendCommand.js +9 -11
- package/dist/node/core/sendFirendMessage.js +9 -11
- package/dist/node/core/sendGroupMessage.js +9 -11
- package/dist/node/core/sendNudge.js +9 -11
- package/dist/node/core/sendTempMessage.js +9 -11
- package/dist/node/core/setEssence.js +9 -11
- package/dist/node/core/setGroupConfig.js +9 -11
- package/dist/node/core/setMemberAdmin.js +70 -0
- package/dist/node/core/setMemberInfo.js +9 -11
- package/dist/node/core/setSessionConfig.js +9 -11
- package/dist/node/core/startListeningBrowser.js +8 -9
- package/dist/node/core/startListeningNode.js +8 -10
- package/dist/node/core/stopListeningBrowser.js +5 -1
- package/dist/node/core/stopListeningNode.js +5 -1
- package/dist/node/core/unmute.js +9 -11
- package/dist/node/core/unmuteAll.js +9 -11
- package/dist/node/core/uploadFileAndSend.js +6 -1
- package/dist/node/core/uploadImage.js +9 -10
- package/dist/node/core/uploadVoice.js +9 -10
- package/dist/node/core/verify.js +9 -11
- package/dist/node/polyfill/URL.js +5 -0
- package/dist/node/polyfill/wsListener.js +6 -0
- package/package.json +2 -2
- package/src/BaseType.d.ts +5 -2
- package/src/Bot.d.ts +95 -8
- package/src/Bot.js +154 -9
- package/src/FileManager.js +10 -6
- package/src/core/anno/deleteAnno.js +42 -0
- package/src/core/anno/getAnno.js +43 -0
- package/src/core/anno/publishAnno.js +43 -0
- package/src/core/auth.js +5 -7
- package/src/core/fs/deleteGroupFile.js +44 -0
- package/src/core/fs/getGroupFileInfo.js +45 -0
- package/src/core/fs/getGroupFileList.js +46 -0
- package/src/core/fs/makeGroupDir.js +44 -0
- package/src/core/fs/moveGroupFile.js +46 -0
- package/src/core/{groupFileRename.js → fs/renameGroupFile.js} +11 -13
- package/src/core/{uploadFileAndSend.js → fs/uploadGroupFIle.js} +9 -11
- package/src/core/getFriendList.js +5 -7
- package/src/core/getGroupConfig.js +5 -7
- package/src/core/getGroupList.js +5 -7
- package/src/core/getMemberInfo.js +8 -10
- package/src/core/getMemberList.js +5 -7
- package/src/core/getSessionConfig.js +5 -7
- package/src/core/getUserProfile.js +39 -0
- package/src/core/mute.js +5 -7
- package/src/core/muteAll.js +5 -7
- package/src/core/quitGroup.js +5 -7
- package/src/core/recall.js +5 -7
- package/src/core/releaseSession.js +6 -7
- package/src/core/{groupFileDelete.js → removeFriend.js} +11 -17
- package/src/core/removeMember.js +5 -7
- package/src/core/responseBotInvitedJoinGroupRequest.js +5 -7
- package/src/core/responseFirendRequest.js +5 -7
- package/src/core/responseMemberJoinRequest.js +5 -7
- package/src/core/sendCommand.js +5 -7
- package/src/core/sendFirendMessage.js +5 -7
- package/src/core/sendGroupMessage.js +5 -7
- package/src/core/sendNudge.js +5 -7
- package/src/core/sendTempMessage.js +5 -7
- package/src/core/setEssence.js +5 -7
- package/src/core/setGroupConfig.js +5 -7
- package/src/core/setMemberAdmin.js +43 -0
- package/src/core/setMemberInfo.js +5 -7
- package/src/core/setSessionConfig.js +5 -7
- package/src/core/startListeningBrowser.js +4 -6
- package/src/core/startListeningNode.js +4 -6
- package/src/core/stopListeningBrowser.js +3 -0
- package/src/core/stopListeningNode.js +3 -0
- package/src/core/unmute.js +5 -7
- package/src/core/unmuteAll.js +5 -7
- package/src/core/uploadImage.js +5 -7
- package/src/core/uploadVoice.js +5 -7
- package/src/core/verify.js +5 -7
- package/src/polyfill/URL.js +3 -0
- package/src/polyfill/wsListener.js +4 -0
- package/webpack.config.js +4 -0
- package/src/core/getGroupFileInfo.js +0 -44
- package/src/core/getGroupFileList.js +0 -40
- package/src/core/groupFileMove.js +0 -46
@@ -1,30 +1,27 @@
|
|
1
|
-
const { errCodeMap } = require('
|
1
|
+
const { errCodeMap } = require('../../util/errCode');
|
2
2
|
const axios = require('axios');
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
URL = window.URL;
|
8
|
-
}
|
9
|
-
const errorHandler = require('../util/errorHandler');
|
3
|
+
const { URL } = require('../../polyfill/URL');
|
4
|
+
const errorHandler = require('../../util/errorHandler');
|
5
|
+
const path = require('path');
|
6
|
+
const locationStr = `core.${path.basename(__filename, path.extname(__filename))}`;
|
10
7
|
|
11
8
|
/**
|
12
9
|
* @description 重命名群文件
|
13
10
|
* @param {string} baseUrl mirai-api-http server 的地址
|
14
11
|
* @param {string} sessionKey 会话标识
|
15
|
-
* @param {number} target 群号
|
16
12
|
* @param {number} id 文件 id
|
13
|
+
* @param {number} group 群号
|
17
14
|
* @param {string} rename 重命名
|
18
15
|
* @returns {Object} 结构 { message, code }
|
19
16
|
*/
|
20
|
-
module.exports = async ({ baseUrl, sessionKey,
|
17
|
+
module.exports = async ({ baseUrl, sessionKey, id, path, group, renameTo }) => {
|
21
18
|
try {
|
22
19
|
// 拼接 url
|
23
|
-
const url = new URL('/
|
20
|
+
const url = new URL('/file/rename', baseUrl).toString();
|
24
21
|
|
25
22
|
// 请求
|
26
23
|
const responseData = await axios.post(url, {
|
27
|
-
sessionKey, target,
|
24
|
+
sessionKey, id, path, target: group, group, renameTo
|
28
25
|
});
|
29
26
|
|
30
27
|
try {
|
@@ -32,7 +29,7 @@ module.exports = async ({ baseUrl, sessionKey, target, id, rename }) => {
|
|
32
29
|
data: { msg: message, code }
|
33
30
|
} = responseData;
|
34
31
|
} catch (error) {
|
35
|
-
throw new Error('
|
32
|
+
throw new Error(('请求返回格式出错,请检查 mirai-console'));
|
36
33
|
}
|
37
34
|
// 抛出 mirai 的异常,到 catch 中处理后再抛出
|
38
35
|
if (code in errCodeMap) {
|
@@ -40,6 +37,7 @@ module.exports = async ({ baseUrl, sessionKey, target, id, rename }) => {
|
|
40
37
|
}
|
41
38
|
return { message, code };
|
42
39
|
} catch (error) {
|
40
|
+
console.error(`mirai-js: error ${locationStr}`);
|
43
41
|
errorHandler(error);
|
44
42
|
}
|
45
43
|
};
|
@@ -1,12 +1,9 @@
|
|
1
|
-
const { errCodeMap } = require('
|
1
|
+
const { errCodeMap } = require('../../util/errCode');
|
2
2
|
const axios = require('axios').default;
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
URL = window.URL;
|
8
|
-
}
|
9
|
-
const errorHandler = require('../util/errorHandler');
|
3
|
+
const { URL } = require('../../polyfill/URL');
|
4
|
+
const errorHandler = require('../../util/errorHandler');
|
5
|
+
const path = require('path');
|
6
|
+
const locationStr = `core.${path.basename(__filename, path.extname(__filename))}`;
|
10
7
|
const FormData = require('form-data');
|
11
8
|
|
12
9
|
|
@@ -16,14 +13,14 @@ const FormData = require('form-data');
|
|
16
13
|
* @param {string} sessionKey 会话标识
|
17
14
|
* @param {string} type "friend" 或 "group",目前仅支持 group
|
18
15
|
* @param {string} target 群/好友号
|
19
|
-
* @param {string} path 上传目录
|
16
|
+
* @param {string} path 上传目录id
|
20
17
|
* @param {Buffer} file 文件二进制数据
|
21
18
|
* @returns {string} 文件 id
|
22
19
|
*/
|
23
20
|
module.exports = async ({ baseUrl, sessionKey, type, target, path, file }) => {
|
24
21
|
try {
|
25
22
|
// 拼接 url
|
26
|
-
const targetUrl = new URL('/
|
23
|
+
const targetUrl = new URL('/file/upload', baseUrl).toString();
|
27
24
|
|
28
25
|
// 构造 fromdata
|
29
26
|
const form = new FormData();
|
@@ -45,7 +42,7 @@ module.exports = async ({ baseUrl, sessionKey, type, target, path, file }) => {
|
|
45
42
|
data: { msg: message, code, id }
|
46
43
|
} = responseData;
|
47
44
|
} catch (error) {
|
48
|
-
throw new Error('
|
45
|
+
throw new Error(('请求返回格式出错,请检查 mirai-console'));
|
49
46
|
}
|
50
47
|
|
51
48
|
// 抛出 mirai 的异常,到 catch 中处理后再抛出
|
@@ -54,6 +51,7 @@ module.exports = async ({ baseUrl, sessionKey, type, target, path, file }) => {
|
|
54
51
|
}
|
55
52
|
return id;
|
56
53
|
} catch (error) {
|
54
|
+
console.error(`mirai-js: error ${locationStr}`);
|
57
55
|
errorHandler(error);
|
58
56
|
}
|
59
57
|
};
|
@@ -1,12 +1,9 @@
|
|
1
1
|
const { errCodeMap } = require('../util/errCode');
|
2
2
|
const axios = require('axios').default;
|
3
|
-
|
4
|
-
if (!process.browser) {
|
5
|
-
({ URL } = require('url'));
|
6
|
-
} else {
|
7
|
-
URL = window.URL;
|
8
|
-
}
|
3
|
+
const { URL } = require('../polyfill/URL');
|
9
4
|
const errorHandler = require('../util/errorHandler');
|
5
|
+
const path = require('path');
|
6
|
+
const locationStr = `core.${path.basename(__filename, path.extname(__filename))}`;
|
10
7
|
|
11
8
|
/**
|
12
9
|
* @description 获取好友列表
|
@@ -24,7 +21,7 @@ module.exports = async ({ baseUrl, sessionKey }) => {
|
|
24
21
|
try {
|
25
22
|
var { data: { msg: message, code, data } } = responseData;
|
26
23
|
} catch (error) {
|
27
|
-
throw new Error('
|
24
|
+
throw new Error(('请求返回格式出错,请检查 mirai-console'));
|
28
25
|
}
|
29
26
|
|
30
27
|
// 抛出 mirai 的异常,到 catch 中处理后再抛出
|
@@ -33,6 +30,7 @@ module.exports = async ({ baseUrl, sessionKey }) => {
|
|
33
30
|
}
|
34
31
|
return data;
|
35
32
|
} catch (error) {
|
33
|
+
console.error(`mirai-js: error ${locationStr}`);
|
36
34
|
errorHandler(error);
|
37
35
|
}
|
38
36
|
};
|
@@ -1,12 +1,9 @@
|
|
1
1
|
const { errCodeMap } = require('../util/errCode');
|
2
2
|
const axios = require('axios').default;
|
3
|
-
|
4
|
-
if (!process.browser) {
|
5
|
-
({ URL } = require('url'));
|
6
|
-
} else {
|
7
|
-
URL = window.URL;
|
8
|
-
}
|
3
|
+
const { URL } = require('../polyfill/URL');
|
9
4
|
const errorHandler = require('../util/errorHandler');
|
5
|
+
const path = require('path');
|
6
|
+
const locationStr = `core.${path.basename(__filename, path.extname(__filename))}`;
|
10
7
|
|
11
8
|
/**
|
12
9
|
* @description 获取群配置
|
@@ -25,7 +22,7 @@ module.exports = async ({ baseUrl, sessionKey, target }) => {
|
|
25
22
|
try {
|
26
23
|
var { data, data: { msg: message, code } } = responseData;
|
27
24
|
} catch (error) {
|
28
|
-
throw new Error('
|
25
|
+
throw new Error(('请求返回格式出错,请检查 mirai-console'));
|
29
26
|
}
|
30
27
|
// 抛出 mirai 的异常,到 catch 中处理后再抛出
|
31
28
|
if (code in errCodeMap) {
|
@@ -33,6 +30,7 @@ module.exports = async ({ baseUrl, sessionKey, target }) => {
|
|
33
30
|
}
|
34
31
|
return data;
|
35
32
|
} catch (error) {
|
33
|
+
console.error(`mirai-js: error ${locationStr}`);
|
36
34
|
errorHandler(error);
|
37
35
|
}
|
38
36
|
};
|
package/src/core/getGroupList.js
CHANGED
@@ -1,12 +1,9 @@
|
|
1
1
|
const { errCodeMap } = require('../util/errCode');
|
2
2
|
const axios = require('axios').default;
|
3
|
-
|
4
|
-
if (!process.browser) {
|
5
|
-
({ URL } = require('url'));
|
6
|
-
} else {
|
7
|
-
URL = window.URL;
|
8
|
-
}
|
3
|
+
const { URL } = require('../polyfill/URL');
|
9
4
|
const errorHandler = require('../util/errorHandler');
|
5
|
+
const path = require('path');
|
6
|
+
const locationStr = `core.${path.basename(__filename, path.extname(__filename))}`;
|
10
7
|
|
11
8
|
/**
|
12
9
|
* @description 获取群列表
|
@@ -24,7 +21,7 @@ module.exports = async ({ baseUrl, sessionKey }) => {
|
|
24
21
|
try {
|
25
22
|
var { data, data: { msg: message, code } } = responseData;
|
26
23
|
} catch (error) {
|
27
|
-
throw new Error('
|
24
|
+
throw new Error(('请求返回格式出错,请检查 mirai-console'));
|
28
25
|
}
|
29
26
|
|
30
27
|
// 抛出 mirai 的异常,到 catch 中处理后再抛出
|
@@ -33,6 +30,7 @@ module.exports = async ({ baseUrl, sessionKey }) => {
|
|
33
30
|
}
|
34
31
|
return data;
|
35
32
|
} catch (error) {
|
33
|
+
console.error(`mirai-js: error ${locationStr}`);
|
36
34
|
errorHandler(error);
|
37
35
|
}
|
38
36
|
};
|
@@ -1,12 +1,9 @@
|
|
1
1
|
const { errCodeMap } = require('../util/errCode');
|
2
2
|
const axios = require('axios');
|
3
|
-
|
4
|
-
if (!process.browser) {
|
5
|
-
({ URL } = require('url'));
|
6
|
-
} else {
|
7
|
-
URL = window.URL;
|
8
|
-
}
|
3
|
+
const { URL } = require('../polyfill/URL');
|
9
4
|
const errorHandler = require('../util/errorHandler');
|
5
|
+
const path = require('path');
|
6
|
+
const locationStr = `core.${path.basename(__filename, path.extname(__filename))}`;
|
10
7
|
|
11
8
|
/**
|
12
9
|
* @description 获取群成员信息
|
@@ -14,7 +11,7 @@ const errorHandler = require('../util/errorHandler');
|
|
14
11
|
* @param {string} sessionKey 会话标识
|
15
12
|
* @param {number} target 群成员所在群号
|
16
13
|
* @param {number} memberId 群成员的 qq 号
|
17
|
-
* @returns {Object}
|
14
|
+
* @returns {Object}
|
18
15
|
*/
|
19
16
|
module.exports = async ({ baseUrl, sessionKey, target, memberId }) => {
|
20
17
|
try {
|
@@ -25,17 +22,18 @@ module.exports = async ({ baseUrl, sessionKey, target, memberId }) => {
|
|
25
22
|
const responseData = await axios.get(url, { params: { sessionKey, target, memberId } });
|
26
23
|
try {
|
27
24
|
var {
|
28
|
-
data: { msg: message, code
|
25
|
+
data, data: { msg: message, code }
|
29
26
|
} = responseData;
|
30
27
|
} catch (error) {
|
31
|
-
throw new Error('
|
28
|
+
throw new Error(('请求返回格式出错,请检查 mirai-console'));
|
32
29
|
}
|
33
30
|
// 抛出 mirai 的异常,到 catch 中处理后再抛出
|
34
31
|
if (code in errCodeMap) {
|
35
32
|
throw new Error(message);
|
36
33
|
}
|
37
|
-
return
|
34
|
+
return data;
|
38
35
|
} catch (error) {
|
36
|
+
console.error(`mirai-js: error ${locationStr}`);
|
39
37
|
errorHandler(error);
|
40
38
|
}
|
41
39
|
|
@@ -1,12 +1,9 @@
|
|
1
1
|
const { errCodeMap } = require('../util/errCode');
|
2
2
|
const axios = require('axios').default;
|
3
|
-
|
4
|
-
if (!process.browser) {
|
5
|
-
({ URL } = require('url'));
|
6
|
-
} else {
|
7
|
-
URL = window.URL;
|
8
|
-
}
|
3
|
+
const { URL } = require('../polyfill/URL');
|
9
4
|
const errorHandler = require('../util/errorHandler');
|
5
|
+
const path = require('path');
|
6
|
+
const locationStr = `core.${path.basename(__filename, path.extname(__filename))}`;
|
10
7
|
|
11
8
|
/**
|
12
9
|
* @description 获取指定群的成员列表
|
@@ -31,7 +28,7 @@ module.exports = async ({ baseUrl, sessionKey, target }) => {
|
|
31
28
|
try {
|
32
29
|
var { data, data: { msg: message, code } } = responseData;
|
33
30
|
} catch (error) {
|
34
|
-
throw new Error('
|
31
|
+
throw new Error(('请求返回格式出错,请检查 mirai-console'));
|
35
32
|
}
|
36
33
|
|
37
34
|
// 抛出 mirai 的异常,到 catch 中处理后再抛出
|
@@ -40,6 +37,7 @@ module.exports = async ({ baseUrl, sessionKey, target }) => {
|
|
40
37
|
}
|
41
38
|
return data;
|
42
39
|
} catch (error) {
|
40
|
+
console.error(`mirai-js: error ${locationStr}`);
|
43
41
|
errorHandler(error);
|
44
42
|
}
|
45
43
|
};
|
@@ -1,12 +1,9 @@
|
|
1
1
|
const { errCodeMap } = require('../util/errCode');
|
2
2
|
const axios = require('axios');
|
3
|
-
|
4
|
-
if (!process.browser) {
|
5
|
-
({ URL } = require('url'));
|
6
|
-
} else {
|
7
|
-
URL = window.URL;
|
8
|
-
}
|
3
|
+
const { URL } = require('../polyfill/URL');
|
9
4
|
const errorHandler = require('../util/errorHandler');
|
5
|
+
const path = require('path');
|
6
|
+
const locationStr = `core.${path.basename(__filename, path.extname(__filename))}`;
|
10
7
|
|
11
8
|
/**
|
12
9
|
* @description 获取指定 session 的 config
|
@@ -26,7 +23,7 @@ module.exports = async ({ baseUrl, sessionKey }) => {
|
|
26
23
|
data: { data: { msg: message, code, cacheSize, enableWebsocket } },
|
27
24
|
} = responseData;
|
28
25
|
} catch (error) {
|
29
|
-
throw new Error('
|
26
|
+
throw new Error(('请求返回格式出错,请检查 mirai-console'));
|
30
27
|
}
|
31
28
|
// 抛出 mirai 的异常,到 catch 中处理后再抛出
|
32
29
|
if (code in errCodeMap) {
|
@@ -34,6 +31,7 @@ module.exports = async ({ baseUrl, sessionKey }) => {
|
|
34
31
|
}
|
35
32
|
return { cacheSize, enableWebsocket };
|
36
33
|
} catch (error) {
|
34
|
+
console.error(`mirai-js: error ${locationStr}`);
|
37
35
|
errorHandler(error);
|
38
36
|
}
|
39
37
|
|
@@ -0,0 +1,39 @@
|
|
1
|
+
const { errCodeMap } = require('../util/errCode');
|
2
|
+
const axios = require('axios');
|
3
|
+
const { URL } = require('../polyfill/URL');
|
4
|
+
const errorHandler = require('../util/errorHandler');
|
5
|
+
const path = require('path');
|
6
|
+
const locationStr = `core.${path.basename(__filename, path.extname(__filename))}`;
|
7
|
+
|
8
|
+
/**
|
9
|
+
* @description 获取用户信息
|
10
|
+
* @param {string} baseUrl mirai-api-http server 的地址
|
11
|
+
* @param {string} sessionKey 会话标识
|
12
|
+
* @param {number} target qq 号
|
13
|
+
* @returns {Object} 结构 { nickname, email, age, level, sign, sex }
|
14
|
+
*/
|
15
|
+
module.exports = async ({ baseUrl, sessionKey, target, memberId }) => {
|
16
|
+
try {
|
17
|
+
// 拼接 url
|
18
|
+
const url = new URL('/userProfile', baseUrl).toString();
|
19
|
+
|
20
|
+
// 请求
|
21
|
+
const responseData = await axios.get(url, { params: { sessionKey, target, memberId } });
|
22
|
+
try {
|
23
|
+
var {
|
24
|
+
data: { msg: message, code, nickname, email, age, level, sign, sex }
|
25
|
+
} = responseData;
|
26
|
+
} catch (error) {
|
27
|
+
throw new Error('请求返回格式出错,请检查 mirai-console');
|
28
|
+
}
|
29
|
+
// 抛出 mirai 的异常,到 catch 中处理后再抛出
|
30
|
+
if (code in errCodeMap) {
|
31
|
+
throw new Error(message);
|
32
|
+
}
|
33
|
+
return { nickname, email, age, level, sign, sex };
|
34
|
+
} catch (error) {
|
35
|
+
console.error(`mirai-js: error ${locationStr}`);
|
36
|
+
errorHandler(error);
|
37
|
+
}
|
38
|
+
|
39
|
+
};
|
package/src/core/mute.js
CHANGED
@@ -1,12 +1,9 @@
|
|
1
1
|
const { errCodeMap } = require('../util/errCode');
|
2
2
|
const axios = require('axios').default;
|
3
|
-
|
4
|
-
if (!process.browser) {
|
5
|
-
({ URL } = require('url'));
|
6
|
-
} else {
|
7
|
-
URL = window.URL;
|
8
|
-
}
|
3
|
+
const { URL } = require('../polyfill/URL');
|
9
4
|
const errorHandler = require('../util/errorHandler');
|
5
|
+
const path = require('path');
|
6
|
+
const locationStr = `core.${path.basename(__filename, path.extname(__filename))}`;
|
10
7
|
|
11
8
|
/**
|
12
9
|
* @description 禁言群成员
|
@@ -29,7 +26,7 @@ module.exports = async ({ baseUrl, sessionKey, target, memberId, time }) => {
|
|
29
26
|
data: { code, msg: message }
|
30
27
|
} = responseData;
|
31
28
|
} catch (error) {
|
32
|
-
throw new Error('
|
29
|
+
throw new Error(('请求返回格式出错,请检查 mirai-console'));
|
33
30
|
}
|
34
31
|
// 抛出 mirai 的异常,到 catch 中处理后再抛出
|
35
32
|
if (code in errCodeMap) {
|
@@ -37,6 +34,7 @@ module.exports = async ({ baseUrl, sessionKey, target, memberId, time }) => {
|
|
37
34
|
}
|
38
35
|
return { message, code };
|
39
36
|
} catch (error) {
|
37
|
+
console.error(`mirai-js: error ${locationStr}`);
|
40
38
|
errorHandler(error);
|
41
39
|
}
|
42
40
|
};
|
package/src/core/muteAll.js
CHANGED
@@ -1,12 +1,9 @@
|
|
1
1
|
const { errCodeMap } = require('../util/errCode');
|
2
2
|
const axios = require('axios').default;
|
3
|
-
|
4
|
-
if (!process.browser) {
|
5
|
-
({ URL } = require('url'));
|
6
|
-
} else {
|
7
|
-
URL = window.URL;
|
8
|
-
}
|
3
|
+
const { URL } = require('../polyfill/URL');
|
9
4
|
const errorHandler = require('../util/errorHandler');
|
5
|
+
const path = require('path');
|
6
|
+
const locationStr = `core.${path.basename(__filename, path.extname(__filename))}`;
|
10
7
|
|
11
8
|
/**
|
12
9
|
* @description 全员禁言
|
@@ -27,7 +24,7 @@ module.exports = async ({ baseUrl, sessionKey, target }) => {
|
|
27
24
|
data: { code, msg: message }
|
28
25
|
} = responseData;
|
29
26
|
} catch (error) {
|
30
|
-
throw new Error('
|
27
|
+
throw new Error(('请求返回格式出错,请检查 mirai-console'));
|
31
28
|
}
|
32
29
|
// 抛出 mirai 的异常,到 catch 中处理后再抛出
|
33
30
|
if (code in errCodeMap) {
|
@@ -35,6 +32,7 @@ module.exports = async ({ baseUrl, sessionKey, target }) => {
|
|
35
32
|
}
|
36
33
|
return { message, code };
|
37
34
|
} catch (error) {
|
35
|
+
console.error(`mirai-js: error ${locationStr}`);
|
38
36
|
errorHandler(error);
|
39
37
|
}
|
40
38
|
};
|
package/src/core/quitGroup.js
CHANGED
@@ -1,12 +1,9 @@
|
|
1
1
|
const { errCodeMap } = require('../util/errCode');
|
2
2
|
const axios = require('axios').default;
|
3
|
-
|
4
|
-
if (!process.browser) {
|
5
|
-
({ URL } = require('url'));
|
6
|
-
} else {
|
7
|
-
URL = window.URL;
|
8
|
-
}
|
3
|
+
const { URL } = require('../polyfill/URL');
|
9
4
|
const errorHandler = require('../util/errorHandler');
|
5
|
+
const path = require('path');
|
6
|
+
const locationStr = `core.${path.basename(__filename, path.extname(__filename))}`;
|
10
7
|
|
11
8
|
/**
|
12
9
|
* @description 退出群聊
|
@@ -27,7 +24,7 @@ module.exports = async ({ baseUrl, sessionKey, target }) => {
|
|
27
24
|
data: { msg: message, code }
|
28
25
|
} = responseData;
|
29
26
|
} catch (error) {
|
30
|
-
throw new Error('
|
27
|
+
throw new Error(('请求返回格式出错,请检查 mirai-console'));
|
31
28
|
}
|
32
29
|
// 抛出 mirai 的异常,到 catch 中处理后再抛出
|
33
30
|
if (code in errCodeMap) {
|
@@ -35,6 +32,7 @@ module.exports = async ({ baseUrl, sessionKey, target }) => {
|
|
35
32
|
}
|
36
33
|
return { message, code };
|
37
34
|
} catch (error) {
|
35
|
+
console.error(`mirai-js: error ${locationStr}`);
|
38
36
|
errorHandler(error);
|
39
37
|
}
|
40
38
|
|
package/src/core/recall.js
CHANGED
@@ -1,12 +1,9 @@
|
|
1
1
|
const { errCodeMap } = require('../util/errCode');
|
2
2
|
const axios = require('axios').default;
|
3
|
-
|
4
|
-
if (!process.browser) {
|
5
|
-
({ URL } = require('url'));
|
6
|
-
} else {
|
7
|
-
URL = window.URL;
|
8
|
-
}
|
3
|
+
const { URL } = require('../polyfill/URL');
|
9
4
|
const errorHandler = require('../util/errorHandler');
|
5
|
+
const path = require('path');
|
6
|
+
const locationStr = `core.${path.basename(__filename, path.extname(__filename))}`;
|
10
7
|
|
11
8
|
/**
|
12
9
|
* @description 撤回由 messageId 确定的消息
|
@@ -27,7 +24,7 @@ module.exports = async ({ baseUrl, sessionKey, target }) => {
|
|
27
24
|
data: { code, msg: message }
|
28
25
|
} = responseData;
|
29
26
|
} catch (error) {
|
30
|
-
throw new Error('
|
27
|
+
throw new Error(('请求返回格式出错,请检查 mirai-console'));
|
31
28
|
}
|
32
29
|
// 抛出 mirai 的异常,到 catch 中处理后再抛出
|
33
30
|
if (code in errCodeMap) {
|
@@ -35,6 +32,7 @@ module.exports = async ({ baseUrl, sessionKey, target }) => {
|
|
35
32
|
}
|
36
33
|
return { message, code };
|
37
34
|
} catch (error) {
|
35
|
+
console.error(`mirai-js: error ${locationStr}`);
|
38
36
|
errorHandler(error);
|
39
37
|
}
|
40
38
|
};
|
@@ -1,12 +1,9 @@
|
|
1
1
|
const { errCodeMap } = require('../util/errCode');
|
2
2
|
const axios = require('axios').default;
|
3
|
-
|
4
|
-
if (!process.browser) {
|
5
|
-
({ URL } = require('url'));
|
6
|
-
} else {
|
7
|
-
URL = window.URL;
|
8
|
-
}
|
3
|
+
const { URL } = require('../polyfill/URL');
|
9
4
|
const errorHandler = require('../util/errorHandler');
|
5
|
+
const path = require('path');
|
6
|
+
const locationStr = `core.${path.basename(__filename, path.extname(__filename))}`;
|
10
7
|
|
11
8
|
/**
|
12
9
|
* @description 关闭一个会话
|
@@ -27,7 +24,7 @@ module.exports = async ({ baseUrl, sessionKey, qq }) => {
|
|
27
24
|
data: { msg: message, code }
|
28
25
|
} = responseData;
|
29
26
|
} catch (error) {
|
30
|
-
throw new Error('
|
27
|
+
throw new Error(('请求返回格式出错,请检查 mirai-console'));
|
31
28
|
}
|
32
29
|
// 抛出 mirai 的异常,到 catch 中处理后再抛出
|
33
30
|
if (code in errCodeMap) {
|
@@ -35,6 +32,8 @@ module.exports = async ({ baseUrl, sessionKey, qq }) => {
|
|
35
32
|
}
|
36
33
|
return { message, code };
|
37
34
|
} catch (error) {
|
35
|
+
console.error(`mirai-js: error ${locationStr}`);
|
36
|
+
console.error(`mirai-js: error ${locationStr}`);
|
38
37
|
errorHandler(error);
|
39
38
|
}
|
40
39
|
|
@@ -1,37 +1,30 @@
|
|
1
1
|
const { errCodeMap } = require('../util/errCode');
|
2
|
-
const axios = require('axios');
|
3
|
-
|
4
|
-
if (!process.browser) {
|
5
|
-
({ URL } = require('url'));
|
6
|
-
} else {
|
7
|
-
URL = window.URL;
|
8
|
-
}
|
2
|
+
const axios = require('axios').default;
|
3
|
+
const { URL } = require('../polyfill/URL');
|
9
4
|
const errorHandler = require('../util/errorHandler');
|
5
|
+
const path = require('path');
|
6
|
+
const locationStr = `core.${path.basename(__filename, path.extname(__filename))}`;
|
10
7
|
|
11
8
|
/**
|
12
|
-
* @description
|
9
|
+
* @description 删除好友
|
13
10
|
* @param {string} baseUrl mirai-api-http server 的地址
|
14
11
|
* @param {string} sessionKey 会话标识
|
15
|
-
* @param {number} target
|
16
|
-
* @param {number} id 文件 id
|
12
|
+
* @param {number} target 欲删除好友的 qq 号
|
17
13
|
* @returns {Object} 结构 { message, code }
|
18
14
|
*/
|
19
|
-
module.exports = async ({ baseUrl, sessionKey, target
|
15
|
+
module.exports = async ({ baseUrl, sessionKey, target }) => {
|
20
16
|
try {
|
21
17
|
// 拼接 url
|
22
|
-
const url = new URL('/
|
18
|
+
const url = new URL('/deleteFriend', baseUrl).toString();
|
23
19
|
|
24
20
|
// 请求
|
25
|
-
const responseData = await axios.post(url, {
|
26
|
-
sessionKey, target, id
|
27
|
-
});
|
28
|
-
|
21
|
+
const responseData = await axios.post(url, { sessionKey, target });
|
29
22
|
try {
|
30
23
|
var {
|
31
24
|
data: { msg: message, code }
|
32
25
|
} = responseData;
|
33
26
|
} catch (error) {
|
34
|
-
throw new Error('
|
27
|
+
throw new Error(('请求返回格式出错,请检查 mirai-console'));
|
35
28
|
}
|
36
29
|
// 抛出 mirai 的异常,到 catch 中处理后再抛出
|
37
30
|
if (code in errCodeMap) {
|
@@ -39,6 +32,7 @@ module.exports = async ({ baseUrl, sessionKey, target, id }) => {
|
|
39
32
|
}
|
40
33
|
return { message, code };
|
41
34
|
} catch (error) {
|
35
|
+
console.error(`mirai-js: error ${locationStr}`);
|
42
36
|
errorHandler(error);
|
43
37
|
}
|
44
38
|
|
package/src/core/removeMember.js
CHANGED
@@ -1,12 +1,9 @@
|
|
1
1
|
const { errCodeMap } = require('../util/errCode');
|
2
2
|
const axios = require('axios').default;
|
3
|
-
|
4
|
-
if (!process.browser) {
|
5
|
-
({ URL } = require('url'));
|
6
|
-
} else {
|
7
|
-
URL = window.URL;
|
8
|
-
}
|
3
|
+
const { URL } = require('../polyfill/URL');
|
9
4
|
const errorHandler = require('../util/errorHandler');
|
5
|
+
const path = require('path');
|
6
|
+
const locationStr = `core.${path.basename(__filename, path.extname(__filename))}`;
|
10
7
|
|
11
8
|
/**
|
12
9
|
* @description 移除群成员
|
@@ -29,7 +26,7 @@ module.exports = async ({ baseUrl, sessionKey, target, memberId, msg }) => {
|
|
29
26
|
data: { msg: message, code }
|
30
27
|
} = responseData;
|
31
28
|
} catch (error) {
|
32
|
-
throw new Error('
|
29
|
+
throw new Error(('请求返回格式出错,请检查 mirai-console'));
|
33
30
|
}
|
34
31
|
// 抛出 mirai 的异常,到 catch 中处理后再抛出
|
35
32
|
if (code in errCodeMap) {
|
@@ -37,6 +34,7 @@ module.exports = async ({ baseUrl, sessionKey, target, memberId, msg }) => {
|
|
37
34
|
}
|
38
35
|
return { message, code };
|
39
36
|
} catch (error) {
|
37
|
+
console.error(`mirai-js: error ${locationStr}`);
|
40
38
|
errorHandler(error);
|
41
39
|
}
|
42
40
|
|
@@ -1,12 +1,9 @@
|
|
1
1
|
const { errCodeMap } = require('../util/errCode');
|
2
2
|
const axios = require('axios');
|
3
|
-
|
4
|
-
if (!process.browser) {
|
5
|
-
({ URL } = require('url'));
|
6
|
-
} else {
|
7
|
-
URL = window.URL;
|
8
|
-
}
|
3
|
+
const { URL } = require('../polyfill/URL');
|
9
4
|
const errorHandler = require('../util/errorHandler');
|
5
|
+
const path = require('path');
|
6
|
+
const locationStr = `core.${path.basename(__filename, path.extname(__filename))}`;
|
10
7
|
|
11
8
|
/**
|
12
9
|
* ! 自动同意时,不会触发该事件
|
@@ -35,13 +32,14 @@ module.exports = async ({ baseUrl, sessionKey, eventId, fromId, groupId, operate
|
|
35
32
|
data: { code, msg: serverMessage }
|
36
33
|
} = responseData;
|
37
34
|
} catch (error) {
|
38
|
-
throw new Error('
|
35
|
+
throw new Error(('请求返回格式出错,请检查 mirai-console'));
|
39
36
|
}
|
40
37
|
// 抛出 mirai 的异常,到 catch 中处理后再抛出
|
41
38
|
if (code in errCodeMap) {
|
42
39
|
throw new Error(serverMessage);
|
43
40
|
}
|
44
41
|
} catch (error) {
|
42
|
+
console.error(`mirai-js: error ${locationStr}`);
|
45
43
|
errorHandler(error);
|
46
44
|
}
|
47
45
|
};
|