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
@@ -1,12 +1,15 @@
|
|
1
1
|
"use strict";
|
2
2
|
|
3
3
|
const errorHandler = require('../util/errorHandler');
|
4
|
+
|
5
|
+
const path = require('path');
|
6
|
+
|
7
|
+
const locationStr = `core.${path.basename(__filename, path.extname(__filename))}`;
|
4
8
|
/**
|
5
9
|
* @description 停止侦听事件
|
6
10
|
* @param {WebSocket} 建立连接的 WebSocket 实例
|
7
11
|
*/
|
8
12
|
|
9
|
-
|
10
13
|
module.exports = async wsConnection => {
|
11
14
|
try {
|
12
15
|
// 由于在 ws open 之前关闭连接会抛异常,故应先判断此时是否正在连接中
|
@@ -27,6 +30,7 @@ module.exports = async wsConnection => {
|
|
27
30
|
// do nothing
|
28
31
|
}
|
29
32
|
} catch (error) {
|
33
|
+
console.error(`mirai-js: error ${locationStr}`);
|
30
34
|
errorHandler(error);
|
31
35
|
}
|
32
36
|
};
|
@@ -1,12 +1,15 @@
|
|
1
1
|
"use strict";
|
2
2
|
|
3
3
|
const errorHandler = require('../util/errorHandler');
|
4
|
+
|
5
|
+
const path = require('path');
|
6
|
+
|
7
|
+
const locationStr = `core.${path.basename(__filename, path.extname(__filename))}`;
|
4
8
|
/**
|
5
9
|
* @description 停止侦听事件
|
6
10
|
* @param {WebSocket} 建立连接的 WebSocket 实例
|
7
11
|
*/
|
8
12
|
|
9
|
-
|
10
13
|
module.exports = async wsConnection => {
|
11
14
|
try {
|
12
15
|
// 由于在 ws open 之前关闭连接会抛异常,故应先判断此时是否正在连接中
|
@@ -27,6 +30,7 @@ module.exports = async wsConnection => {
|
|
27
30
|
// do nothing
|
28
31
|
}
|
29
32
|
} catch (error) {
|
33
|
+
console.error(`mirai-js: error ${locationStr}`);
|
30
34
|
errorHandler(error);
|
31
35
|
}
|
32
36
|
};
|
package/dist/node/core/unmute.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
|
* @description 解除禁言
|
22
26
|
* @param {string} baseUrl mirai-api-http server 的主机地址
|
@@ -26,7 +30,6 @@ const errorHandler = require('../util/errorHandler');
|
|
26
30
|
* @returns {Object} 结构 { message, code }
|
27
31
|
*/
|
28
32
|
|
29
|
-
|
30
33
|
module.exports = async ({
|
31
34
|
baseUrl,
|
32
35
|
sessionKey,
|
@@ -51,7 +54,7 @@ module.exports = async ({
|
|
51
54
|
}
|
52
55
|
} = responseData;
|
53
56
|
} catch (error) {
|
54
|
-
throw new Error('
|
57
|
+
throw new Error('请求返回格式出错,请检查 mirai-console');
|
55
58
|
} // 抛出 mirai 的异常,到 catch 中处理后再抛出
|
56
59
|
|
57
60
|
|
@@ -64,6 +67,7 @@ module.exports = async ({
|
|
64
67
|
code
|
65
68
|
};
|
66
69
|
} catch (error) {
|
70
|
+
console.error(`mirai-js: error ${locationStr}`);
|
67
71
|
errorHandler(error);
|
68
72
|
}
|
69
73
|
};
|
@@ -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
|
* @description 解除全员禁言
|
22
26
|
* @param {string} baseUrl mirai-api-http server 的主机地址
|
@@ -25,7 +29,6 @@ const errorHandler = require('../util/errorHandler');
|
|
25
29
|
* @returns {Object} 结构 { message, code }
|
26
30
|
*/
|
27
31
|
|
28
|
-
|
29
32
|
module.exports = async ({
|
30
33
|
baseUrl,
|
31
34
|
sessionKey,
|
@@ -48,7 +51,7 @@ module.exports = async ({
|
|
48
51
|
}
|
49
52
|
} = responseData;
|
50
53
|
} catch (error) {
|
51
|
-
throw new Error('
|
54
|
+
throw new Error('请求返回格式出错,请检查 mirai-console');
|
52
55
|
} // 抛出 mirai 的异常,到 catch 中处理后再抛出
|
53
56
|
|
54
57
|
|
@@ -61,6 +64,7 @@ module.exports = async ({
|
|
61
64
|
code
|
62
65
|
};
|
63
66
|
} catch (error) {
|
67
|
+
console.error(`mirai-js: error ${locationStr}`);
|
64
68
|
errorHandler(error);
|
65
69
|
}
|
66
70
|
};
|
@@ -18,6 +18,10 @@ if (!process.browser) {
|
|
18
18
|
|
19
19
|
const errorHandler = require('../util/errorHandler');
|
20
20
|
|
21
|
+
const path = require('path');
|
22
|
+
|
23
|
+
const locationStr = `core.${path.basename(__filename, path.extname(__filename))}`;
|
24
|
+
|
21
25
|
const FormData = require('form-data');
|
22
26
|
/**
|
23
27
|
* @description 上传文件至服务器并发送,返回文件 id
|
@@ -67,7 +71,7 @@ module.exports = async ({
|
|
67
71
|
}
|
68
72
|
} = responseData;
|
69
73
|
} catch (error) {
|
70
|
-
throw new Error('
|
74
|
+
throw new Error('请求返回格式出错,请检查 mirai-console');
|
71
75
|
} // 抛出 mirai 的异常,到 catch 中处理后再抛出
|
72
76
|
|
73
77
|
|
@@ -77,6 +81,7 @@ module.exports = async ({
|
|
77
81
|
|
78
82
|
return id;
|
79
83
|
} catch (error) {
|
84
|
+
console.error(`mirai-js: error ${locationStr}`);
|
80
85
|
errorHandler(error);
|
81
86
|
}
|
82
87
|
};
|
@@ -18,6 +18,10 @@ if (!process.browser) {
|
|
18
18
|
|
19
19
|
const errorHandler = require('../util/errorHandler');
|
20
20
|
|
21
|
+
const path = require('path');
|
22
|
+
|
23
|
+
const locationStr = `core.${path.basename(__filename, path.extname(__filename))}`;
|
24
|
+
|
21
25
|
const FormData = require('form-data');
|
22
26
|
/**
|
23
27
|
* @description 上传图片至服务器,返回指定 type 的 imageId,url,及 path
|
@@ -64,7 +68,7 @@ module.exports = async ({
|
|
64
68
|
}
|
65
69
|
} = responseData;
|
66
70
|
} catch (error) {
|
67
|
-
throw new Error('
|
71
|
+
throw new Error('请求返回格式出错,请检查 mirai-console');
|
68
72
|
} // 抛出 mirai 的异常,到 catch 中处理后再抛出
|
69
73
|
|
70
74
|
|
@@ -78,6 +82,7 @@ module.exports = async ({
|
|
78
82
|
path
|
79
83
|
};
|
80
84
|
} catch (error) {
|
85
|
+
console.error(`mirai-js: error ${locationStr}`);
|
81
86
|
errorHandler(error);
|
82
87
|
}
|
83
88
|
};
|
@@ -18,6 +18,10 @@ if (!process.browser) {
|
|
18
18
|
|
19
19
|
const errorHandler = require('../util/errorHandler');
|
20
20
|
|
21
|
+
const path = require('path');
|
22
|
+
|
23
|
+
const locationStr = `core.${path.basename(__filename, path.extname(__filename))}`;
|
24
|
+
|
21
25
|
const FormData = require('form-data');
|
22
26
|
/**
|
23
27
|
* FIXME: 目前该功能返回的 voiceId 无法正常使用,无法
|
@@ -65,7 +69,7 @@ module.exports = async ({
|
|
65
69
|
}
|
66
70
|
} = responseData;
|
67
71
|
} catch (error) {
|
68
|
-
throw new Error('
|
72
|
+
throw new Error('请求返回格式出错,请检查 mirai-console');
|
69
73
|
} // 抛出 mirai 的异常,到 catch 中处理后再抛出
|
70
74
|
|
71
75
|
|
@@ -79,6 +83,7 @@ module.exports = async ({
|
|
79
83
|
path
|
80
84
|
};
|
81
85
|
} catch (error) {
|
86
|
+
console.error(`mirai-js: error ${locationStr}`);
|
82
87
|
errorHandler(error);
|
83
88
|
}
|
84
89
|
};
|
package/dist/node/core/verify.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
|
* @description 校验 sessionKey,将一个 session 绑定到指定的 qq 上
|
22
26
|
* @param {string} baseUrl mirai-api-http server 的地址
|
@@ -26,7 +30,6 @@ const errorHandler = require('../util/errorHandler');
|
|
26
30
|
* @returns {Object} 结构 { message, code }
|
27
31
|
*/
|
28
32
|
|
29
|
-
|
30
33
|
module.exports = async ({
|
31
34
|
baseUrl,
|
32
35
|
sessionKey,
|
@@ -50,7 +53,7 @@ module.exports = async ({
|
|
50
53
|
}
|
51
54
|
} = responseData;
|
52
55
|
} catch (error) {
|
53
|
-
throw new Error('
|
56
|
+
throw new Error('请求返回格式出错,请检查 mirai-console');
|
54
57
|
} // 抛出 mirai 的异常,到 catch 中处理后再抛出
|
55
58
|
|
56
59
|
|
@@ -63,6 +66,7 @@ module.exports = async ({
|
|
63
66
|
code
|
64
67
|
};
|
65
68
|
} catch (error) {
|
69
|
+
console.error(`mirai-js: error ${locationStr}`);
|
66
70
|
errorHandler(error);
|
67
71
|
}
|
68
72
|
};
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "mirai-js",
|
3
|
-
"version": "2.
|
3
|
+
"version": "2.3.0",
|
4
4
|
"description": "QQ robot development framework based on Mirai-api-http.",
|
5
5
|
"main": "dist/node/index.js",
|
6
6
|
"scripts": {
|
@@ -32,7 +32,7 @@
|
|
32
32
|
"dependencies": {
|
33
33
|
"axios": "^0.24.0",
|
34
34
|
"form-data": "^3.0.0",
|
35
|
-
"ws": "^
|
35
|
+
"ws": "^8.4.0"
|
36
36
|
},
|
37
37
|
"devDependencies": {
|
38
38
|
"@babel/cli": "^7.13.14",
|
package/src/Bot.d.ts
CHANGED
@@ -146,9 +146,9 @@ export class Bot implements BotConfigGetable {
|
|
146
146
|
|
147
147
|
/**
|
148
148
|
* @description 上传语音至服务器,返回 voiceId, url 及 path
|
149
|
-
* @param
|
150
|
-
* @param
|
151
|
-
* @param
|
149
|
+
* @param type 目前仅支持 "group",请忽略该参数
|
150
|
+
* @param voice 二选一,语音二进制数据
|
151
|
+
* @param filename 二选一,语音文件路径
|
152
152
|
*/
|
153
153
|
uploadVoice({ type, voice, filename }: Bot.UploadVoiceOptions): Promise<Bot.VoiceInfo>;
|
154
154
|
|
@@ -181,8 +181,9 @@ export class Bot implements BotConfigGetable {
|
|
181
181
|
* @param qq 必选,群成员的 qq 号
|
182
182
|
* @param name 可选,要设置的群名片
|
183
183
|
* @param title 可选,要设置的群头衔
|
184
|
+
* @param permission 可选,要设置的群头衔
|
184
185
|
*/
|
185
|
-
setMemberInfo({ group, qq, name, title }: Bot.SetMemberInfoOptions): Promise<void>;
|
186
|
+
setMemberInfo({ group, qq, name, title, permission }: Bot.SetMemberInfoOptions): Promise<void>;
|
186
187
|
|
187
188
|
/**
|
188
189
|
* @description 禁言群成员
|
@@ -219,6 +220,12 @@ export class Bot implements BotConfigGetable {
|
|
219
220
|
*/
|
220
221
|
removeMember({ group, qq, message }: Bot.RemoveMemberOptions): Promise<void>;
|
221
222
|
|
223
|
+
/**
|
224
|
+
* @description 删除好友
|
225
|
+
* @param qq 欲删除的好友 qq 号
|
226
|
+
*/
|
227
|
+
removeFriend({ qq }: Bot.RemoveFriendOptions): Promise<void>;
|
228
|
+
|
222
229
|
/**
|
223
230
|
* @description 移除群成员
|
224
231
|
* @param group 必选,欲移除的成员所在群号
|
@@ -377,6 +384,7 @@ declare namespace Bot {
|
|
377
384
|
qq: number;
|
378
385
|
name?: string;
|
379
386
|
title?: string;
|
387
|
+
permission?: GroupPermission
|
380
388
|
}
|
381
389
|
|
382
390
|
interface MuteOptions {
|
@@ -404,6 +412,10 @@ declare namespace Bot {
|
|
404
412
|
message?: string;
|
405
413
|
}
|
406
414
|
|
415
|
+
interface RemoveFriendOptions {
|
416
|
+
qq: number;
|
417
|
+
}
|
418
|
+
|
407
419
|
interface QuitGroupOptions {
|
408
420
|
group: number;
|
409
421
|
}
|
package/src/Bot.js
CHANGED
@@ -16,12 +16,14 @@ const _getGroupList = require('./core/getGroupList');
|
|
16
16
|
const _getMemberList = require('./core/getMemberList');
|
17
17
|
const _getMemberInfo = require('./core/getMemberInfo');
|
18
18
|
const _setMemberInfo = require('./core/setMemberInfo');
|
19
|
+
const _setMemberAdmin = require('./core/setMemberAdmin');
|
19
20
|
const _recall = require('./core/recall');
|
20
21
|
const _mute = require('./core/mute');
|
21
22
|
const _muteAll = require('./core/muteAll');
|
22
23
|
const _unmute = require('./core/unmute');
|
23
24
|
const _unmuteAll = require('./core/unmuteAll');
|
24
25
|
const _removeMember = require('./core/removeMember');
|
26
|
+
const _removeFriend = require('./core/removeFriend');
|
25
27
|
const _quitGroup = require('./core/quitGroup');
|
26
28
|
const _getGroupConfig = require('./core/getGroupConfig');
|
27
29
|
const _setGroupConfig = require('./core/setGroupConfig');
|
@@ -725,9 +727,11 @@ class Bot extends BotConfigGetable {
|
|
725
727
|
* @param {number} qq 必选,群成员的 qq 号
|
726
728
|
* @param {string} name 可选,要设置的群名片
|
727
729
|
* @param {string} title 可选,要设置的群头衔
|
730
|
+
* @param {boolean} permission 可选,要设置的权限,
|
731
|
+
* 使用枚举值:Bot.Permission.Admin, Bot.Permission.Member
|
728
732
|
* @returns {void}
|
729
733
|
*/
|
730
|
-
async setMemberInfo({ group, qq, name, title }) {
|
734
|
+
async setMemberInfo({ group, qq, name, title, permission }) {
|
731
735
|
// 检查对象状态
|
732
736
|
if (!this.config) {
|
733
737
|
throw new Error('setMemberInfo 请先调用 open,建立一个会话');
|
@@ -739,13 +743,28 @@ class Bot extends BotConfigGetable {
|
|
739
743
|
group, qq
|
740
744
|
})} 参数`);
|
741
745
|
}
|
746
|
+
if (permission != undefined
|
747
|
+
&& permission != Bot.groupPermission.ADMINISTRATOR
|
748
|
+
&& permission != Bot.groupPermission.MEMBER) {
|
749
|
+
throw new Error('setMemberInfo admin 参数只能是 Bot.groupPermission.ADMINISTRATOR 或 Bot.groupPermission.Member');
|
750
|
+
}
|
742
751
|
|
743
|
-
//
|
752
|
+
// setMemberInfo
|
744
753
|
const { baseUrl, sessionKey } = this.config;
|
745
|
-
|
746
|
-
|
747
|
-
|
748
|
-
|
754
|
+
if (name != undefined || title != undefined) {
|
755
|
+
await _setMemberInfo({
|
756
|
+
baseUrl, sessionKey, target: group, memberId: qq,
|
757
|
+
name, specialTitle: title,
|
758
|
+
});
|
759
|
+
}
|
760
|
+
|
761
|
+
// setPermission
|
762
|
+
if (permission != undefined) {
|
763
|
+
await _setMemberAdmin({
|
764
|
+
baseUrl, sessionKey, target: group, memberId: qq,
|
765
|
+
assign: permission == Bot.groupPermission.ADMINISTRATOR ? true : false,
|
766
|
+
});
|
767
|
+
}
|
749
768
|
}
|
750
769
|
|
751
770
|
/**
|
@@ -858,13 +877,35 @@ class Bot extends BotConfigGetable {
|
|
858
877
|
await _removeMember({ baseUrl, sessionKey, target: group, memberId: qq, msg: message });
|
859
878
|
}
|
860
879
|
|
880
|
+
/**
|
881
|
+
* @description 删除好友
|
882
|
+
* @param {*} qq 欲删除的好友 qq 号
|
883
|
+
* @returns {void}
|
884
|
+
*/
|
885
|
+
async removeFriend({ qq }) {
|
886
|
+
// 检查对象状态
|
887
|
+
if (!this.config) {
|
888
|
+
throw new Error('removeFriend 请先调用 open,建立一个会话');
|
889
|
+
}
|
890
|
+
|
891
|
+
// 检查参数
|
892
|
+
if (!qq) {
|
893
|
+
throw new Error('removeFriend 缺少必要的 qq 参数');
|
894
|
+
}
|
895
|
+
|
896
|
+
const { baseUrl, sessionKey } = this.config;
|
897
|
+
|
898
|
+
// 删除好友
|
899
|
+
await _removeFriend({ baseUrl, sessionKey, target: qq });
|
900
|
+
}
|
901
|
+
|
861
902
|
/**
|
862
903
|
* @description 移除群成员
|
863
904
|
* @param {number} group 必选,欲移除的成员所在群号
|
864
905
|
* @returns {void}
|
865
906
|
*/
|
866
907
|
async quitGroup({ group }) {
|
867
|
-
// 检查对象状态
|
908
|
+
// 检查对象状态
|
868
909
|
if (!this.config) {
|
869
910
|
throw new Error('quitGroup 请先调用 open,建立一个会话');
|
870
911
|
}
|
package/src/FileManager.js
CHANGED
@@ -7,27 +7,31 @@ class FileManager {
|
|
7
7
|
const baseUrl = bot.getBaseUrl();
|
8
8
|
const sessionKey = bot.sessionKey();
|
9
9
|
// core 柯里化,为内部类 File Directory 提供包装的接口
|
10
|
-
this._getGroupFileList = ({ dir }) => require('./core/getGroupFileList')({
|
10
|
+
this._getGroupFileList = ({ dir }) => require('./core/fs/getGroupFileList')({
|
11
11
|
baseUrl, sessionKey, target: group, dir
|
12
12
|
});
|
13
13
|
|
14
|
-
this._getGroupFileInfo = ({ id }) => require('./core/getGroupFileInfo')({
|
14
|
+
this._getGroupFileInfo = ({ id }) => require('./core/fs/getGroupFileInfo')({
|
15
15
|
baseUrl, sessionKey, target: group, id
|
16
16
|
});
|
17
17
|
|
18
|
-
this._uploadFileAndSend = ({ type, path, file }) => require('./core/
|
18
|
+
this._uploadFileAndSend = ({ type, path, file }) => require('./core/fs/uploadGroupFIle')({
|
19
19
|
baseUrl, sessionKey, type, target: group, path, file
|
20
20
|
});
|
21
21
|
|
22
|
-
this._groupFileDelete = ({ id }) => require('./core/
|
22
|
+
this._groupFileDelete = ({ id }) => require('./core/fs/deleteGroupFile')({
|
23
23
|
baseUrl, sessionKey, target: group, id
|
24
24
|
});
|
25
25
|
|
26
|
-
this.
|
26
|
+
this._makeGroupDir = ({ dir }) => require('./core/fs/makeGroupDir')({
|
27
|
+
baseUrl, sessionKey, target: group, dir
|
28
|
+
});
|
29
|
+
|
30
|
+
this._groupFileRename = ({ id, rename }) => require('./core/fs/renameGroupFile')({
|
27
31
|
baseUrl, sessionKey, target: group, id, rename
|
28
32
|
});
|
29
33
|
|
30
|
-
this._groupFileMove = ({ id, movePath }) => require('./core/
|
34
|
+
this._groupFileMove = ({ id, movePath }) => require('./core/fs/moveGroupFile')({
|
31
35
|
baseUrl, sessionKey, target: group, id, movePath
|
32
36
|
});
|
33
37
|
|
package/src/core/auth.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
|
*
|
@@ -27,7 +29,7 @@ module.exports = async ({ baseUrl, verifyKey }) => {
|
|
27
29
|
data: { msg: message, code, session: sessionKey },
|
28
30
|
} = responseData;
|
29
31
|
} catch (error) {
|
30
|
-
throw new Error('
|
32
|
+
throw new Error(('请求返回格式出错,请检查 mirai-console'));
|
31
33
|
}
|
32
34
|
|
33
35
|
// 抛出 mirai 的异常,到 catch 中处理后再抛出
|
@@ -36,6 +38,7 @@ module.exports = async ({ baseUrl, verifyKey }) => {
|
|
36
38
|
}
|
37
39
|
return sessionKey;
|
38
40
|
} catch (error) {
|
41
|
+
console.error(`mirai-js: error ${locationStr}`);
|
39
42
|
errorHandler(error);
|
40
43
|
}
|
41
44
|
};
|
@@ -0,0 +1,49 @@
|
|
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
|
+
* @returns {Object} 结构 { message, code }
|
21
|
+
*/
|
22
|
+
module.exports = async ({ baseUrl, sessionKey, id, path, group }) => {
|
23
|
+
try {
|
24
|
+
// 拼接 url
|
25
|
+
const url = new URL('/file/delete', baseUrl).toString();
|
26
|
+
|
27
|
+
// 请求
|
28
|
+
const responseData = await axios.post(url, {
|
29
|
+
sessionKey, id, path, target: group, group,
|
30
|
+
});
|
31
|
+
|
32
|
+
try {
|
33
|
+
var {
|
34
|
+
data: { msg: message, code }
|
35
|
+
} = responseData;
|
36
|
+
} catch (error) {
|
37
|
+
throw new Error(('请求返回格式出错,请检查 mirai-console'));
|
38
|
+
}
|
39
|
+
// 抛出 mirai 的异常,到 catch 中处理后再抛出
|
40
|
+
if (code in errCodeMap) {
|
41
|
+
throw new Error(message);
|
42
|
+
}
|
43
|
+
return { message, code };
|
44
|
+
} catch (error) {
|
45
|
+
console.error(`mirai-js: error ${locationStr}`);
|
46
|
+
errorHandler(error);
|
47
|
+
}
|
48
|
+
|
49
|
+
};
|
@@ -0,0 +1,50 @@
|
|
1
|
+
const { errCodeMap } = require('../../util/errCode');
|
2
|
+
const axios = require('axios').default;
|
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 {boolean} withDownloadInfo 是否携带下载信息,额外请求,无必要不要携带
|
21
|
+
* @returns {Object}
|
22
|
+
* 结构 { id, name, path, parent, contact, isFile, isDirectory, downloadInfo }
|
23
|
+
*/
|
24
|
+
module.exports = async ({ baseUrl, sessionKey, id, path, group/*, qq 字段保留 */, withDownloadInfo }) => {
|
25
|
+
try {
|
26
|
+
// 拼接 url
|
27
|
+
const url = new URL('/file/info', baseUrl).toString();
|
28
|
+
|
29
|
+
// 请求
|
30
|
+
const responseData = await axios.get(url, {
|
31
|
+
params: {
|
32
|
+
sessionKey, id, path, target: group, group, withDownloadInfo
|
33
|
+
}
|
34
|
+
});
|
35
|
+
try {
|
36
|
+
var { data: { msg: message, code, data } } = responseData;
|
37
|
+
} catch (error) {
|
38
|
+
throw new Error(('请求返回格式出错,请检查 mirai-console'));
|
39
|
+
}
|
40
|
+
|
41
|
+
// 抛出 mirai 的异常,到 catch 中处理后再抛出
|
42
|
+
if (code in errCodeMap) {
|
43
|
+
throw new Error(message);
|
44
|
+
}
|
45
|
+
return data;
|
46
|
+
} catch (error) {
|
47
|
+
console.error(`mirai-js: error ${locationStr}`);
|
48
|
+
errorHandler(error);
|
49
|
+
}
|
50
|
+
};
|
@@ -0,0 +1,51 @@
|
|
1
|
+
const { errCodeMap } = require('../../util/errCode');
|
2
|
+
const axios = require('axios').default;
|
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 {boolern} withDownloadInfo 是否携带下载信息,额外请求,无必要不要携带
|
21
|
+
* @param {number} offset 分页偏移
|
22
|
+
* @param {number} size 分页大小
|
23
|
+
* @returns {Object[]} 结构 array[...{ id, name, path, parent, contact, isFile, isDirectory, downloadInfo }]
|
24
|
+
*/
|
25
|
+
module.exports = async ({ baseUrl, sessionKey, id, path, group/*, qq 字段保留 */, withDownloadInfo, offset, size }) => {
|
26
|
+
try {
|
27
|
+
// 拼接 url
|
28
|
+
const url = new URL('/file/list', baseUrl).toString();
|
29
|
+
|
30
|
+
// 请求
|
31
|
+
const responseData = await axios.get(url, {
|
32
|
+
params: {
|
33
|
+
sessionKey, id, path, target: group, group, withDownloadInfo, offset, size
|
34
|
+
}
|
35
|
+
});
|
36
|
+
try {
|
37
|
+
var { data: { msg: message, code, data } } = responseData;
|
38
|
+
} catch (error) {
|
39
|
+
throw new Error(('请求返回格式出错,请检查 mirai-console'));
|
40
|
+
}
|
41
|
+
|
42
|
+
// 抛出 mirai 的异常,到 catch 中处理后再抛出
|
43
|
+
if (code in errCodeMap) {
|
44
|
+
throw new Error(message);
|
45
|
+
}
|
46
|
+
return data;
|
47
|
+
} catch (error) {
|
48
|
+
console.error(`mirai-js: error ${locationStr}`);
|
49
|
+
errorHandler(error);
|
50
|
+
}
|
51
|
+
};
|
@@ -0,0 +1,49 @@
|
|
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 {boolern} withDownloadInfo 是否携带下载信息,额外请求,无必要不要携带
|
21
|
+
* @returns {Object} 结构 { id, name, path, parent, contact, isFile, isDirectory, downloadInfo }
|
22
|
+
*/
|
23
|
+
module.exports = async ({ baseUrl, sessionKey, id, rename, path, group, withDownloadInfo }) => {
|
24
|
+
try {
|
25
|
+
// 拼接 url
|
26
|
+
const url = new URL('/file/mkdir', baseUrl).toString();
|
27
|
+
|
28
|
+
// 请求
|
29
|
+
const responseData = await axios.post(url, {
|
30
|
+
sessionKey, id, rename, path, group, withDownloadInfo
|
31
|
+
});
|
32
|
+
|
33
|
+
try {
|
34
|
+
var {
|
35
|
+
data: { msg: message, code, data }
|
36
|
+
} = responseData;
|
37
|
+
} catch (error) {
|
38
|
+
throw new Error(('请求返回格式出错,请检查 mirai-console'));
|
39
|
+
}
|
40
|
+
// 抛出 mirai 的异常,到 catch 中处理后再抛出
|
41
|
+
if (code in errCodeMap) {
|
42
|
+
throw new Error(message);
|
43
|
+
}
|
44
|
+
return data;
|
45
|
+
} catch (error) {
|
46
|
+
console.error(`mirai-js: error ${locationStr}`);
|
47
|
+
errorHandler(error);
|
48
|
+
}
|
49
|
+
};
|