mirai-js 2.2.0 → 2.4.1
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/README.md +17 -283
- package/demo.html +1 -1
- package/demo.js +13 -71
- package/dist/browser/mirai-js.js +1 -1
- package/dist/node/BaseType.d.ts +5 -2
- package/dist/node/Bot.d.ts +95 -8
- package/dist/node/Bot.js +233 -10
- package/dist/node/FileManager.js +15 -6
- package/dist/node/core/anno/deleteAnno.js +67 -0
- package/dist/node/core/anno/getAnno.js +70 -0
- package/dist/node/core/anno/publishAnno.js +70 -0
- package/dist/node/core/auth.js +9 -11
- package/dist/node/core/fs/deleteGroupFile.js +71 -0
- package/dist/node/core/fs/getGroupFileInfo.js +77 -0
- package/dist/node/core/fs/getGroupFileList.js +82 -0
- package/dist/node/core/fs/makeGroupDir.js +73 -0
- package/dist/node/core/fs/moveGroupFile.js +77 -0
- package/dist/node/core/fs/renameGroupFile.js +73 -0
- package/dist/node/core/fs/uploadGroupFIle.js +81 -0
- package/dist/node/core/getFriendList.js +9 -11
- package/dist/node/core/getGroupConfig.js +9 -11
- package/dist/node/core/getGroupFileInfo.js +6 -2
- package/dist/node/core/getGroupFileList.js +6 -2
- package/dist/node/core/getGroupList.js +9 -11
- package/dist/node/core/getMemberInfo.js +13 -19
- package/dist/node/core/getMemberList.js +9 -11
- package/dist/node/core/getSessionConfig.js +9 -11
- package/dist/node/core/getUserProfile.js +78 -0
- package/dist/node/core/groupFileDelete.js +6 -2
- package/dist/node/core/groupFileMove.js +6 -2
- package/dist/node/core/groupFileRename.js +6 -2
- package/dist/node/core/mute.js +9 -11
- package/dist/node/core/muteAll.js +9 -11
- package/dist/node/core/quitGroup.js +9 -11
- package/dist/node/core/recall.js +9 -11
- package/dist/node/core/releaseSession.js +10 -11
- package/dist/node/core/removeFriend.js +64 -0
- package/dist/node/core/removeMember.js +9 -11
- package/dist/node/core/responseBotInvitedJoinGroupRequest.js +9 -11
- package/dist/node/core/responseFirendRequest.js +9 -11
- package/dist/node/core/responseMemberJoinRequest.js +9 -11
- package/dist/node/core/sendCommand.js +9 -11
- package/dist/node/core/sendFirendMessage.js +9 -11
- package/dist/node/core/sendGroupMessage.js +9 -11
- package/dist/node/core/sendNudge.js +9 -11
- package/dist/node/core/sendTempMessage.js +9 -11
- package/dist/node/core/setEssence.js +9 -11
- package/dist/node/core/setGroupConfig.js +9 -11
- package/dist/node/core/setMemberAdmin.js +70 -0
- package/dist/node/core/setMemberInfo.js +9 -11
- package/dist/node/core/setSessionConfig.js +9 -11
- package/dist/node/core/startListeningBrowser.js +8 -9
- package/dist/node/core/startListeningNode.js +8 -10
- package/dist/node/core/stopListeningBrowser.js +5 -1
- package/dist/node/core/stopListeningNode.js +5 -1
- package/dist/node/core/unmute.js +9 -11
- package/dist/node/core/unmuteAll.js +9 -11
- package/dist/node/core/uploadFileAndSend.js +6 -1
- package/dist/node/core/uploadImage.js +9 -10
- package/dist/node/core/uploadVoice.js +9 -10
- package/dist/node/core/verify.js +9 -11
- package/dist/node/polyfill/URL.js +5 -0
- package/dist/node/polyfill/wsListener.js +6 -0
- package/package.json +2 -2
- package/src/BaseType.d.ts +5 -2
- package/src/Bot.d.ts +95 -8
- package/src/Bot.js +154 -9
- package/src/FileManager.js +10 -6
- package/src/core/anno/deleteAnno.js +42 -0
- package/src/core/anno/getAnno.js +43 -0
- package/src/core/anno/publishAnno.js +43 -0
- package/src/core/auth.js +5 -7
- package/src/core/fs/deleteGroupFile.js +44 -0
- package/src/core/fs/getGroupFileInfo.js +45 -0
- package/src/core/fs/getGroupFileList.js +46 -0
- package/src/core/fs/makeGroupDir.js +44 -0
- package/src/core/fs/moveGroupFile.js +46 -0
- package/src/core/{groupFileRename.js → fs/renameGroupFile.js} +11 -13
- package/src/core/{uploadFileAndSend.js → fs/uploadGroupFIle.js} +9 -11
- package/src/core/getFriendList.js +5 -7
- package/src/core/getGroupConfig.js +5 -7
- package/src/core/getGroupList.js +5 -7
- package/src/core/getMemberInfo.js +8 -10
- package/src/core/getMemberList.js +5 -7
- package/src/core/getSessionConfig.js +5 -7
- package/src/core/getUserProfile.js +39 -0
- package/src/core/mute.js +5 -7
- package/src/core/muteAll.js +5 -7
- package/src/core/quitGroup.js +5 -7
- package/src/core/recall.js +5 -7
- package/src/core/releaseSession.js +6 -7
- package/src/core/{groupFileDelete.js → removeFriend.js} +11 -17
- package/src/core/removeMember.js +5 -7
- package/src/core/responseBotInvitedJoinGroupRequest.js +5 -7
- package/src/core/responseFirendRequest.js +5 -7
- package/src/core/responseMemberJoinRequest.js +5 -7
- package/src/core/sendCommand.js +5 -7
- package/src/core/sendFirendMessage.js +5 -7
- package/src/core/sendGroupMessage.js +5 -7
- package/src/core/sendNudge.js +5 -7
- package/src/core/sendTempMessage.js +5 -7
- package/src/core/setEssence.js +5 -7
- package/src/core/setGroupConfig.js +5 -7
- package/src/core/setMemberAdmin.js +43 -0
- package/src/core/setMemberInfo.js +5 -7
- package/src/core/setSessionConfig.js +5 -7
- package/src/core/startListeningBrowser.js +4 -6
- package/src/core/startListeningNode.js +4 -6
- package/src/core/stopListeningBrowser.js +3 -0
- package/src/core/stopListeningNode.js +3 -0
- package/src/core/unmute.js +5 -7
- package/src/core/unmuteAll.js +5 -7
- package/src/core/uploadImage.js +5 -7
- package/src/core/uploadVoice.js +5 -7
- package/src/core/verify.js +5 -7
- package/src/polyfill/URL.js +3 -0
- package/src/polyfill/wsListener.js +4 -0
- package/webpack.config.js +4 -0
- package/src/core/getGroupFileInfo.js +0 -44
- package/src/core/getGroupFileList.js +0 -40
- package/src/core/groupFileMove.js +0 -46
package/dist/node/Bot.js
CHANGED
@@ -33,8 +33,18 @@ const _getMemberList = require('./core/getMemberList');
|
|
33
33
|
|
34
34
|
const _getMemberInfo = require('./core/getMemberInfo');
|
35
35
|
|
36
|
+
const _getUserProfile = require('./core/getUserProfile');
|
37
|
+
|
36
38
|
const _setMemberInfo = require('./core/setMemberInfo');
|
37
39
|
|
40
|
+
const _setMemberAdmin = require('./core/setMemberAdmin');
|
41
|
+
|
42
|
+
const _getAnnoList = require('./core/anno/getAnno');
|
43
|
+
|
44
|
+
const _publishAnno = require('./core/anno/publishAnno');
|
45
|
+
|
46
|
+
const _deleteAnno = require('./core/anno/deleteAnno');
|
47
|
+
|
38
48
|
const _recall = require('./core/recall');
|
39
49
|
|
40
50
|
const _mute = require('./core/mute');
|
@@ -47,6 +57,8 @@ const _unmuteAll = require('./core/unmuteAll');
|
|
47
57
|
|
48
58
|
const _removeMember = require('./core/removeMember');
|
49
59
|
|
60
|
+
const _removeFriend = require('./core/removeFriend');
|
61
|
+
|
50
62
|
const _quitGroup = require('./core/quitGroup');
|
51
63
|
|
52
64
|
const _getGroupConfig = require('./core/getGroupConfig');
|
@@ -55,9 +67,10 @@ const _setGroupConfig = require('./core/setGroupConfig');
|
|
55
67
|
|
56
68
|
const _setEssence = require('./core/setEssence');
|
57
69
|
|
58
|
-
const
|
59
|
-
|
60
|
-
|
70
|
+
const {
|
71
|
+
wsStartListening: _startListening,
|
72
|
+
wsStopListening: _stopListening
|
73
|
+
} = require('./polyfill/wsListener'); // 其他
|
61
74
|
|
62
75
|
|
63
76
|
const random = require('./util/random')(0, 2E16);
|
@@ -910,7 +923,7 @@ class Bot extends BotConfigGetable {
|
|
910
923
|
* @description 获取群成员信息
|
911
924
|
* @param {number} group 必选,群成员所在群号
|
912
925
|
* @param {number} qq 必选,群成员的 qq 号
|
913
|
-
* @returns {Object
|
926
|
+
* @returns {Object}
|
914
927
|
*/
|
915
928
|
|
916
929
|
|
@@ -947,12 +960,44 @@ class Bot extends BotConfigGetable {
|
|
947
960
|
delete memberInfo.specialTitle;
|
948
961
|
return memberInfo;
|
949
962
|
}
|
963
|
+
/**
|
964
|
+
* @description 获取群成员信息
|
965
|
+
* @param {number} qq 必选,用户的 qq 号
|
966
|
+
* @returns {Object} 结构 { nickname, email, age, level, sign, sex }
|
967
|
+
*/
|
968
|
+
|
969
|
+
|
970
|
+
async getUserProfile({
|
971
|
+
qq
|
972
|
+
}) {
|
973
|
+
// 检查对象状态
|
974
|
+
if (!this.config) {
|
975
|
+
throw new Error('getUserProfile 请先调用 open,建立一个会话');
|
976
|
+
} // 检查参数
|
977
|
+
|
978
|
+
|
979
|
+
if (!qq) {
|
980
|
+
throw new Error('getUserProfile 缺少必要的 qq 参数');
|
981
|
+
}
|
982
|
+
|
983
|
+
const {
|
984
|
+
baseUrl,
|
985
|
+
sessionKey
|
986
|
+
} = this.config;
|
987
|
+
return await _getUserProfile({
|
988
|
+
baseUrl,
|
989
|
+
sessionKey,
|
990
|
+
target: qq
|
991
|
+
});
|
992
|
+
}
|
950
993
|
/**
|
951
994
|
* @description 设置群成员信息
|
952
995
|
* @param {number} group 必选,群成员所在群号
|
953
996
|
* @param {number} qq 必选,群成员的 qq 号
|
954
997
|
* @param {string} name 可选,要设置的群名片
|
955
998
|
* @param {string} title 可选,要设置的群头衔
|
999
|
+
* @param {boolean} permission 可选,要设置的权限,
|
1000
|
+
* 使用枚举值:Bot.Permission.Admin, Bot.Permission.Member
|
956
1001
|
* @returns {void}
|
957
1002
|
*/
|
958
1003
|
|
@@ -961,7 +1006,8 @@ class Bot extends BotConfigGetable {
|
|
961
1006
|
group,
|
962
1007
|
qq,
|
963
1008
|
name,
|
964
|
-
title
|
1009
|
+
title,
|
1010
|
+
permission
|
965
1011
|
}) {
|
966
1012
|
// 检查对象状态
|
967
1013
|
if (!this.config) {
|
@@ -974,6 +1020,58 @@ class Bot extends BotConfigGetable {
|
|
974
1020
|
group,
|
975
1021
|
qq
|
976
1022
|
})} 参数`);
|
1023
|
+
}
|
1024
|
+
|
1025
|
+
if (permission != undefined && permission != Bot.groupPermission.ADMINISTRATOR && permission != Bot.groupPermission.MEMBER) {
|
1026
|
+
throw new Error('setMemberInfo admin 参数只能是 Bot.groupPermission.ADMINISTRATOR 或 Bot.groupPermission.Member');
|
1027
|
+
} // setMemberInfo
|
1028
|
+
|
1029
|
+
|
1030
|
+
const {
|
1031
|
+
baseUrl,
|
1032
|
+
sessionKey
|
1033
|
+
} = this.config;
|
1034
|
+
|
1035
|
+
if (name != undefined || title != undefined) {
|
1036
|
+
await _setMemberInfo({
|
1037
|
+
baseUrl,
|
1038
|
+
sessionKey,
|
1039
|
+
target: group,
|
1040
|
+
memberId: qq,
|
1041
|
+
name,
|
1042
|
+
specialTitle: title
|
1043
|
+
});
|
1044
|
+
} // setPermission
|
1045
|
+
|
1046
|
+
|
1047
|
+
if (permission != undefined) {
|
1048
|
+
await _setMemberAdmin({
|
1049
|
+
baseUrl,
|
1050
|
+
sessionKey,
|
1051
|
+
target: group,
|
1052
|
+
memberId: qq,
|
1053
|
+
assign: permission == Bot.groupPermission.ADMINISTRATOR ? true : false
|
1054
|
+
});
|
1055
|
+
}
|
1056
|
+
}
|
1057
|
+
/**
|
1058
|
+
* @description 获取群公告列表迭代器
|
1059
|
+
* @param {number} group 必选,群号
|
1060
|
+
* @returns 迭代器
|
1061
|
+
*/
|
1062
|
+
|
1063
|
+
|
1064
|
+
async *getAnnoIter({
|
1065
|
+
group
|
1066
|
+
}) {
|
1067
|
+
// 检查对象状态
|
1068
|
+
if (!this.config) {
|
1069
|
+
throw new Error('getAnno 请先调用 open,建立一个会话');
|
1070
|
+
} // 检查参数
|
1071
|
+
|
1072
|
+
|
1073
|
+
if (!group) {
|
1074
|
+
throw new Error('getAnno 缺少必要的 group 参数');
|
977
1075
|
} // 获取列表
|
978
1076
|
|
979
1077
|
|
@@ -981,13 +1079,107 @@ class Bot extends BotConfigGetable {
|
|
981
1079
|
baseUrl,
|
982
1080
|
sessionKey
|
983
1081
|
} = this.config;
|
984
|
-
|
1082
|
+
let offset = 0;
|
1083
|
+
let annoList = await _getAnnoList({
|
1084
|
+
baseUrl,
|
1085
|
+
sessionKey,
|
1086
|
+
id: group,
|
1087
|
+
offset,
|
1088
|
+
size: 10
|
1089
|
+
});
|
1090
|
+
|
1091
|
+
while (annoList.length > 0) {
|
1092
|
+
for (const anno of annoList) {
|
1093
|
+
yield anno;
|
1094
|
+
} // 获取下一页
|
1095
|
+
|
1096
|
+
|
1097
|
+
offset += 10;
|
1098
|
+
annoList = await _getAnnoList({
|
1099
|
+
baseUrl,
|
1100
|
+
sessionKey,
|
1101
|
+
id: group,
|
1102
|
+
offset,
|
1103
|
+
size: 10
|
1104
|
+
});
|
1105
|
+
}
|
1106
|
+
|
1107
|
+
return;
|
1108
|
+
}
|
1109
|
+
/**
|
1110
|
+
* @description 发布群公告
|
1111
|
+
* @param {number} group 必选,群号
|
1112
|
+
* @param {string} content 必选,公告内容
|
1113
|
+
* @returns {void}
|
1114
|
+
*/
|
1115
|
+
|
1116
|
+
|
1117
|
+
async publishAnno({
|
1118
|
+
group,
|
1119
|
+
content,
|
1120
|
+
pinned
|
1121
|
+
}) {
|
1122
|
+
// 检查对象状态
|
1123
|
+
if (!this.config) {
|
1124
|
+
throw new Error('publishAllo 请先调用 open,建立一个会话');
|
1125
|
+
} // 检查参数
|
1126
|
+
|
1127
|
+
|
1128
|
+
if (!group || !content) {
|
1129
|
+
throw new Error(`publishAllo 缺少必要的 ${getInvalidParamsString({
|
1130
|
+
group,
|
1131
|
+
content
|
1132
|
+
})} 参数`);
|
1133
|
+
} // 发布公告
|
1134
|
+
|
1135
|
+
|
1136
|
+
const {
|
1137
|
+
baseUrl,
|
1138
|
+
sessionKey
|
1139
|
+
} = this.config;
|
1140
|
+
await _publishAnno({
|
985
1141
|
baseUrl,
|
986
1142
|
sessionKey,
|
987
1143
|
target: group,
|
988
|
-
|
989
|
-
|
990
|
-
|
1144
|
+
content,
|
1145
|
+
pinned
|
1146
|
+
});
|
1147
|
+
}
|
1148
|
+
/**
|
1149
|
+
* @description 删除群公告
|
1150
|
+
* @param {number} group 必选,群号
|
1151
|
+
* @param {string} fid 必选,公告 id
|
1152
|
+
* @reaturns {void}
|
1153
|
+
*/
|
1154
|
+
|
1155
|
+
|
1156
|
+
async deleteAnno({
|
1157
|
+
group,
|
1158
|
+
fid
|
1159
|
+
}) {
|
1160
|
+
// 检查对象状态
|
1161
|
+
if (!this.config) {
|
1162
|
+
throw new Error('deleteAnno 请先调用 open,建立一个会话');
|
1163
|
+
} // 检查参数
|
1164
|
+
|
1165
|
+
|
1166
|
+
if (!group || !fid) {
|
1167
|
+
throw new Error(`deleteAnno 缺少必要的 ${getInvalidParamsString({
|
1168
|
+
group,
|
1169
|
+
fid
|
1170
|
+
})} 参数`);
|
1171
|
+
} // 发布公告
|
1172
|
+
|
1173
|
+
|
1174
|
+
const {
|
1175
|
+
baseUrl,
|
1176
|
+
sessionKey
|
1177
|
+
} = this.config;
|
1178
|
+
await _deleteAnno({
|
1179
|
+
baseUrl,
|
1180
|
+
sessionKey,
|
1181
|
+
id: group,
|
1182
|
+
fid
|
991
1183
|
});
|
992
1184
|
}
|
993
1185
|
/**
|
@@ -1170,6 +1362,37 @@ class Bot extends BotConfigGetable {
|
|
1170
1362
|
msg: message
|
1171
1363
|
});
|
1172
1364
|
}
|
1365
|
+
/**
|
1366
|
+
* @description 删除好友
|
1367
|
+
* @param {*} qq 欲删除的好友 qq 号
|
1368
|
+
* @returns {void}
|
1369
|
+
*/
|
1370
|
+
|
1371
|
+
|
1372
|
+
async removeFriend({
|
1373
|
+
qq
|
1374
|
+
}) {
|
1375
|
+
// 检查对象状态
|
1376
|
+
if (!this.config) {
|
1377
|
+
throw new Error('removeFriend 请先调用 open,建立一个会话');
|
1378
|
+
} // 检查参数
|
1379
|
+
|
1380
|
+
|
1381
|
+
if (!qq) {
|
1382
|
+
throw new Error('removeFriend 缺少必要的 qq 参数');
|
1383
|
+
}
|
1384
|
+
|
1385
|
+
const {
|
1386
|
+
baseUrl,
|
1387
|
+
sessionKey
|
1388
|
+
} = this.config; // 删除好友
|
1389
|
+
|
1390
|
+
await _removeFriend({
|
1391
|
+
baseUrl,
|
1392
|
+
sessionKey,
|
1393
|
+
target: qq
|
1394
|
+
});
|
1395
|
+
}
|
1173
1396
|
/**
|
1174
1397
|
* @description 移除群成员
|
1175
1398
|
* @param {number} group 必选,欲移除的成员所在群号
|
@@ -1180,7 +1403,7 @@ class Bot extends BotConfigGetable {
|
|
1180
1403
|
async quitGroup({
|
1181
1404
|
group
|
1182
1405
|
}) {
|
1183
|
-
// 检查对象状态
|
1406
|
+
// 检查对象状态
|
1184
1407
|
if (!this.config) {
|
1185
1408
|
throw new Error('quitGroup 请先调用 open,建立一个会话');
|
1186
1409
|
} // 检查参数
|
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,
|
@@ -0,0 +1,67 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
const {
|
4
|
+
errCodeMap
|
5
|
+
} = require('../../util/errCode');
|
6
|
+
|
7
|
+
const axios = require('axios');
|
8
|
+
|
9
|
+
const {
|
10
|
+
URL
|
11
|
+
} = require('../../polyfill/URL');
|
12
|
+
|
13
|
+
const errorHandler = require('../../util/errorHandler');
|
14
|
+
|
15
|
+
const path = require('path');
|
16
|
+
|
17
|
+
const locationStr = `core.${path.basename(__filename, path.extname(__filename))}`;
|
18
|
+
/**
|
19
|
+
* @description 删除群公告
|
20
|
+
* @param {string} baseUrl mirai-api-http server 的地址
|
21
|
+
* @param {string} sessionKey 会话标识
|
22
|
+
* @param {number} id 群号
|
23
|
+
* @param {string} fid 公告 id
|
24
|
+
* @returns {Object} { code, msg }
|
25
|
+
*/
|
26
|
+
|
27
|
+
module.exports = async ({
|
28
|
+
baseUrl,
|
29
|
+
sessionKey,
|
30
|
+
id,
|
31
|
+
fid
|
32
|
+
}) => {
|
33
|
+
try {
|
34
|
+
// 拼接 url
|
35
|
+
const url = new URL('/anno/delete', baseUrl).toString(); // 请求
|
36
|
+
|
37
|
+
const responseData = await axios.post(url, {
|
38
|
+
sessionKey,
|
39
|
+
id,
|
40
|
+
fid
|
41
|
+
});
|
42
|
+
|
43
|
+
try {
|
44
|
+
var {
|
45
|
+
data: {
|
46
|
+
msg: message,
|
47
|
+
code
|
48
|
+
}
|
49
|
+
} = responseData;
|
50
|
+
} catch (error) {
|
51
|
+
throw new Error('请求返回格式出错,请检查 mirai-console');
|
52
|
+
} // 抛出 mirai 的异常,到 catch 中处理后再抛出
|
53
|
+
|
54
|
+
|
55
|
+
if (code in errCodeMap) {
|
56
|
+
throw new Error(message);
|
57
|
+
}
|
58
|
+
|
59
|
+
return {
|
60
|
+
message,
|
61
|
+
code
|
62
|
+
};
|
63
|
+
} catch (error) {
|
64
|
+
console.error(`mirai-js: error ${locationStr}`);
|
65
|
+
errorHandler(error);
|
66
|
+
}
|
67
|
+
};
|
@@ -0,0 +1,70 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
const {
|
4
|
+
errCodeMap
|
5
|
+
} = require('../../util/errCode');
|
6
|
+
|
7
|
+
const axios = require('axios').default;
|
8
|
+
|
9
|
+
const {
|
10
|
+
URL
|
11
|
+
} = require('../../polyfill/URL');
|
12
|
+
|
13
|
+
const errorHandler = require('../../util/errorHandler');
|
14
|
+
|
15
|
+
const path = require('path');
|
16
|
+
|
17
|
+
const locationStr = `core.${path.basename(__filename, path.extname(__filename))}`;
|
18
|
+
/**
|
19
|
+
* @description 获取群公告
|
20
|
+
* @param {string} baseUrl mirai-api-http server 的地址
|
21
|
+
* @param {string} sessionKey 会话标识
|
22
|
+
* @param {number} id 群号
|
23
|
+
* @param {number} offset 分页
|
24
|
+
* @param {number} size 分页, 默认 10
|
25
|
+
* @returns {Object[]}
|
26
|
+
*/
|
27
|
+
|
28
|
+
module.exports = async ({
|
29
|
+
baseUrl,
|
30
|
+
sessionKey,
|
31
|
+
id,
|
32
|
+
offset,
|
33
|
+
size = 10
|
34
|
+
}) => {
|
35
|
+
try {
|
36
|
+
// 拼接 url
|
37
|
+
const url = new URL('/anno/list', baseUrl).toString(); // 请求
|
38
|
+
|
39
|
+
const responseData = await axios.get(url, {
|
40
|
+
params: {
|
41
|
+
sessionKey,
|
42
|
+
id,
|
43
|
+
offset,
|
44
|
+
size
|
45
|
+
}
|
46
|
+
});
|
47
|
+
|
48
|
+
try {
|
49
|
+
var {
|
50
|
+
data: {
|
51
|
+
msg: message,
|
52
|
+
code,
|
53
|
+
data
|
54
|
+
}
|
55
|
+
} = responseData;
|
56
|
+
} catch (error) {
|
57
|
+
throw new Error('请求返回格式出错,请检查 mirai-console');
|
58
|
+
} // 抛出 mirai 的异常,到 catch 中处理后再抛出
|
59
|
+
|
60
|
+
|
61
|
+
if (code in errCodeMap) {
|
62
|
+
throw new Error(message);
|
63
|
+
}
|
64
|
+
|
65
|
+
return data;
|
66
|
+
} catch (error) {
|
67
|
+
console.error(`mirai-js: error ${locationStr}`);
|
68
|
+
errorHandler(error);
|
69
|
+
}
|
70
|
+
};
|
@@ -0,0 +1,70 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
const {
|
4
|
+
errCodeMap
|
5
|
+
} = require('../../util/errCode');
|
6
|
+
|
7
|
+
const axios = require('axios');
|
8
|
+
|
9
|
+
const {
|
10
|
+
URL
|
11
|
+
} = require('../../polyfill/URL');
|
12
|
+
|
13
|
+
const errorHandler = require('../../util/errorHandler');
|
14
|
+
|
15
|
+
const path = require('path');
|
16
|
+
|
17
|
+
const locationStr = `core.${path.basename(__filename, path.extname(__filename))}`;
|
18
|
+
/**
|
19
|
+
* @description 发布群公告
|
20
|
+
* @param {string} baseUrl mirai-api-http server 的地址
|
21
|
+
* @param {string} sessionKey 会话标识
|
22
|
+
* @param {number} target 群号
|
23
|
+
* @param {string} content 公告内容
|
24
|
+
* @param {boolean} pinned 是否置顶
|
25
|
+
* @returns {Object} { code, msg }
|
26
|
+
*/
|
27
|
+
|
28
|
+
module.exports = async ({
|
29
|
+
baseUrl,
|
30
|
+
sessionKey,
|
31
|
+
target,
|
32
|
+
content,
|
33
|
+
pinned
|
34
|
+
}) => {
|
35
|
+
try {
|
36
|
+
// 拼接 url
|
37
|
+
const url = new URL('/anno/publish', baseUrl).toString(); // 请求
|
38
|
+
|
39
|
+
const responseData = await axios.post(url, {
|
40
|
+
sessionKey,
|
41
|
+
target,
|
42
|
+
content,
|
43
|
+
pinned
|
44
|
+
});
|
45
|
+
|
46
|
+
try {
|
47
|
+
var {
|
48
|
+
data: {
|
49
|
+
msg: message,
|
50
|
+
code
|
51
|
+
}
|
52
|
+
} = responseData;
|
53
|
+
} catch (error) {
|
54
|
+
throw new Error('请求返回格式出错,请检查 mirai-console');
|
55
|
+
} // 抛出 mirai 的异常,到 catch 中处理后再抛出
|
56
|
+
|
57
|
+
|
58
|
+
if (code in errCodeMap) {
|
59
|
+
throw new Error(message);
|
60
|
+
}
|
61
|
+
|
62
|
+
return {
|
63
|
+
message,
|
64
|
+
code
|
65
|
+
};
|
66
|
+
} catch (error) {
|
67
|
+
console.error(`mirai-js: error ${locationStr}`);
|
68
|
+
errorHandler(error);
|
69
|
+
}
|
70
|
+
};
|
package/dist/node/core/auth.js
CHANGED
@@ -6,17 +6,15 @@ const {
|
|
6
6
|
|
7
7
|
const axios = require('axios');
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
({
|
13
|
-
URL
|
14
|
-
} = require('url'));
|
15
|
-
} else {
|
16
|
-
URL = window.URL;
|
17
|
-
}
|
9
|
+
const {
|
10
|
+
URL
|
11
|
+
} = require('../polyfill/URL');
|
18
12
|
|
19
13
|
const errorHandler = require('../util/errorHandler');
|
14
|
+
|
15
|
+
const path = require('path');
|
16
|
+
|
17
|
+
const locationStr = `core.${path.basename(__filename, path.extname(__filename))}`;
|
20
18
|
/**
|
21
19
|
*
|
22
20
|
* @description 认证 verifyKey,创建回话,返回一个 sessionKey
|
@@ -25,7 +23,6 @@ const errorHandler = require('../util/errorHandler');
|
|
25
23
|
* @returns {string} 会话标识 sessionKey
|
26
24
|
*/
|
27
25
|
|
28
|
-
|
29
26
|
module.exports = async ({
|
30
27
|
baseUrl,
|
31
28
|
verifyKey
|
@@ -47,7 +44,7 @@ module.exports = async ({
|
|
47
44
|
}
|
48
45
|
} = responseData;
|
49
46
|
} catch (error) {
|
50
|
-
throw new Error('
|
47
|
+
throw new Error('请求返回格式出错,请检查 mirai-console');
|
51
48
|
} // 抛出 mirai 的异常,到 catch 中处理后再抛出
|
52
49
|
|
53
50
|
|
@@ -57,6 +54,7 @@ module.exports = async ({
|
|
57
54
|
|
58
55
|
return sessionKey;
|
59
56
|
} catch (error) {
|
57
|
+
console.error(`mirai-js: error ${locationStr}`);
|
60
58
|
errorHandler(error);
|
61
59
|
}
|
62
60
|
};
|
@@ -0,0 +1,71 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
const {
|
4
|
+
errCodeMap
|
5
|
+
} = require('../../util/errCode');
|
6
|
+
|
7
|
+
const axios = require('axios');
|
8
|
+
|
9
|
+
const {
|
10
|
+
URL
|
11
|
+
} = require('../../polyfill/URL');
|
12
|
+
|
13
|
+
const errorHandler = require('../../util/errorHandler');
|
14
|
+
|
15
|
+
const path = require('path');
|
16
|
+
|
17
|
+
const locationStr = `core.${path.basename(__filename, path.extname(__filename))}`;
|
18
|
+
/**
|
19
|
+
* @description 删除群文件
|
20
|
+
* @param {string} baseUrl mirai-api-http server 的地址
|
21
|
+
* @param {string} sessionKey 会话标识
|
22
|
+
* @param {string} id 文件夹id, 空串为根目录
|
23
|
+
* @param {string} path 文件夹路径, 文件夹允许重名, 不保证准确, 准确定位使用 id
|
24
|
+
* @param {number} group 群号
|
25
|
+
* @returns {Object} 结构 { message, code }
|
26
|
+
*/
|
27
|
+
|
28
|
+
module.exports = async ({
|
29
|
+
baseUrl,
|
30
|
+
sessionKey,
|
31
|
+
id,
|
32
|
+
path,
|
33
|
+
group
|
34
|
+
}) => {
|
35
|
+
try {
|
36
|
+
// 拼接 url
|
37
|
+
const url = new URL('/file/delete', baseUrl).toString(); // 请求
|
38
|
+
|
39
|
+
const responseData = await axios.post(url, {
|
40
|
+
sessionKey,
|
41
|
+
id,
|
42
|
+
path,
|
43
|
+
target: group,
|
44
|
+
group
|
45
|
+
});
|
46
|
+
|
47
|
+
try {
|
48
|
+
var {
|
49
|
+
data: {
|
50
|
+
msg: message,
|
51
|
+
code
|
52
|
+
}
|
53
|
+
} = responseData;
|
54
|
+
} catch (error) {
|
55
|
+
throw new Error('请求返回格式出错,请检查 mirai-console');
|
56
|
+
} // 抛出 mirai 的异常,到 catch 中处理后再抛出
|
57
|
+
|
58
|
+
|
59
|
+
if (code in errCodeMap) {
|
60
|
+
throw new Error(message);
|
61
|
+
}
|
62
|
+
|
63
|
+
return {
|
64
|
+
message,
|
65
|
+
code
|
66
|
+
};
|
67
|
+
} catch (error) {
|
68
|
+
console.error(`mirai-js: error ${locationStr}`);
|
69
|
+
errorHandler(error);
|
70
|
+
}
|
71
|
+
};
|