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/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/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');
|
@@ -97,8 +101,7 @@ const {
|
|
97
101
|
|
98
102
|
class Bot extends BotConfigGetable {
|
99
103
|
constructor() {
|
100
|
-
super();
|
101
|
-
|
104
|
+
super();
|
102
105
|
this.waiter = new Waiter(this);
|
103
106
|
this.config = undefined;
|
104
107
|
this.eventProcessorMap = {};
|
@@ -954,6 +957,8 @@ class Bot extends BotConfigGetable {
|
|
954
957
|
* @param {number} qq 必选,群成员的 qq 号
|
955
958
|
* @param {string} name 可选,要设置的群名片
|
956
959
|
* @param {string} title 可选,要设置的群头衔
|
960
|
+
* @param {boolean} permission 可选,要设置的权限,
|
961
|
+
* 使用枚举值:Bot.Permission.Admin, Bot.Permission.Member
|
957
962
|
* @returns {void}
|
958
963
|
*/
|
959
964
|
|
@@ -962,7 +967,8 @@ class Bot extends BotConfigGetable {
|
|
962
967
|
group,
|
963
968
|
qq,
|
964
969
|
name,
|
965
|
-
title
|
970
|
+
title,
|
971
|
+
permission
|
966
972
|
}) {
|
967
973
|
// 检查对象状态
|
968
974
|
if (!this.config) {
|
@@ -975,21 +981,39 @@ class Bot extends BotConfigGetable {
|
|
975
981
|
group,
|
976
982
|
qq
|
977
983
|
})} 参数`);
|
978
|
-
}
|
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
|
979
989
|
|
980
990
|
|
981
991
|
const {
|
982
992
|
baseUrl,
|
983
993
|
sessionKey
|
984
994
|
} = this.config;
|
985
|
-
|
986
|
-
|
987
|
-
|
988
|
-
|
989
|
-
|
990
|
-
|
991
|
-
|
992
|
-
|
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
|
+
}
|
993
1017
|
}
|
994
1018
|
/**
|
995
1019
|
* @description 禁言群成员
|
@@ -1171,6 +1195,37 @@ class Bot extends BotConfigGetable {
|
|
1171
1195
|
msg: message
|
1172
1196
|
});
|
1173
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
|
+
}
|
1174
1229
|
/**
|
1175
1230
|
* @description 移除群成员
|
1176
1231
|
* @param {number} group 必选,欲移除的成员所在群号
|
@@ -1181,7 +1236,7 @@ class Bot extends BotConfigGetable {
|
|
1181
1236
|
async quitGroup({
|
1182
1237
|
group
|
1183
1238
|
}) {
|
1184
|
-
// 检查对象状态
|
1239
|
+
// 检查对象状态
|
1185
1240
|
if (!this.config) {
|
1186
1241
|
throw new Error('quitGroup 请先调用 open,建立一个会话');
|
1187
1242
|
} // 检查参数
|
@@ -1325,6 +1380,48 @@ class Bot extends BotConfigGetable {
|
|
1325
1380
|
target: messageId
|
1326
1381
|
});
|
1327
1382
|
}
|
1383
|
+
/**
|
1384
|
+
* @description 向 mirai-console 发送指令
|
1385
|
+
* @param {string[]} command 必选,指令和参数
|
1386
|
+
* @returns {Object} 结构 { message },注意查看 message 的内容,已知的问题:
|
1387
|
+
* 'Login failed: Mirai 无法完成滑块验证. 使用协议 ANDROID_PHONE 强制要求滑块验证,
|
1388
|
+
* 请更换协议后重试. 另请参阅: https://github.com/project-mirai/mirai-login-solver-selenium'
|
1389
|
+
*/
|
1390
|
+
|
1391
|
+
|
1392
|
+
async sendCommand({
|
1393
|
+
command
|
1394
|
+
}) {
|
1395
|
+
// 检查对象状态
|
1396
|
+
if (!this.config) {
|
1397
|
+
throw new Error('setEssence 请先调用 open,建立一个会话');
|
1398
|
+
} // 检查参数
|
1399
|
+
|
1400
|
+
|
1401
|
+
if (!command) {
|
1402
|
+
throw new Error(`sendCommand 缺少必要的 ${getInvalidParamsString({
|
1403
|
+
command
|
1404
|
+
})} 参数`);
|
1405
|
+
}
|
1406
|
+
|
1407
|
+
const {
|
1408
|
+
Message
|
1409
|
+
} = require('./Message');
|
1410
|
+
|
1411
|
+
const {
|
1412
|
+
baseUrl,
|
1413
|
+
sessionKey
|
1414
|
+
} = this.config;
|
1415
|
+
return await _sendCommand({
|
1416
|
+
baseUrl,
|
1417
|
+
sessionKey,
|
1418
|
+
command: command.map(v => {
|
1419
|
+
var _v$toString;
|
1420
|
+
|
1421
|
+
return (_v$toString = v === null || v === void 0 ? void 0 : v.toString()) !== null && _v$toString !== void 0 ? _v$toString : '';
|
1422
|
+
}).reduce((acc, cur) => acc.addText(cur), new Message()).messageChain
|
1423
|
+
});
|
1424
|
+
}
|
1328
1425
|
/**
|
1329
1426
|
* @description 检测该账号是否已经在 mirai-console 登录
|
1330
1427
|
* @param {string} baseUrl 必选,mirai-api-http server 的地址
|
@@ -1373,40 +1470,6 @@ class Bot extends BotConfigGetable {
|
|
1373
1470
|
return true;
|
1374
1471
|
}
|
1375
1472
|
}
|
1376
|
-
/**
|
1377
|
-
* @description 向 mirai-console 发送指令
|
1378
|
-
* @param {string} baseUrl 必选,mirai-api-http server 的地址
|
1379
|
-
* @param {string} verifyKey 必选,mirai-api-http server 设置的 verifyKey
|
1380
|
-
* @param {string} command 必选,指令名
|
1381
|
-
* @param {string[]} args 可选,指令的参数
|
1382
|
-
* @returns {Object} 结构 { message },注意查看 message 的内容,已知的问题:
|
1383
|
-
* 'Login failed: Mirai 无法完成滑块验证. 使用协议 ANDROID_PHONE 强制要求滑块验证,
|
1384
|
-
* 请更换协议后重试. 另请参阅: https://github.com/project-mirai/mirai-login-solver-selenium'
|
1385
|
-
*/
|
1386
|
-
|
1387
|
-
|
1388
|
-
static async sendCommand({
|
1389
|
-
baseUrl,
|
1390
|
-
verifyKey,
|
1391
|
-
command,
|
1392
|
-
args
|
1393
|
-
}) {
|
1394
|
-
// 检查参数
|
1395
|
-
if (!baseUrl || !verifyKey || !command) {
|
1396
|
-
throw new Error(`sendCommand 缺少必要的 ${getInvalidParamsString({
|
1397
|
-
baseUrl,
|
1398
|
-
verifyKey,
|
1399
|
-
command
|
1400
|
-
})} 参数`);
|
1401
|
-
}
|
1402
|
-
|
1403
|
-
return await _sendCommand({
|
1404
|
-
baseUrl,
|
1405
|
-
verifyKey,
|
1406
|
-
command,
|
1407
|
-
args
|
1408
|
-
});
|
1409
|
-
}
|
1410
1473
|
|
1411
1474
|
} // 静态属性: 群成员的权限
|
1412
1475
|
|
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/Middleware.js
CHANGED
@@ -26,21 +26,12 @@ class Middleware {
|
|
26
26
|
|
27
27
|
|
28
28
|
autoReLogin({
|
29
|
-
baseUrl,
|
30
|
-
verifyKey,
|
31
29
|
password
|
32
30
|
}) {
|
33
|
-
const {
|
34
|
-
Bot
|
35
|
-
} = require('./index.js');
|
36
|
-
|
37
31
|
this.middleware.push(async (data, next) => {
|
38
32
|
try {
|
39
|
-
await
|
40
|
-
|
41
|
-
verifyKey,
|
42
|
-
command: '/login',
|
43
|
-
args: [data.qq, password]
|
33
|
+
await data.bot.sendCommand({
|
34
|
+
command: ['/login', data.qq, password]
|
44
35
|
});
|
45
36
|
await data.bot.open();
|
46
37
|
await next();
|
@@ -649,26 +640,100 @@ class Middleware {
|
|
649
640
|
throw new Error('Middleware.syncWrapper 消息格式出错');
|
650
641
|
}
|
651
642
|
|
652
|
-
|
653
|
-
|
654
|
-
var _data$bot, _data$bot$waiter;
|
643
|
+
const watiForMessageChain = async qq => {
|
644
|
+
var _qq, _data$sender17;
|
655
645
|
|
656
|
-
|
657
|
-
messageChain
|
658
|
-
}) => messageChain);
|
659
|
-
},
|
660
|
-
text: () => {
|
661
|
-
var _data$bot2, _data$bot2$waiter;
|
646
|
+
qq = (_qq = qq) !== null && _qq !== void 0 ? _qq : data === null || data === void 0 ? void 0 : (_data$sender17 = data.sender) === null || _data$sender17 === void 0 ? void 0 : _data$sender17.id;
|
662
647
|
|
663
|
-
|
664
|
-
|
665
|
-
|
666
|
-
|
667
|
-
|
668
|
-
var _data$
|
648
|
+
if (qq == undefined) {
|
649
|
+
throw new Error('Middleware.syncWrapper 消息格式出错');
|
650
|
+
}
|
651
|
+
|
652
|
+
do {
|
653
|
+
var _await$data$bot$waite, _data$bot, _data$bot$waiter;
|
654
|
+
|
655
|
+
var {
|
656
|
+
messageChain,
|
657
|
+
id
|
658
|
+
} = (_await$data$bot$waite = await ((_data$bot = data.bot) === null || _data$bot === void 0 ? void 0 : (_data$bot$waiter = _data$bot.waiter) === null || _data$bot$waiter === void 0 ? void 0 : _data$bot$waiter.wait(data.type, ({
|
659
|
+
messageChain,
|
660
|
+
sender: {
|
661
|
+
id
|
662
|
+
}
|
663
|
+
}) => ({
|
664
|
+
messageChain,
|
665
|
+
id
|
666
|
+
})))) !== null && _await$data$bot$waite !== void 0 ? _await$data$bot$waite : {};
|
667
|
+
} while (qq != id);
|
668
|
+
|
669
|
+
return messageChain;
|
670
|
+
};
|
671
|
+
|
672
|
+
const waitForText = async qq => {
|
673
|
+
var _qq2, _data$sender18;
|
674
|
+
|
675
|
+
qq = (_qq2 = qq) !== null && _qq2 !== void 0 ? _qq2 : data === null || data === void 0 ? void 0 : (_data$sender18 = data.sender) === null || _data$sender18 === void 0 ? void 0 : _data$sender18.id;
|
669
676
|
|
670
|
-
|
677
|
+
if (qq == undefined) {
|
678
|
+
throw new Error('Middleware.syncWrapper 消息格式出错');
|
671
679
|
}
|
680
|
+
|
681
|
+
do {
|
682
|
+
var _await$data$bot$waite2, _data$bot2, _data$bot2$waiter;
|
683
|
+
|
684
|
+
var {
|
685
|
+
text,
|
686
|
+
id
|
687
|
+
} = (_await$data$bot$waite2 = await ((_data$bot2 = data.bot) === null || _data$bot2 === void 0 ? void 0 : (_data$bot2$waiter = _data$bot2.waiter) === null || _data$bot2$waiter === void 0 ? void 0 : _data$bot2$waiter.wait(data.type, new Middleware().textProcessor().done(({
|
688
|
+
text,
|
689
|
+
sender: {
|
690
|
+
id
|
691
|
+
}
|
692
|
+
}) => ({
|
693
|
+
text,
|
694
|
+
id
|
695
|
+
}))))) !== null && _await$data$bot$waite2 !== void 0 ? _await$data$bot$waite2 : {};
|
696
|
+
} while (qq != id);
|
697
|
+
|
698
|
+
return text;
|
699
|
+
};
|
700
|
+
|
701
|
+
const waitForCustom = async (qq, processor) => {
|
702
|
+
var _qq3, _data$sender19;
|
703
|
+
|
704
|
+
qq = (_qq3 = qq) !== null && _qq3 !== void 0 ? _qq3 : data === null || data === void 0 ? void 0 : (_data$sender19 = data.sender) === null || _data$sender19 === void 0 ? void 0 : _data$sender19.id;
|
705
|
+
|
706
|
+
if (qq == undefined) {
|
707
|
+
throw new Error('Middleware.syncWrapper 消息格式出错');
|
708
|
+
}
|
709
|
+
|
710
|
+
do {
|
711
|
+
var _data$sender20, _data$bot3, _data$bot3$waiter;
|
712
|
+
|
713
|
+
var data = await ((_data$bot3 = data.bot) === null || _data$bot3 === void 0 ? void 0 : (_data$bot3$waiter = _data$bot3.waiter) === null || _data$bot3$waiter === void 0 ? void 0 : _data$bot3$waiter.wait(data.type, new Middleware().textProcessor().done(data => data)));
|
714
|
+
} while (qq != (data === null || data === void 0 ? void 0 : (_data$sender20 = data.sender) === null || _data$sender20 === void 0 ? void 0 : _data$sender20.id));
|
715
|
+
|
716
|
+
return await processor(data);
|
717
|
+
};
|
718
|
+
|
719
|
+
data.waitFor = {
|
720
|
+
groupMember: (qq = undefined) => {
|
721
|
+
return {
|
722
|
+
messageChain: () => watiForMessageChain(qq),
|
723
|
+
text: () => waitForText(qq),
|
724
|
+
custom: processor => waitForCustom(qq, processor)
|
725
|
+
};
|
726
|
+
},
|
727
|
+
friend: qq => {
|
728
|
+
return {
|
729
|
+
messageChain: () => watiForMessageChain(qq),
|
730
|
+
text: () => waitForText(qq),
|
731
|
+
custom: processor => waitForCustom(qq, processor)
|
732
|
+
};
|
733
|
+
},
|
734
|
+
messageChain: () => watiForMessageChain(data.sender.id),
|
735
|
+
text: () => waitForText(data.sender.id),
|
736
|
+
custom: processor => waitForCustom(data.sender.id, processor)
|
672
737
|
};
|
673
738
|
await next();
|
674
739
|
} catch (error) {
|
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
|
+
};
|