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.
- package/.github/FUNDING.yml +1 -1
- package/demo.html +1 -1
- package/demo.js +19 -73
- package/dist/browser/mirai-js.js +1 -1
- package/dist/node/Bot.d.ts +16 -4
- package/dist/node/Bot.js +67 -11
- package/dist/node/FileManager.js +15 -6
- package/dist/node/core/auth.js +6 -2
- package/dist/node/core/fs/deleteGroupFile.js +77 -0
- package/dist/node/core/fs/getGroupFileInfo.js +83 -0
- package/dist/node/core/fs/getGroupFileList.js +88 -0
- package/dist/node/core/fs/makeGroupDir.js +79 -0
- package/dist/node/core/fs/moveGroupFile.js +83 -0
- package/dist/node/core/fs/renameGroupFile.js +79 -0
- package/dist/node/core/fs/uploadGroupFIle.js +87 -0
- package/dist/node/core/getFriendList.js +6 -2
- package/dist/node/core/getGroupConfig.js +6 -2
- package/dist/node/core/getGroupFileInfo.js +6 -2
- package/dist/node/core/getGroupFileList.js +6 -2
- package/dist/node/core/getGroupList.js +6 -2
- package/dist/node/core/getMemberInfo.js +6 -2
- package/dist/node/core/getMemberList.js +6 -2
- package/dist/node/core/getSessionConfig.js +6 -2
- 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 +6 -2
- package/dist/node/core/muteAll.js +6 -2
- package/dist/node/core/quitGroup.js +6 -2
- package/dist/node/core/recall.js +6 -2
- package/dist/node/core/releaseSession.js +7 -2
- package/dist/node/core/removeFriend.js +70 -0
- package/dist/node/core/removeMember.js +6 -2
- package/dist/node/core/responseBotInvitedJoinGroupRequest.js +6 -2
- package/dist/node/core/responseFirendRequest.js +6 -2
- package/dist/node/core/responseMemberJoinRequest.js +6 -2
- package/dist/node/core/sendCommand.js +6 -2
- package/dist/node/core/sendFirendMessage.js +6 -2
- package/dist/node/core/sendGroupMessage.js +6 -2
- package/dist/node/core/sendNudge.js +6 -2
- package/dist/node/core/sendTempMessage.js +6 -2
- package/dist/node/core/setEssence.js +6 -2
- package/dist/node/core/setGroupConfig.js +6 -2
- package/dist/node/core/setMemberAdmin.js +76 -0
- package/dist/node/core/setMemberInfo.js +6 -2
- package/dist/node/core/setSessionConfig.js +6 -2
- package/dist/node/core/startListeningBrowser.js +5 -1
- package/dist/node/core/startListeningNode.js +5 -1
- package/dist/node/core/stopListeningBrowser.js +5 -1
- package/dist/node/core/stopListeningNode.js +5 -1
- package/dist/node/core/unmute.js +6 -2
- package/dist/node/core/unmuteAll.js +6 -2
- package/dist/node/core/uploadFileAndSend.js +6 -1
- package/dist/node/core/uploadImage.js +6 -1
- package/dist/node/core/uploadVoice.js +6 -1
- package/dist/node/core/verify.js +6 -2
- package/package.json +2 -2
- package/src/Bot.d.ts +16 -4
- package/src/Bot.js +48 -7
- package/src/FileManager.js +10 -6
- package/src/core/auth.js +4 -1
- package/src/core/fs/deleteGroupFile.js +49 -0
- package/src/core/fs/getGroupFileInfo.js +50 -0
- package/src/core/fs/getGroupFileList.js +51 -0
- package/src/core/fs/makeGroupDir.js +49 -0
- package/src/core/fs/moveGroupFile.js +51 -0
- package/src/core/{groupFileRename.js → fs/renameGroupFile.js} +10 -7
- package/src/core/{uploadFileAndSend.js → fs/uploadGroupFIle.js} +8 -5
- package/src/core/getFriendList.js +4 -1
- package/src/core/getGroupConfig.js +4 -1
- package/src/core/getGroupList.js +4 -1
- package/src/core/getMemberInfo.js +4 -1
- package/src/core/getMemberList.js +4 -1
- package/src/core/getSessionConfig.js +4 -1
- package/src/core/mute.js +4 -1
- package/src/core/muteAll.js +4 -1
- package/src/core/quitGroup.js +4 -1
- package/src/core/recall.js +4 -1
- package/src/core/releaseSession.js +5 -1
- package/src/core/{groupFileDelete.js → removeFriend.js} +10 -11
- package/src/core/removeMember.js +4 -1
- package/src/core/responseBotInvitedJoinGroupRequest.js +4 -1
- package/src/core/responseFirendRequest.js +4 -1
- package/src/core/responseMemberJoinRequest.js +4 -1
- package/src/core/sendCommand.js +4 -1
- package/src/core/sendFirendMessage.js +4 -1
- package/src/core/sendGroupMessage.js +4 -1
- package/src/core/sendNudge.js +4 -1
- package/src/core/sendTempMessage.js +4 -1
- package/src/core/setEssence.js +4 -1
- package/src/core/setGroupConfig.js +4 -1
- package/src/core/setMemberAdmin.js +48 -0
- package/src/core/setMemberInfo.js +4 -1
- package/src/core/setSessionConfig.js +4 -1
- package/src/core/startListeningBrowser.js +3 -0
- package/src/core/startListeningNode.js +3 -0
- package/src/core/stopListeningBrowser.js +3 -0
- package/src/core/stopListeningNode.js +3 -0
- package/src/core/unmute.js +4 -1
- package/src/core/unmuteAll.js +4 -1
- package/src/core/uploadImage.js +4 -1
- package/src/core/uploadVoice.js +4 -1
- package/src/core/verify.js +4 -1
- 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
@@ -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('
|
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('
|
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,
|
22
|
+
module.exports = async ({ baseUrl, sessionKey, id, path, group, renameTo }) => {
|
21
23
|
try {
|
22
24
|
// 拼接 url
|
23
|
-
const url = new URL('/
|
25
|
+
const url = new URL('/file/rename', baseUrl).toString();
|
24
26
|
|
25
27
|
// 请求
|
26
28
|
const responseData = await axios.post(url, {
|
27
|
-
sessionKey, target,
|
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('
|
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('
|
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('
|
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('/
|
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('
|
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('
|
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('
|
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
|
};
|
package/src/core/getGroupList.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 获取群列表
|
@@ -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('
|
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('
|
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('
|
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('
|
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('
|
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
|
};
|
package/src/core/muteAll.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 全员禁言
|
@@ -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('
|
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
|
};
|
package/src/core/quitGroup.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 退出群聊
|
@@ -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('
|
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
|
|
package/src/core/recall.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 撤回由 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('
|
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('
|
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
|
20
|
+
module.exports = async ({ baseUrl, sessionKey, target }) => {
|
20
21
|
try {
|
21
22
|
// 拼接 url
|
22
|
-
const url = new URL('/
|
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('
|
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
|
|
package/src/core/removeMember.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, msg }) => {
|
|
29
31
|
data: { msg: message, code }
|
30
32
|
} = responseData;
|
31
33
|
} catch (error) {
|
32
|
-
throw new Error('
|
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('
|
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('
|
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('
|
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
|
};
|
package/src/core/sendCommand.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 向 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('
|
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('
|
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
|
};
|