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
package/dist/node/Bot.js
CHANGED
@@ -35,6 +35,8 @@ const _getMemberInfo = require('./core/getMemberInfo');
|
|
35
35
|
|
36
36
|
const _setMemberInfo = require('./core/setMemberInfo');
|
37
37
|
|
38
|
+
const _setMemberAdmin = require('./core/setMemberAdmin');
|
39
|
+
|
38
40
|
const _recall = require('./core/recall');
|
39
41
|
|
40
42
|
const _mute = require('./core/mute');
|
@@ -47,6 +49,8 @@ const _unmuteAll = require('./core/unmuteAll');
|
|
47
49
|
|
48
50
|
const _removeMember = require('./core/removeMember');
|
49
51
|
|
52
|
+
const _removeFriend = require('./core/removeFriend');
|
53
|
+
|
50
54
|
const _quitGroup = require('./core/quitGroup');
|
51
55
|
|
52
56
|
const _getGroupConfig = require('./core/getGroupConfig');
|
@@ -953,6 +957,8 @@ class Bot extends BotConfigGetable {
|
|
953
957
|
* @param {number} qq 必选,群成员的 qq 号
|
954
958
|
* @param {string} name 可选,要设置的群名片
|
955
959
|
* @param {string} title 可选,要设置的群头衔
|
960
|
+
* @param {boolean} permission 可选,要设置的权限,
|
961
|
+
* 使用枚举值:Bot.Permission.Admin, Bot.Permission.Member
|
956
962
|
* @returns {void}
|
957
963
|
*/
|
958
964
|
|
@@ -961,7 +967,8 @@ class Bot extends BotConfigGetable {
|
|
961
967
|
group,
|
962
968
|
qq,
|
963
969
|
name,
|
964
|
-
title
|
970
|
+
title,
|
971
|
+
permission
|
965
972
|
}) {
|
966
973
|
// 检查对象状态
|
967
974
|
if (!this.config) {
|
@@ -974,21 +981,39 @@ class Bot extends BotConfigGetable {
|
|
974
981
|
group,
|
975
982
|
qq
|
976
983
|
})} 参数`);
|
977
|
-
}
|
984
|
+
}
|
985
|
+
|
986
|
+
if (permission != undefined && permission != Bot.groupPermission.ADMINISTRATOR && permission != Bot.groupPermission.MEMBER) {
|
987
|
+
throw new Error('setMemberInfo admin 参数只能是 Bot.groupPermission.ADMINISTRATOR 或 Bot.groupPermission.Member');
|
988
|
+
} // setMemberInfo
|
978
989
|
|
979
990
|
|
980
991
|
const {
|
981
992
|
baseUrl,
|
982
993
|
sessionKey
|
983
994
|
} = this.config;
|
984
|
-
|
985
|
-
|
986
|
-
|
987
|
-
|
988
|
-
|
989
|
-
|
990
|
-
|
991
|
-
|
995
|
+
|
996
|
+
if (name != undefined || title != undefined) {
|
997
|
+
await _setMemberInfo({
|
998
|
+
baseUrl,
|
999
|
+
sessionKey,
|
1000
|
+
target: group,
|
1001
|
+
memberId: qq,
|
1002
|
+
name,
|
1003
|
+
specialTitle: title
|
1004
|
+
});
|
1005
|
+
} // setPermission
|
1006
|
+
|
1007
|
+
|
1008
|
+
if (permission != undefined) {
|
1009
|
+
await _setMemberAdmin({
|
1010
|
+
baseUrl,
|
1011
|
+
sessionKey,
|
1012
|
+
target: group,
|
1013
|
+
memberId: qq,
|
1014
|
+
assign: permission == Bot.groupPermission.ADMINISTRATOR ? true : false
|
1015
|
+
});
|
1016
|
+
}
|
992
1017
|
}
|
993
1018
|
/**
|
994
1019
|
* @description 禁言群成员
|
@@ -1170,6 +1195,37 @@ class Bot extends BotConfigGetable {
|
|
1170
1195
|
msg: message
|
1171
1196
|
});
|
1172
1197
|
}
|
1198
|
+
/**
|
1199
|
+
* @description 删除好友
|
1200
|
+
* @param {*} qq 欲删除的好友 qq 号
|
1201
|
+
* @returns {void}
|
1202
|
+
*/
|
1203
|
+
|
1204
|
+
|
1205
|
+
async removeFriend({
|
1206
|
+
qq
|
1207
|
+
}) {
|
1208
|
+
// 检查对象状态
|
1209
|
+
if (!this.config) {
|
1210
|
+
throw new Error('removeFriend 请先调用 open,建立一个会话');
|
1211
|
+
} // 检查参数
|
1212
|
+
|
1213
|
+
|
1214
|
+
if (!qq) {
|
1215
|
+
throw new Error('removeFriend 缺少必要的 qq 参数');
|
1216
|
+
}
|
1217
|
+
|
1218
|
+
const {
|
1219
|
+
baseUrl,
|
1220
|
+
sessionKey
|
1221
|
+
} = this.config; // 删除好友
|
1222
|
+
|
1223
|
+
await _removeFriend({
|
1224
|
+
baseUrl,
|
1225
|
+
sessionKey,
|
1226
|
+
target: qq
|
1227
|
+
});
|
1228
|
+
}
|
1173
1229
|
/**
|
1174
1230
|
* @description 移除群成员
|
1175
1231
|
* @param {number} group 必选,欲移除的成员所在群号
|
@@ -1180,7 +1236,7 @@ class Bot extends BotConfigGetable {
|
|
1180
1236
|
async quitGroup({
|
1181
1237
|
group
|
1182
1238
|
}) {
|
1183
|
-
// 检查对象状态
|
1239
|
+
// 检查对象状态
|
1184
1240
|
if (!this.config) {
|
1185
1241
|
throw new Error('quitGroup 请先调用 open,建立一个会话');
|
1186
1242
|
} // 检查参数
|
package/dist/node/FileManager.js
CHANGED
@@ -18,7 +18,7 @@ class FileManager {
|
|
18
18
|
|
19
19
|
this._getGroupFileList = ({
|
20
20
|
dir
|
21
|
-
}) => require('./core/getGroupFileList')({
|
21
|
+
}) => require('./core/fs/getGroupFileList')({
|
22
22
|
baseUrl,
|
23
23
|
sessionKey,
|
24
24
|
target: group,
|
@@ -27,7 +27,7 @@ class FileManager {
|
|
27
27
|
|
28
28
|
this._getGroupFileInfo = ({
|
29
29
|
id
|
30
|
-
}) => require('./core/getGroupFileInfo')({
|
30
|
+
}) => require('./core/fs/getGroupFileInfo')({
|
31
31
|
baseUrl,
|
32
32
|
sessionKey,
|
33
33
|
target: group,
|
@@ -38,7 +38,7 @@ class FileManager {
|
|
38
38
|
type,
|
39
39
|
path,
|
40
40
|
file
|
41
|
-
}) => require('./core/
|
41
|
+
}) => require('./core/fs/uploadGroupFIle')({
|
42
42
|
baseUrl,
|
43
43
|
sessionKey,
|
44
44
|
type,
|
@@ -49,17 +49,26 @@ class FileManager {
|
|
49
49
|
|
50
50
|
this._groupFileDelete = ({
|
51
51
|
id
|
52
|
-
}) => require('./core/
|
52
|
+
}) => require('./core/fs/deleteGroupFile')({
|
53
53
|
baseUrl,
|
54
54
|
sessionKey,
|
55
55
|
target: group,
|
56
56
|
id
|
57
57
|
});
|
58
58
|
|
59
|
+
this._makeGroupDir = ({
|
60
|
+
dir
|
61
|
+
}) => require('./core/fs/makeGroupDir')({
|
62
|
+
baseUrl,
|
63
|
+
sessionKey,
|
64
|
+
target: group,
|
65
|
+
dir
|
66
|
+
});
|
67
|
+
|
59
68
|
this._groupFileRename = ({
|
60
69
|
id,
|
61
70
|
rename
|
62
|
-
}) => require('./core/
|
71
|
+
}) => require('./core/fs/renameGroupFile')({
|
63
72
|
baseUrl,
|
64
73
|
sessionKey,
|
65
74
|
target: group,
|
@@ -70,7 +79,7 @@ class FileManager {
|
|
70
79
|
this._groupFileMove = ({
|
71
80
|
id,
|
72
81
|
movePath
|
73
|
-
}) => require('./core/
|
82
|
+
}) => require('./core/fs/moveGroupFile')({
|
74
83
|
baseUrl,
|
75
84
|
sessionKey,
|
76
85
|
target: group,
|
package/dist/node/core/auth.js
CHANGED
@@ -17,6 +17,10 @@ if (!process.browser) {
|
|
17
17
|
}
|
18
18
|
|
19
19
|
const errorHandler = require('../util/errorHandler');
|
20
|
+
|
21
|
+
const path = require('path');
|
22
|
+
|
23
|
+
const locationStr = `core.${path.basename(__filename, path.extname(__filename))}`;
|
20
24
|
/**
|
21
25
|
*
|
22
26
|
* @description 认证 verifyKey,创建回话,返回一个 sessionKey
|
@@ -25,7 +29,6 @@ const errorHandler = require('../util/errorHandler');
|
|
25
29
|
* @returns {string} 会话标识 sessionKey
|
26
30
|
*/
|
27
31
|
|
28
|
-
|
29
32
|
module.exports = async ({
|
30
33
|
baseUrl,
|
31
34
|
verifyKey
|
@@ -47,7 +50,7 @@ module.exports = async ({
|
|
47
50
|
}
|
48
51
|
} = responseData;
|
49
52
|
} catch (error) {
|
50
|
-
throw new Error('
|
53
|
+
throw new Error('请求返回格式出错,请检查 mirai-console');
|
51
54
|
} // 抛出 mirai 的异常,到 catch 中处理后再抛出
|
52
55
|
|
53
56
|
|
@@ -57,6 +60,7 @@ module.exports = async ({
|
|
57
60
|
|
58
61
|
return sessionKey;
|
59
62
|
} catch (error) {
|
63
|
+
console.error(`mirai-js: error ${locationStr}`);
|
60
64
|
errorHandler(error);
|
61
65
|
}
|
62
66
|
};
|
@@ -0,0 +1,77 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
const {
|
4
|
+
errCodeMap
|
5
|
+
} = require('../../util/errCode');
|
6
|
+
|
7
|
+
const axios = require('axios');
|
8
|
+
|
9
|
+
let URL;
|
10
|
+
|
11
|
+
if (!process.browser) {
|
12
|
+
({
|
13
|
+
URL
|
14
|
+
} = require('url'));
|
15
|
+
} else {
|
16
|
+
URL = window.URL;
|
17
|
+
}
|
18
|
+
|
19
|
+
const errorHandler = require('../../util/errorHandler');
|
20
|
+
|
21
|
+
const path = require('path');
|
22
|
+
|
23
|
+
const locationStr = `core.${path.basename(__filename, path.extname(__filename))}`;
|
24
|
+
/**
|
25
|
+
* @description 删除群文件
|
26
|
+
* @param {string} baseUrl mirai-api-http server 的地址
|
27
|
+
* @param {string} sessionKey 会话标识
|
28
|
+
* @param {string} id 文件夹id, 空串为根目录
|
29
|
+
* @param {string} path 文件夹路径, 文件夹允许重名, 不保证准确, 准确定位使用 id
|
30
|
+
* @param {number} group 群号
|
31
|
+
* @returns {Object} 结构 { message, code }
|
32
|
+
*/
|
33
|
+
|
34
|
+
module.exports = async ({
|
35
|
+
baseUrl,
|
36
|
+
sessionKey,
|
37
|
+
id,
|
38
|
+
path,
|
39
|
+
group
|
40
|
+
}) => {
|
41
|
+
try {
|
42
|
+
// 拼接 url
|
43
|
+
const url = new URL('/file/delete', baseUrl).toString(); // 请求
|
44
|
+
|
45
|
+
const responseData = await axios.post(url, {
|
46
|
+
sessionKey,
|
47
|
+
id,
|
48
|
+
path,
|
49
|
+
target: group,
|
50
|
+
group
|
51
|
+
});
|
52
|
+
|
53
|
+
try {
|
54
|
+
var {
|
55
|
+
data: {
|
56
|
+
msg: message,
|
57
|
+
code
|
58
|
+
}
|
59
|
+
} = responseData;
|
60
|
+
} catch (error) {
|
61
|
+
throw new Error('请求返回格式出错,请检查 mirai-console');
|
62
|
+
} // 抛出 mirai 的异常,到 catch 中处理后再抛出
|
63
|
+
|
64
|
+
|
65
|
+
if (code in errCodeMap) {
|
66
|
+
throw new Error(message);
|
67
|
+
}
|
68
|
+
|
69
|
+
return {
|
70
|
+
message,
|
71
|
+
code
|
72
|
+
};
|
73
|
+
} catch (error) {
|
74
|
+
console.error(`mirai-js: error ${locationStr}`);
|
75
|
+
errorHandler(error);
|
76
|
+
}
|
77
|
+
};
|
@@ -0,0 +1,83 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
const {
|
4
|
+
errCodeMap
|
5
|
+
} = require('../../util/errCode');
|
6
|
+
|
7
|
+
const axios = require('axios').default;
|
8
|
+
|
9
|
+
let URL;
|
10
|
+
|
11
|
+
if (!process.browser) {
|
12
|
+
({
|
13
|
+
URL
|
14
|
+
} = require('url'));
|
15
|
+
} else {
|
16
|
+
URL = window.URL;
|
17
|
+
}
|
18
|
+
|
19
|
+
const errorHandler = require('../../util/errorHandler');
|
20
|
+
|
21
|
+
const path = require('path');
|
22
|
+
|
23
|
+
const locationStr = `core.${path.basename(__filename, path.extname(__filename))}`;
|
24
|
+
/**
|
25
|
+
* @description 获取群文件详细信息
|
26
|
+
* @param {string} baseUrl mirai-api-http server 的地址
|
27
|
+
* @param {string} sessionKey 会话标识
|
28
|
+
* @param {string} id 文件夹id, 空串为根目录
|
29
|
+
* @param {string} path 文件夹路径, 文件夹允许重名, 不保证准确, 准确定位使用 id
|
30
|
+
* @param {number} group 群号
|
31
|
+
* @param {boolean} withDownloadInfo 是否携带下载信息,额外请求,无必要不要携带
|
32
|
+
* @returns {Object}
|
33
|
+
* 结构 { id, name, path, parent, contact, isFile, isDirectory, downloadInfo }
|
34
|
+
*/
|
35
|
+
|
36
|
+
module.exports = async ({
|
37
|
+
baseUrl,
|
38
|
+
sessionKey,
|
39
|
+
id,
|
40
|
+
path,
|
41
|
+
group
|
42
|
+
/*, qq 字段保留 */
|
43
|
+
,
|
44
|
+
withDownloadInfo
|
45
|
+
}) => {
|
46
|
+
try {
|
47
|
+
// 拼接 url
|
48
|
+
const url = new URL('/file/info', baseUrl).toString(); // 请求
|
49
|
+
|
50
|
+
const responseData = await axios.get(url, {
|
51
|
+
params: {
|
52
|
+
sessionKey,
|
53
|
+
id,
|
54
|
+
path,
|
55
|
+
target: group,
|
56
|
+
group,
|
57
|
+
withDownloadInfo
|
58
|
+
}
|
59
|
+
});
|
60
|
+
|
61
|
+
try {
|
62
|
+
var {
|
63
|
+
data: {
|
64
|
+
msg: message,
|
65
|
+
code,
|
66
|
+
data
|
67
|
+
}
|
68
|
+
} = responseData;
|
69
|
+
} catch (error) {
|
70
|
+
throw new Error('请求返回格式出错,请检查 mirai-console');
|
71
|
+
} // 抛出 mirai 的异常,到 catch 中处理后再抛出
|
72
|
+
|
73
|
+
|
74
|
+
if (code in errCodeMap) {
|
75
|
+
throw new Error(message);
|
76
|
+
}
|
77
|
+
|
78
|
+
return data;
|
79
|
+
} catch (error) {
|
80
|
+
console.error(`mirai-js: error ${locationStr}`);
|
81
|
+
errorHandler(error);
|
82
|
+
}
|
83
|
+
};
|
@@ -0,0 +1,88 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
const {
|
4
|
+
errCodeMap
|
5
|
+
} = require('../../util/errCode');
|
6
|
+
|
7
|
+
const axios = require('axios').default;
|
8
|
+
|
9
|
+
let URL;
|
10
|
+
|
11
|
+
if (!process.browser) {
|
12
|
+
({
|
13
|
+
URL
|
14
|
+
} = require('url'));
|
15
|
+
} else {
|
16
|
+
URL = window.URL;
|
17
|
+
}
|
18
|
+
|
19
|
+
const errorHandler = require('../../util/errorHandler');
|
20
|
+
|
21
|
+
const path = require('path');
|
22
|
+
|
23
|
+
const locationStr = `core.${path.basename(__filename, path.extname(__filename))}`;
|
24
|
+
/**
|
25
|
+
* @description 获取群文件列表
|
26
|
+
* @param {string} baseUrl mirai-api-http server 的地址
|
27
|
+
* @param {string} sessionKey 会话标识
|
28
|
+
* @param {string} id 文件夹id, 空串为根目录
|
29
|
+
* @param {string} path 文件夹路径, 文件夹允许重名, 不保证准确, 准确定位使用 id
|
30
|
+
* @param {number} group 群号
|
31
|
+
* @param {boolern} withDownloadInfo 是否携带下载信息,额外请求,无必要不要携带
|
32
|
+
* @param {number} offset 分页偏移
|
33
|
+
* @param {number} size 分页大小
|
34
|
+
* @returns {Object[]} 结构 array[...{ id, name, path, parent, contact, isFile, isDirectory, downloadInfo }]
|
35
|
+
*/
|
36
|
+
|
37
|
+
module.exports = async ({
|
38
|
+
baseUrl,
|
39
|
+
sessionKey,
|
40
|
+
id,
|
41
|
+
path,
|
42
|
+
group
|
43
|
+
/*, qq 字段保留 */
|
44
|
+
,
|
45
|
+
withDownloadInfo,
|
46
|
+
offset,
|
47
|
+
size
|
48
|
+
}) => {
|
49
|
+
try {
|
50
|
+
// 拼接 url
|
51
|
+
const url = new URL('/file/list', baseUrl).toString(); // 请求
|
52
|
+
|
53
|
+
const responseData = await axios.get(url, {
|
54
|
+
params: {
|
55
|
+
sessionKey,
|
56
|
+
id,
|
57
|
+
path,
|
58
|
+
target: group,
|
59
|
+
group,
|
60
|
+
withDownloadInfo,
|
61
|
+
offset,
|
62
|
+
size
|
63
|
+
}
|
64
|
+
});
|
65
|
+
|
66
|
+
try {
|
67
|
+
var {
|
68
|
+
data: {
|
69
|
+
msg: message,
|
70
|
+
code,
|
71
|
+
data
|
72
|
+
}
|
73
|
+
} = responseData;
|
74
|
+
} catch (error) {
|
75
|
+
throw new Error('请求返回格式出错,请检查 mirai-console');
|
76
|
+
} // 抛出 mirai 的异常,到 catch 中处理后再抛出
|
77
|
+
|
78
|
+
|
79
|
+
if (code in errCodeMap) {
|
80
|
+
throw new Error(message);
|
81
|
+
}
|
82
|
+
|
83
|
+
return data;
|
84
|
+
} catch (error) {
|
85
|
+
console.error(`mirai-js: error ${locationStr}`);
|
86
|
+
errorHandler(error);
|
87
|
+
}
|
88
|
+
};
|
@@ -0,0 +1,79 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
const {
|
4
|
+
errCodeMap
|
5
|
+
} = require('../../util/errCode');
|
6
|
+
|
7
|
+
const axios = require('axios');
|
8
|
+
|
9
|
+
let URL;
|
10
|
+
|
11
|
+
if (!process.browser) {
|
12
|
+
({
|
13
|
+
URL
|
14
|
+
} = require('url'));
|
15
|
+
} else {
|
16
|
+
URL = window.URL;
|
17
|
+
}
|
18
|
+
|
19
|
+
const errorHandler = require('../../util/errorHandler');
|
20
|
+
|
21
|
+
const path = require('path');
|
22
|
+
|
23
|
+
const locationStr = `core.${path.basename(__filename, path.extname(__filename))}`;
|
24
|
+
/**
|
25
|
+
* @description 新建群文件夹
|
26
|
+
* @param {string} baseUrl mirai-api-http server 的地址
|
27
|
+
* @param {string} sessionKey 会话标识
|
28
|
+
* @param {string} id 文件夹id, 空串为根目录
|
29
|
+
* @param {string} path 文件夹路径, 文件夹允许重名, 不保证准确, 准确定位使用 id
|
30
|
+
* @param {number} group 群号
|
31
|
+
* @param {boolern} withDownloadInfo 是否携带下载信息,额外请求,无必要不要携带
|
32
|
+
* @returns {Object} 结构 { id, name, path, parent, contact, isFile, isDirectory, downloadInfo }
|
33
|
+
*/
|
34
|
+
|
35
|
+
module.exports = async ({
|
36
|
+
baseUrl,
|
37
|
+
sessionKey,
|
38
|
+
id,
|
39
|
+
rename,
|
40
|
+
path,
|
41
|
+
group,
|
42
|
+
withDownloadInfo
|
43
|
+
}) => {
|
44
|
+
try {
|
45
|
+
// 拼接 url
|
46
|
+
const url = new URL('/file/mkdir', baseUrl).toString(); // 请求
|
47
|
+
|
48
|
+
const responseData = await axios.post(url, {
|
49
|
+
sessionKey,
|
50
|
+
id,
|
51
|
+
rename,
|
52
|
+
path,
|
53
|
+
group,
|
54
|
+
withDownloadInfo
|
55
|
+
});
|
56
|
+
|
57
|
+
try {
|
58
|
+
var {
|
59
|
+
data: {
|
60
|
+
msg: message,
|
61
|
+
code,
|
62
|
+
data
|
63
|
+
}
|
64
|
+
} = responseData;
|
65
|
+
} catch (error) {
|
66
|
+
throw new Error('请求返回格式出错,请检查 mirai-console');
|
67
|
+
} // 抛出 mirai 的异常,到 catch 中处理后再抛出
|
68
|
+
|
69
|
+
|
70
|
+
if (code in errCodeMap) {
|
71
|
+
throw new Error(message);
|
72
|
+
}
|
73
|
+
|
74
|
+
return data;
|
75
|
+
} catch (error) {
|
76
|
+
console.error(`mirai-js: error ${locationStr}`);
|
77
|
+
errorHandler(error);
|
78
|
+
}
|
79
|
+
};
|
@@ -0,0 +1,83 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
const {
|
4
|
+
errCodeMap
|
5
|
+
} = require('../../util/errCode');
|
6
|
+
|
7
|
+
const axios = require('axios');
|
8
|
+
|
9
|
+
let URL;
|
10
|
+
|
11
|
+
if (!process.browser) {
|
12
|
+
({
|
13
|
+
URL
|
14
|
+
} = require('url'));
|
15
|
+
} else {
|
16
|
+
URL = window.URL;
|
17
|
+
}
|
18
|
+
|
19
|
+
const errorHandler = require('../../util/errorHandler');
|
20
|
+
|
21
|
+
const path = require('path');
|
22
|
+
|
23
|
+
const locationStr = `core.${path.basename(__filename, path.extname(__filename))}`;
|
24
|
+
/**
|
25
|
+
* @description 移动群文件
|
26
|
+
* @param {string} baseUrl mirai-api-http server 的地址
|
27
|
+
* @param {string} sessionKey 会话标识
|
28
|
+
* @param {string} id 文件夹id, 空串为根目录
|
29
|
+
* @param {string} path 文件夹路径, 文件夹允许重名, 不保证准确, 准确定位使用 id
|
30
|
+
* @param {number} group 群号
|
31
|
+
* @param {string} moveTo 移动目标文件夹id
|
32
|
+
* @param {string} moveToPath 移动目标文件夹path
|
33
|
+
* @returns {Object} 结构 { message, code }
|
34
|
+
*/
|
35
|
+
|
36
|
+
module.exports = async ({
|
37
|
+
baseUrl,
|
38
|
+
sessionKey,
|
39
|
+
id,
|
40
|
+
path,
|
41
|
+
group,
|
42
|
+
moveTo,
|
43
|
+
moveToPath
|
44
|
+
}) => {
|
45
|
+
try {
|
46
|
+
// 拼接 url
|
47
|
+
const url = new URL('/file/move', baseUrl).toString(); // 请求
|
48
|
+
|
49
|
+
const responseData = await axios.post(url, {
|
50
|
+
sessionKey,
|
51
|
+
id,
|
52
|
+
path,
|
53
|
+
target: group,
|
54
|
+
group,
|
55
|
+
moveTo,
|
56
|
+
moveToPath
|
57
|
+
});
|
58
|
+
|
59
|
+
try {
|
60
|
+
var {
|
61
|
+
data: {
|
62
|
+
msg: message,
|
63
|
+
code
|
64
|
+
}
|
65
|
+
} = responseData;
|
66
|
+
} catch (error) {
|
67
|
+
throw new Error('请求返回格式出错,请检查 mirai-console');
|
68
|
+
} // 抛出 mirai 的异常,到 catch 中处理后再抛出
|
69
|
+
|
70
|
+
|
71
|
+
if (code in errCodeMap) {
|
72
|
+
throw new Error(message);
|
73
|
+
}
|
74
|
+
|
75
|
+
return {
|
76
|
+
message,
|
77
|
+
code
|
78
|
+
};
|
79
|
+
} catch (error) {
|
80
|
+
console.error(`mirai-js: error ${locationStr}`);
|
81
|
+
errorHandler(error);
|
82
|
+
}
|
83
|
+
};
|