mirai-js 2.0.2 → 2.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/FUNDING.yml +1 -1
- package/.github/dependabot.yml +1 -1
- package/.github/workflows/codeql-analysis.yml +70 -0
- package/.husky/pre-commit +0 -0
- package/demo.html +2 -2
- package/demo.js +6 -90
- package/dist/browser/mirai-js.js +1 -1
- package/dist/node/Bot.d.ts +22 -19
- package/dist/node/Bot.js +110 -47
- package/dist/node/FileManager.js +15 -6
- package/dist/node/Middleware.js +92 -27
- 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 +29 -14
- 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 +18 -22
- 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 +8 -2
- 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/docs/checkDocShouldBuild.sh +4 -0
- package/package.json +8 -8
- package/src/Bot.d.ts +22 -19
- package/src/Bot.js +77 -26
- package/src/FileManager.js +10 -6
- package/src/Middleware.js +54 -10
- 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 +17 -9
- 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 +16 -13
- 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 +4 -1
- 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/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,11 +1,11 @@
|
|
1
1
|
{
|
2
2
|
"name": "mirai-js",
|
3
|
-
"version": "2.0
|
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": {
|
7
7
|
"lint": "eslint --fix .",
|
8
|
-
"build": "webpack &&
|
8
|
+
"build": "webpack && babel src --out-dir dist/node --copy-files",
|
9
9
|
"prepare": "husky install"
|
10
10
|
},
|
11
11
|
"lint-staged": {
|
@@ -30,19 +30,19 @@
|
|
30
30
|
"homepage": "https://drincann.github.io/Mirai-js/",
|
31
31
|
"license": "AGPL-3.0",
|
32
32
|
"dependencies": {
|
33
|
-
"axios": "^0.
|
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",
|
39
39
|
"@babel/core": "^7.13.14",
|
40
40
|
"@babel/preset-env": "^7.13.12",
|
41
|
-
"@typescript-eslint/eslint-plugin": "^4.
|
42
|
-
"@typescript-eslint/parser": "^
|
43
|
-
"eslint": "^
|
41
|
+
"@typescript-eslint/eslint-plugin": "^5.4.0",
|
42
|
+
"@typescript-eslint/parser": "^5.5.0",
|
43
|
+
"eslint": "^8.2.0",
|
44
44
|
"husky": "^6.0.0",
|
45
|
-
"lint-staged": "^
|
45
|
+
"lint-staged": "^12.0.2",
|
46
46
|
"path-browserify": "^1.0.1",
|
47
47
|
"process": "^0.11.10",
|
48
48
|
"typescript": "^4.2.2",
|
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 必选,欲移除的成员所在群号
|
@@ -253,6 +260,11 @@ export class Bot implements BotConfigGetable {
|
|
253
260
|
*/
|
254
261
|
setEssence({ messageId }: Bot.SetEssenceOptions): Promise<void>;
|
255
262
|
|
263
|
+
/**
|
264
|
+
* @description 向 mirai-console 发送指令
|
265
|
+
* @param command 必选,指令名
|
266
|
+
*/
|
267
|
+
sendCommand({ command }: Bot.SendCommandOptions): Promise<Bot.MiraiConsoleMessage>;
|
256
268
|
|
257
269
|
// 类方法
|
258
270
|
/**
|
@@ -263,17 +275,6 @@ export class Bot implements BotConfigGetable {
|
|
263
275
|
*/
|
264
276
|
static isBotLoggedIn({ baseUrl, verifyKey, qq }: Bot.IsBotLoggedInOptions): Promise<boolean>;
|
265
277
|
|
266
|
-
/**
|
267
|
-
* @description 向 mirai-console 发送指令
|
268
|
-
* @param baseUrl 必选,mirai-api-http server 的地址
|
269
|
-
* @param verifyKey 必选,mirai-api-http server 设置的 verifyKey
|
270
|
-
* @param command 必选,指令名
|
271
|
-
* @param args 可选,指令的参数
|
272
|
-
*/
|
273
|
-
static sendCommand({
|
274
|
-
baseUrl, verifyKey,
|
275
|
-
command, args,
|
276
|
-
}: Bot.SendCommandOptions): Promise<Bot.MiraiConsoleMessage>;
|
277
278
|
}
|
278
279
|
|
279
280
|
// 类型
|
@@ -383,6 +384,7 @@ declare namespace Bot {
|
|
383
384
|
qq: number;
|
384
385
|
name?: string;
|
385
386
|
title?: string;
|
387
|
+
permission?: GroupPermission
|
386
388
|
}
|
387
389
|
|
388
390
|
interface MuteOptions {
|
@@ -410,6 +412,10 @@ declare namespace Bot {
|
|
410
412
|
message?: string;
|
411
413
|
}
|
412
414
|
|
415
|
+
interface RemoveFriendOptions {
|
416
|
+
qq: number;
|
417
|
+
}
|
418
|
+
|
413
419
|
interface QuitGroupOptions {
|
414
420
|
group: number;
|
415
421
|
}
|
@@ -442,10 +448,7 @@ declare namespace Bot {
|
|
442
448
|
}
|
443
449
|
|
444
450
|
interface SendCommandOptions {
|
445
|
-
|
446
|
-
verifyKey: string;
|
447
|
-
command: string;
|
448
|
-
args: string[];
|
451
|
+
command: string[];
|
449
452
|
}
|
450
453
|
|
451
454
|
interface IsBotLoggedInOptions {
|
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');
|
@@ -51,7 +53,6 @@ const { MessageChainGetable, BotConfigGetable } = require('./interface');
|
|
51
53
|
class Bot extends BotConfigGetable {
|
52
54
|
constructor() {
|
53
55
|
super();
|
54
|
-
// 实例化一个内部类 Waiter
|
55
56
|
this.waiter = new Waiter(this);
|
56
57
|
this.config = undefined;
|
57
58
|
this.eventProcessorMap = {};
|
@@ -726,9 +727,11 @@ class Bot extends BotConfigGetable {
|
|
726
727
|
* @param {number} qq 必选,群成员的 qq 号
|
727
728
|
* @param {string} name 可选,要设置的群名片
|
728
729
|
* @param {string} title 可选,要设置的群头衔
|
730
|
+
* @param {boolean} permission 可选,要设置的权限,
|
731
|
+
* 使用枚举值:Bot.Permission.Admin, Bot.Permission.Member
|
729
732
|
* @returns {void}
|
730
733
|
*/
|
731
|
-
async setMemberInfo({ group, qq, name, title }) {
|
734
|
+
async setMemberInfo({ group, qq, name, title, permission }) {
|
732
735
|
// 检查对象状态
|
733
736
|
if (!this.config) {
|
734
737
|
throw new Error('setMemberInfo 请先调用 open,建立一个会话');
|
@@ -740,13 +743,28 @@ class Bot extends BotConfigGetable {
|
|
740
743
|
group, qq
|
741
744
|
})} 参数`);
|
742
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
|
+
}
|
743
751
|
|
744
|
-
//
|
752
|
+
// setMemberInfo
|
745
753
|
const { baseUrl, sessionKey } = this.config;
|
746
|
-
|
747
|
-
|
748
|
-
|
749
|
-
|
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
|
+
}
|
750
768
|
}
|
751
769
|
|
752
770
|
/**
|
@@ -859,13 +877,35 @@ class Bot extends BotConfigGetable {
|
|
859
877
|
await _removeMember({ baseUrl, sessionKey, target: group, memberId: qq, msg: message });
|
860
878
|
}
|
861
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
|
+
|
862
902
|
/**
|
863
903
|
* @description 移除群成员
|
864
904
|
* @param {number} group 必选,欲移除的成员所在群号
|
865
905
|
* @returns {void}
|
866
906
|
*/
|
867
907
|
async quitGroup({ group }) {
|
868
|
-
// 检查对象状态
|
908
|
+
// 检查对象状态
|
869
909
|
if (!this.config) {
|
870
910
|
throw new Error('quitGroup 请先调用 open,建立一个会话');
|
871
911
|
}
|
@@ -966,6 +1006,35 @@ class Bot extends BotConfigGetable {
|
|
966
1006
|
await _setEssence({ baseUrl, sessionKey, target: messageId });
|
967
1007
|
}
|
968
1008
|
|
1009
|
+
/**
|
1010
|
+
* @description 向 mirai-console 发送指令
|
1011
|
+
* @param {string[]} command 必选,指令和参数
|
1012
|
+
* @returns {Object} 结构 { message },注意查看 message 的内容,已知的问题:
|
1013
|
+
* 'Login failed: Mirai 无法完成滑块验证. 使用协议 ANDROID_PHONE 强制要求滑块验证,
|
1014
|
+
* 请更换协议后重试. 另请参阅: https://github.com/project-mirai/mirai-login-solver-selenium'
|
1015
|
+
*/
|
1016
|
+
async sendCommand({ command }) {
|
1017
|
+
// 检查对象状态
|
1018
|
+
if (!this.config) {
|
1019
|
+
throw new Error('setEssence 请先调用 open,建立一个会话');
|
1020
|
+
}
|
1021
|
+
|
1022
|
+
// 检查参数
|
1023
|
+
if (!command) {
|
1024
|
+
throw new Error(`sendCommand 缺少必要的 ${getInvalidParamsString({ command })} 参数`);
|
1025
|
+
}
|
1026
|
+
|
1027
|
+
const { Message } = require('./Message');
|
1028
|
+
const { baseUrl, sessionKey } = this.config;
|
1029
|
+
return await _sendCommand({
|
1030
|
+
baseUrl, sessionKey,
|
1031
|
+
command: command
|
1032
|
+
.map((v) => v?.toString() ?? '')
|
1033
|
+
.reduce((acc, cur) => acc.addText(cur), new Message)
|
1034
|
+
.messageChain
|
1035
|
+
});
|
1036
|
+
}
|
1037
|
+
|
969
1038
|
/**
|
970
1039
|
* @description 检测该账号是否已经在 mirai-console 登录
|
971
1040
|
* @param {string} baseUrl 必选,mirai-api-http server 的地址
|
@@ -990,24 +1059,6 @@ class Bot extends BotConfigGetable {
|
|
990
1059
|
}
|
991
1060
|
}
|
992
1061
|
|
993
|
-
/**
|
994
|
-
* @description 向 mirai-console 发送指令
|
995
|
-
* @param {string} baseUrl 必选,mirai-api-http server 的地址
|
996
|
-
* @param {string} verifyKey 必选,mirai-api-http server 设置的 verifyKey
|
997
|
-
* @param {string} command 必选,指令名
|
998
|
-
* @param {string[]} args 可选,指令的参数
|
999
|
-
* @returns {Object} 结构 { message },注意查看 message 的内容,已知的问题:
|
1000
|
-
* 'Login failed: Mirai 无法完成滑块验证. 使用协议 ANDROID_PHONE 强制要求滑块验证,
|
1001
|
-
* 请更换协议后重试. 另请参阅: https://github.com/project-mirai/mirai-login-solver-selenium'
|
1002
|
-
*/
|
1003
|
-
static async sendCommand({ baseUrl, verifyKey, command, args }) {
|
1004
|
-
// 检查参数
|
1005
|
-
if (!baseUrl || !verifyKey || !command) {
|
1006
|
-
throw new Error(`sendCommand 缺少必要的 ${getInvalidParamsString({ baseUrl, verifyKey, command })} 参数`);
|
1007
|
-
}
|
1008
|
-
|
1009
|
-
return await _sendCommand({ baseUrl, verifyKey, command, args });
|
1010
|
-
}
|
1011
1062
|
}
|
1012
1063
|
|
1013
1064
|
|
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/Middleware.js
CHANGED
@@ -19,15 +19,11 @@ class Middleware {
|
|
19
19
|
* @param {string} verifyKey mirai-api-http server 设置的 verifyKey
|
20
20
|
* @param {string} password 欲重新登陆的 qq 密码
|
21
21
|
*/
|
22
|
-
autoReLogin({
|
23
|
-
const { Bot } = require('./index.js');
|
22
|
+
autoReLogin({ password }) {
|
24
23
|
this.middleware.push(async (data, next) => {
|
25
24
|
try {
|
26
|
-
await
|
27
|
-
|
28
|
-
verifyKey,
|
29
|
-
command: '/login',
|
30
|
-
args: [data.qq, password],
|
25
|
+
await data.bot.sendCommand({
|
26
|
+
command: ['/login', data.qq, password],
|
31
27
|
});
|
32
28
|
await data.bot.open();
|
33
29
|
await next();
|
@@ -538,10 +534,58 @@ class Middleware {
|
|
538
534
|
if (data.type != 'GroupMessage' && data.type != 'FriendMessage') {
|
539
535
|
throw new Error('Middleware.syncWrapper 消息格式出错');
|
540
536
|
}
|
537
|
+
const watiForMessageChain = async (qq) => {
|
538
|
+
qq = qq ?? data?.sender?.id;
|
539
|
+
if (qq == undefined) {
|
540
|
+
throw new Error('Middleware.syncWrapper 消息格式出错');
|
541
|
+
}
|
542
|
+
do {
|
543
|
+
var { messageChain, id } = await data.bot?.waiter?.wait(data.type, ({ messageChain, sender: { id } }) => ({ messageChain, id })) ?? {};
|
544
|
+
} while (qq != id);
|
545
|
+
|
546
|
+
return messageChain;
|
547
|
+
};
|
548
|
+
|
549
|
+
const waitForText = async (qq) => {
|
550
|
+
qq = qq ?? data?.sender?.id;
|
551
|
+
if (qq == undefined) {
|
552
|
+
throw new Error('Middleware.syncWrapper 消息格式出错');
|
553
|
+
}
|
554
|
+
do {
|
555
|
+
var { text, id } = await data.bot?.waiter?.wait(data.type, new Middleware().textProcessor().done(({ text, sender: { id } }) => ({ text, id }))) ?? {};
|
556
|
+
} while (qq != id);
|
557
|
+
return text;
|
558
|
+
};
|
559
|
+
|
560
|
+
const waitForCustom = async (qq, processor) => {
|
561
|
+
qq = qq ?? data?.sender?.id;
|
562
|
+
if (qq == undefined) {
|
563
|
+
throw new Error('Middleware.syncWrapper 消息格式出错');
|
564
|
+
}
|
565
|
+
do {
|
566
|
+
var data = await data.bot?.waiter?.wait(data.type, new Middleware().textProcessor().done((data) => data));
|
567
|
+
} while (qq != data?.sender?.id);
|
568
|
+
return await processor(data);
|
569
|
+
};
|
570
|
+
|
541
571
|
data.waitFor = {
|
542
|
-
|
543
|
-
|
544
|
-
|
572
|
+
groupMember: (qq = undefined) => {
|
573
|
+
return {
|
574
|
+
messageChain: () => watiForMessageChain(qq),
|
575
|
+
text: () => waitForText(qq),
|
576
|
+
custom: (processor) => waitForCustom(qq, processor),
|
577
|
+
};
|
578
|
+
},
|
579
|
+
friend: (qq) => {
|
580
|
+
return {
|
581
|
+
messageChain: () => watiForMessageChain(qq),
|
582
|
+
text: () => waitForText(qq),
|
583
|
+
custom: (processor) => waitForCustom(qq, processor),
|
584
|
+
};
|
585
|
+
},
|
586
|
+
messageChain: () => watiForMessageChain(data.sender.id),
|
587
|
+
text: () => waitForText(data.sender.id),
|
588
|
+
custom: (processor) => waitForCustom(data.sender.id, processor),
|
545
589
|
};
|
546
590
|
|
547
591
|
await next();
|
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
|
+
};
|