mirai-js 2.1.0 → 2.4.0
Sign up to get free protection for your applications and to get access to all the features.
- package/.eslintrc.json +45 -45
- package/.github/FUNDING.yml +12 -12
- package/.github/dependabot.yml +14 -14
- package/.github/workflows/codeql-analysis.yml +70 -0
- package/.husky/pre-commit +5 -5
- package/LICENSE +661 -661
- package/README.md +17 -283
- package/demo.html +1 -1
- package/demo.js +14 -92
- package/dist/browser/mirai-js.js +1 -1
- package/dist/node/BaseType.d.ts +3 -0
- package/dist/node/Bot.d.ts +95 -8
- package/dist/node/Bot.js +241 -18
- package/dist/node/FileManager.js +15 -6
- package/dist/node/Middleware.js +90 -16
- 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/docs/checkDocShouldBuild.sh +4 -4
- package/package.json +51 -51
- package/src/BaseType.d.ts +3 -0
- package/src/Bot.d.ts +95 -8
- package/src/Bot.js +154 -9
- package/src/FileManager.js +10 -6
- package/src/Middleware.js +51 -3
- 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
@@ -0,0 +1,43 @@
|
|
1
|
+
const { errCodeMap } = require('../../util/errCode');
|
2
|
+
const axios = require('axios').default;
|
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} id 群号
|
13
|
+
* @param {number} offset 分页
|
14
|
+
* @param {number} size 分页, 默认 10
|
15
|
+
* @returns {Object[]}
|
16
|
+
*/
|
17
|
+
module.exports = async ({ baseUrl, sessionKey, id, offset, size = 10 }) => {
|
18
|
+
try {
|
19
|
+
// 拼接 url
|
20
|
+
const url = new URL('/anno/list', baseUrl).toString();
|
21
|
+
|
22
|
+
// 请求
|
23
|
+
const responseData = await axios.get(url, {
|
24
|
+
params: {
|
25
|
+
sessionKey, id, offset, size,
|
26
|
+
}
|
27
|
+
});
|
28
|
+
try {
|
29
|
+
var { data: { msg: message, code, data } } = responseData;
|
30
|
+
} catch (error) {
|
31
|
+
throw new Error(('请求返回格式出错,请检查 mirai-console'));
|
32
|
+
}
|
33
|
+
|
34
|
+
// 抛出 mirai 的异常,到 catch 中处理后再抛出
|
35
|
+
if (code in errCodeMap) {
|
36
|
+
throw new Error(message);
|
37
|
+
}
|
38
|
+
return data;
|
39
|
+
} catch (error) {
|
40
|
+
console.error(`mirai-js: error ${locationStr}`);
|
41
|
+
errorHandler(error);
|
42
|
+
}
|
43
|
+
};
|
@@ -0,0 +1,43 @@
|
|
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 群号
|
13
|
+
* @param {string} content 公告内容
|
14
|
+
* @param {boolean} pinned 是否置顶
|
15
|
+
* @returns {Object} { code, msg }
|
16
|
+
*/
|
17
|
+
module.exports = async ({ baseUrl, sessionKey, target, content, pinned }) => {
|
18
|
+
try {
|
19
|
+
// 拼接 url
|
20
|
+
const url = new URL('/anno/publish', baseUrl).toString();
|
21
|
+
|
22
|
+
// 请求
|
23
|
+
const responseData = await axios.post(url, {
|
24
|
+
sessionKey, target, content, pinned
|
25
|
+
});
|
26
|
+
try {
|
27
|
+
var {
|
28
|
+
data: { msg: message, code }
|
29
|
+
} = responseData;
|
30
|
+
} catch (error) {
|
31
|
+
throw new Error(('请求返回格式出错,请检查 mirai-console'));
|
32
|
+
}
|
33
|
+
// 抛出 mirai 的异常,到 catch 中处理后再抛出
|
34
|
+
if (code in errCodeMap) {
|
35
|
+
throw new Error(message);
|
36
|
+
}
|
37
|
+
return { message, code };
|
38
|
+
} catch (error) {
|
39
|
+
console.error(`mirai-js: error ${locationStr}`);
|
40
|
+
errorHandler(error);
|
41
|
+
}
|
42
|
+
|
43
|
+
};
|
package/src/core/auth.js
CHANGED
@@ -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
|
*
|
@@ -27,7 +24,7 @@ module.exports = async ({ baseUrl, verifyKey }) => {
|
|
27
24
|
data: { msg: message, code, session: sessionKey },
|
28
25
|
} = responseData;
|
29
26
|
} catch (error) {
|
30
|
-
throw new Error('
|
27
|
+
throw new Error(('请求返回格式出错,请检查 mirai-console'));
|
31
28
|
}
|
32
29
|
|
33
30
|
// 抛出 mirai 的异常,到 catch 中处理后再抛出
|
@@ -36,6 +33,7 @@ module.exports = async ({ baseUrl, verifyKey }) => {
|
|
36
33
|
}
|
37
34
|
return sessionKey;
|
38
35
|
} catch (error) {
|
36
|
+
console.error(`mirai-js: error ${locationStr}`);
|
39
37
|
errorHandler(error);
|
40
38
|
}
|
41
39
|
};
|
@@ -0,0 +1,44 @@
|
|
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 {string} id 文件夹id, 空串为根目录
|
13
|
+
* @param {string} path 文件夹路径, 文件夹允许重名, 不保证准确, 准确定位使用 id
|
14
|
+
* @param {number} group 群号
|
15
|
+
* @returns {Object} 结构 { message, code }
|
16
|
+
*/
|
17
|
+
module.exports = async ({ baseUrl, sessionKey, id, path, group }) => {
|
18
|
+
try {
|
19
|
+
// 拼接 url
|
20
|
+
const url = new URL('/file/delete', baseUrl).toString();
|
21
|
+
|
22
|
+
// 请求
|
23
|
+
const responseData = await axios.post(url, {
|
24
|
+
sessionKey, id, path, target: group, group,
|
25
|
+
});
|
26
|
+
|
27
|
+
try {
|
28
|
+
var {
|
29
|
+
data: { msg: message, code }
|
30
|
+
} = responseData;
|
31
|
+
} catch (error) {
|
32
|
+
throw new Error(('请求返回格式出错,请检查 mirai-console'));
|
33
|
+
}
|
34
|
+
// 抛出 mirai 的异常,到 catch 中处理后再抛出
|
35
|
+
if (code in errCodeMap) {
|
36
|
+
throw new Error(message);
|
37
|
+
}
|
38
|
+
return { message, code };
|
39
|
+
} catch (error) {
|
40
|
+
console.error(`mirai-js: error ${locationStr}`);
|
41
|
+
errorHandler(error);
|
42
|
+
}
|
43
|
+
|
44
|
+
};
|
@@ -0,0 +1,45 @@
|
|
1
|
+
const { errCodeMap } = require('../../util/errCode');
|
2
|
+
const axios = require('axios').default;
|
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 {string} id 文件夹id, 空串为根目录
|
13
|
+
* @param {string} path 文件夹路径, 文件夹允许重名, 不保证准确, 准确定位使用 id
|
14
|
+
* @param {number} group 群号
|
15
|
+
* @param {boolean} withDownloadInfo 是否携带下载信息,额外请求,无必要不要携带
|
16
|
+
* @returns {Object}
|
17
|
+
* 结构 { id, name, path, parent, contact, isFile, isDirectory, downloadInfo }
|
18
|
+
*/
|
19
|
+
module.exports = async ({ baseUrl, sessionKey, id, path, group/*, qq 字段保留 */, withDownloadInfo }) => {
|
20
|
+
try {
|
21
|
+
// 拼接 url
|
22
|
+
const url = new URL('/file/info', baseUrl).toString();
|
23
|
+
|
24
|
+
// 请求
|
25
|
+
const responseData = await axios.get(url, {
|
26
|
+
params: {
|
27
|
+
sessionKey, id, path, target: group, group, withDownloadInfo
|
28
|
+
}
|
29
|
+
});
|
30
|
+
try {
|
31
|
+
var { data: { msg: message, code, data } } = responseData;
|
32
|
+
} catch (error) {
|
33
|
+
throw new Error(('请求返回格式出错,请检查 mirai-console'));
|
34
|
+
}
|
35
|
+
|
36
|
+
// 抛出 mirai 的异常,到 catch 中处理后再抛出
|
37
|
+
if (code in errCodeMap) {
|
38
|
+
throw new Error(message);
|
39
|
+
}
|
40
|
+
return data;
|
41
|
+
} catch (error) {
|
42
|
+
console.error(`mirai-js: error ${locationStr}`);
|
43
|
+
errorHandler(error);
|
44
|
+
}
|
45
|
+
};
|
@@ -0,0 +1,46 @@
|
|
1
|
+
const { errCodeMap } = require('../../util/errCode');
|
2
|
+
const axios = require('axios').default;
|
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 {string} id 文件夹id, 空串为根目录
|
13
|
+
* @param {string} path 文件夹路径, 文件夹允许重名, 不保证准确, 准确定位使用 id
|
14
|
+
* @param {number} group 群号
|
15
|
+
* @param {boolern} withDownloadInfo 是否携带下载信息,额外请求,无必要不要携带
|
16
|
+
* @param {number} offset 分页偏移
|
17
|
+
* @param {number} size 分页大小
|
18
|
+
* @returns {Object[]} 结构 array[...{ id, name, path, parent, contact, isFile, isDirectory, downloadInfo }]
|
19
|
+
*/
|
20
|
+
module.exports = async ({ baseUrl, sessionKey, id, path, group/*, qq 字段保留 */, withDownloadInfo, offset, size }) => {
|
21
|
+
try {
|
22
|
+
// 拼接 url
|
23
|
+
const url = new URL('/file/list', baseUrl).toString();
|
24
|
+
|
25
|
+
// 请求
|
26
|
+
const responseData = await axios.get(url, {
|
27
|
+
params: {
|
28
|
+
sessionKey, id, path, target: group, group, withDownloadInfo, offset, size
|
29
|
+
}
|
30
|
+
});
|
31
|
+
try {
|
32
|
+
var { data: { msg: message, code, data } } = responseData;
|
33
|
+
} catch (error) {
|
34
|
+
throw new Error(('请求返回格式出错,请检查 mirai-console'));
|
35
|
+
}
|
36
|
+
|
37
|
+
// 抛出 mirai 的异常,到 catch 中处理后再抛出
|
38
|
+
if (code in errCodeMap) {
|
39
|
+
throw new Error(message);
|
40
|
+
}
|
41
|
+
return data;
|
42
|
+
} catch (error) {
|
43
|
+
console.error(`mirai-js: error ${locationStr}`);
|
44
|
+
errorHandler(error);
|
45
|
+
}
|
46
|
+
};
|
@@ -0,0 +1,44 @@
|
|
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 {string} id 文件夹id, 空串为根目录
|
13
|
+
* @param {string} path 文件夹路径, 文件夹允许重名, 不保证准确, 准确定位使用 id
|
14
|
+
* @param {number} group 群号
|
15
|
+
* @param {boolern} withDownloadInfo 是否携带下载信息,额外请求,无必要不要携带
|
16
|
+
* @returns {Object} 结构 { id, name, path, parent, contact, isFile, isDirectory, downloadInfo }
|
17
|
+
*/
|
18
|
+
module.exports = async ({ baseUrl, sessionKey, id, rename, path, group, withDownloadInfo }) => {
|
19
|
+
try {
|
20
|
+
// 拼接 url
|
21
|
+
const url = new URL('/file/mkdir', baseUrl).toString();
|
22
|
+
|
23
|
+
// 请求
|
24
|
+
const responseData = await axios.post(url, {
|
25
|
+
sessionKey, id, rename, path, group, withDownloadInfo
|
26
|
+
});
|
27
|
+
|
28
|
+
try {
|
29
|
+
var {
|
30
|
+
data: { msg: message, code, data }
|
31
|
+
} = responseData;
|
32
|
+
} catch (error) {
|
33
|
+
throw new Error(('请求返回格式出错,请检查 mirai-console'));
|
34
|
+
}
|
35
|
+
// 抛出 mirai 的异常,到 catch 中处理后再抛出
|
36
|
+
if (code in errCodeMap) {
|
37
|
+
throw new Error(message);
|
38
|
+
}
|
39
|
+
return data;
|
40
|
+
} catch (error) {
|
41
|
+
console.error(`mirai-js: error ${locationStr}`);
|
42
|
+
errorHandler(error);
|
43
|
+
}
|
44
|
+
};
|
@@ -0,0 +1,46 @@
|
|
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 {string} id 文件夹id, 空串为根目录
|
13
|
+
* @param {string} path 文件夹路径, 文件夹允许重名, 不保证准确, 准确定位使用 id
|
14
|
+
* @param {number} group 群号
|
15
|
+
* @param {string} moveTo 移动目标文件夹id
|
16
|
+
* @param {string} moveToPath 移动目标文件夹path
|
17
|
+
* @returns {Object} 结构 { message, code }
|
18
|
+
*/
|
19
|
+
module.exports = async ({ baseUrl, sessionKey, id, path, group, moveTo, moveToPath }) => {
|
20
|
+
try {
|
21
|
+
// 拼接 url
|
22
|
+
const url = new URL('/file/move', baseUrl).toString();
|
23
|
+
|
24
|
+
// 请求
|
25
|
+
const responseData = await axios.post(url, {
|
26
|
+
sessionKey, id, path, target: group, group, moveTo, moveToPath
|
27
|
+
});
|
28
|
+
|
29
|
+
try {
|
30
|
+
var {
|
31
|
+
data: { msg: message, code }
|
32
|
+
} = responseData;
|
33
|
+
} catch (error) {
|
34
|
+
throw new Error(('请求返回格式出错,请检查 mirai-console'));
|
35
|
+
}
|
36
|
+
// 抛出 mirai 的异常,到 catch 中处理后再抛出
|
37
|
+
if (code in errCodeMap) {
|
38
|
+
throw new Error(message);
|
39
|
+
}
|
40
|
+
return { message, code };
|
41
|
+
} catch (error) {
|
42
|
+
console.error(`mirai-js: error ${locationStr}`);
|
43
|
+
errorHandler(error);
|
44
|
+
}
|
45
|
+
|
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
|
|