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/src/Bot.js
CHANGED
@@ -15,19 +15,24 @@ const _getFriendList = require('./core/getFriendList');
|
|
15
15
|
const _getGroupList = require('./core/getGroupList');
|
16
16
|
const _getMemberList = require('./core/getMemberList');
|
17
17
|
const _getMemberInfo = require('./core/getMemberInfo');
|
18
|
+
const _getUserProfile = require('./core/getUserProfile');
|
18
19
|
const _setMemberInfo = require('./core/setMemberInfo');
|
20
|
+
const _setMemberAdmin = require('./core/setMemberAdmin');
|
21
|
+
const _getAnnoList = require('./core/anno/getAnno');
|
22
|
+
const _publishAnno = require('./core/anno/publishAnno');
|
23
|
+
const _deleteAnno = require('./core/anno/deleteAnno');
|
19
24
|
const _recall = require('./core/recall');
|
20
25
|
const _mute = require('./core/mute');
|
21
26
|
const _muteAll = require('./core/muteAll');
|
22
27
|
const _unmute = require('./core/unmute');
|
23
28
|
const _unmuteAll = require('./core/unmuteAll');
|
24
29
|
const _removeMember = require('./core/removeMember');
|
30
|
+
const _removeFriend = require('./core/removeFriend');
|
25
31
|
const _quitGroup = require('./core/quitGroup');
|
26
32
|
const _getGroupConfig = require('./core/getGroupConfig');
|
27
33
|
const _setGroupConfig = require('./core/setGroupConfig');
|
28
34
|
const _setEssence = require('./core/setEssence');
|
29
|
-
const _startListening
|
30
|
-
const _stopListening = process.browser ? require('./core/stopListeningBrowser') : require('./core/stopListeningNode');
|
35
|
+
const { wsStartListening: _startListening, wsStopListening: _stopListening } = require('./polyfill/wsListener');
|
31
36
|
|
32
37
|
// 其他
|
33
38
|
const random = require('./util/random')(0, 2E16);
|
@@ -691,7 +696,7 @@ class Bot extends BotConfigGetable {
|
|
691
696
|
* @description 获取群成员信息
|
692
697
|
* @param {number} group 必选,群成员所在群号
|
693
698
|
* @param {number} qq 必选,群成员的 qq 号
|
694
|
-
* @returns {Object
|
699
|
+
* @returns {Object}
|
695
700
|
*/
|
696
701
|
async getMemberInfo({ group, qq }) {
|
697
702
|
// 检查对象状态
|
@@ -719,15 +724,37 @@ class Bot extends BotConfigGetable {
|
|
719
724
|
return memberInfo;
|
720
725
|
}
|
721
726
|
|
727
|
+
/**
|
728
|
+
* @description 获取群成员信息
|
729
|
+
* @param {number} qq 必选,用户的 qq 号
|
730
|
+
* @returns {Object} 结构 { nickname, email, age, level, sign, sex }
|
731
|
+
*/
|
732
|
+
async getUserProfile({ qq }) {
|
733
|
+
// 检查对象状态
|
734
|
+
if (!this.config) {
|
735
|
+
throw new Error('getUserProfile 请先调用 open,建立一个会话');
|
736
|
+
}
|
737
|
+
|
738
|
+
// 检查参数
|
739
|
+
if (!qq) {
|
740
|
+
throw new Error('getUserProfile 缺少必要的 qq 参数');
|
741
|
+
}
|
742
|
+
|
743
|
+
const { baseUrl, sessionKey } = this.config;
|
744
|
+
return await _getUserProfile({ baseUrl, sessionKey, target: qq });
|
745
|
+
}
|
746
|
+
|
722
747
|
/**
|
723
748
|
* @description 设置群成员信息
|
724
749
|
* @param {number} group 必选,群成员所在群号
|
725
750
|
* @param {number} qq 必选,群成员的 qq 号
|
726
751
|
* @param {string} name 可选,要设置的群名片
|
727
752
|
* @param {string} title 可选,要设置的群头衔
|
753
|
+
* @param {boolean} permission 可选,要设置的权限,
|
754
|
+
* 使用枚举值:Bot.Permission.Admin, Bot.Permission.Member
|
728
755
|
* @returns {void}
|
729
756
|
*/
|
730
|
-
async setMemberInfo({ group, qq, name, title }) {
|
757
|
+
async setMemberInfo({ group, qq, name, title, permission }) {
|
731
758
|
// 检查对象状态
|
732
759
|
if (!this.config) {
|
733
760
|
throw new Error('setMemberInfo 请先调用 open,建立一个会话');
|
@@ -739,13 +766,109 @@ class Bot extends BotConfigGetable {
|
|
739
766
|
group, qq
|
740
767
|
})} 参数`);
|
741
768
|
}
|
769
|
+
if (permission != undefined
|
770
|
+
&& permission != Bot.groupPermission.ADMINISTRATOR
|
771
|
+
&& permission != Bot.groupPermission.MEMBER) {
|
772
|
+
throw new Error('setMemberInfo admin 参数只能是 Bot.groupPermission.ADMINISTRATOR 或 Bot.groupPermission.Member');
|
773
|
+
}
|
774
|
+
|
775
|
+
// setMemberInfo
|
776
|
+
const { baseUrl, sessionKey } = this.config;
|
777
|
+
if (name != undefined || title != undefined) {
|
778
|
+
await _setMemberInfo({
|
779
|
+
baseUrl, sessionKey, target: group, memberId: qq,
|
780
|
+
name, specialTitle: title,
|
781
|
+
});
|
782
|
+
}
|
783
|
+
|
784
|
+
// setPermission
|
785
|
+
if (permission != undefined) {
|
786
|
+
await _setMemberAdmin({
|
787
|
+
baseUrl, sessionKey, target: group, memberId: qq,
|
788
|
+
assign: permission == Bot.groupPermission.ADMINISTRATOR ? true : false,
|
789
|
+
});
|
790
|
+
}
|
791
|
+
}
|
792
|
+
|
793
|
+
/**
|
794
|
+
* @description 获取群公告列表迭代器
|
795
|
+
* @param {number} group 必选,群号
|
796
|
+
* @returns 迭代器
|
797
|
+
*/
|
798
|
+
async *getAnnoIter({ group }) {
|
799
|
+
// 检查对象状态
|
800
|
+
if (!this.config) {
|
801
|
+
throw new Error('getAnno 请先调用 open,建立一个会话');
|
802
|
+
}
|
803
|
+
|
804
|
+
// 检查参数
|
805
|
+
if (!group) {
|
806
|
+
throw new Error('getAnno 缺少必要的 group 参数');
|
807
|
+
}
|
742
808
|
|
743
809
|
// 获取列表
|
744
810
|
const { baseUrl, sessionKey } = this.config;
|
745
|
-
|
746
|
-
|
747
|
-
|
748
|
-
|
811
|
+
let offset = 0;
|
812
|
+
let annoList = await _getAnnoList({ baseUrl, sessionKey, id: group, offset, size: 10 });
|
813
|
+
while (annoList.length > 0) {
|
814
|
+
for (const anno of annoList) {
|
815
|
+
yield anno;
|
816
|
+
}
|
817
|
+
|
818
|
+
// 获取下一页
|
819
|
+
offset += 10;
|
820
|
+
annoList = await _getAnnoList({ baseUrl, sessionKey, id: group, offset, size: 10 });
|
821
|
+
}
|
822
|
+
|
823
|
+
return;
|
824
|
+
}
|
825
|
+
|
826
|
+
/**
|
827
|
+
* @description 发布群公告
|
828
|
+
* @param {number} group 必选,群号
|
829
|
+
* @param {string} content 必选,公告内容
|
830
|
+
* @returns {void}
|
831
|
+
*/
|
832
|
+
async publishAnno({ group, content, pinned }) {
|
833
|
+
// 检查对象状态
|
834
|
+
if (!this.config) {
|
835
|
+
throw new Error('publishAllo 请先调用 open,建立一个会话');
|
836
|
+
}
|
837
|
+
|
838
|
+
// 检查参数
|
839
|
+
if (!group || !content) {
|
840
|
+
throw new Error(`publishAllo 缺少必要的 ${getInvalidParamsString({
|
841
|
+
group, content
|
842
|
+
})} 参数`);
|
843
|
+
}
|
844
|
+
|
845
|
+
// 发布公告
|
846
|
+
const { baseUrl, sessionKey } = this.config;
|
847
|
+
await _publishAnno({ baseUrl, sessionKey, target: group, content, pinned });
|
848
|
+
}
|
849
|
+
|
850
|
+
/**
|
851
|
+
* @description 删除群公告
|
852
|
+
* @param {number} group 必选,群号
|
853
|
+
* @param {string} fid 必选,公告 id
|
854
|
+
* @reaturns {void}
|
855
|
+
*/
|
856
|
+
async deleteAnno({ group, fid }) {
|
857
|
+
// 检查对象状态
|
858
|
+
if (!this.config) {
|
859
|
+
throw new Error('deleteAnno 请先调用 open,建立一个会话');
|
860
|
+
}
|
861
|
+
|
862
|
+
// 检查参数
|
863
|
+
if (!group || !fid) {
|
864
|
+
throw new Error(`deleteAnno 缺少必要的 ${getInvalidParamsString({
|
865
|
+
group, fid
|
866
|
+
})} 参数`);
|
867
|
+
}
|
868
|
+
|
869
|
+
// 发布公告
|
870
|
+
const { baseUrl, sessionKey } = this.config;
|
871
|
+
await _deleteAnno({ baseUrl, sessionKey, id: group, fid });
|
749
872
|
}
|
750
873
|
|
751
874
|
/**
|
@@ -858,13 +981,35 @@ class Bot extends BotConfigGetable {
|
|
858
981
|
await _removeMember({ baseUrl, sessionKey, target: group, memberId: qq, msg: message });
|
859
982
|
}
|
860
983
|
|
984
|
+
/**
|
985
|
+
* @description 删除好友
|
986
|
+
* @param {*} qq 欲删除的好友 qq 号
|
987
|
+
* @returns {void}
|
988
|
+
*/
|
989
|
+
async removeFriend({ qq }) {
|
990
|
+
// 检查对象状态
|
991
|
+
if (!this.config) {
|
992
|
+
throw new Error('removeFriend 请先调用 open,建立一个会话');
|
993
|
+
}
|
994
|
+
|
995
|
+
// 检查参数
|
996
|
+
if (!qq) {
|
997
|
+
throw new Error('removeFriend 缺少必要的 qq 参数');
|
998
|
+
}
|
999
|
+
|
1000
|
+
const { baseUrl, sessionKey } = this.config;
|
1001
|
+
|
1002
|
+
// 删除好友
|
1003
|
+
await _removeFriend({ baseUrl, sessionKey, target: qq });
|
1004
|
+
}
|
1005
|
+
|
861
1006
|
/**
|
862
1007
|
* @description 移除群成员
|
863
1008
|
* @param {number} group 必选,欲移除的成员所在群号
|
864
1009
|
* @returns {void}
|
865
1010
|
*/
|
866
1011
|
async quitGroup({ group }) {
|
867
|
-
// 检查对象状态
|
1012
|
+
// 检查对象状态
|
868
1013
|
if (!this.config) {
|
869
1014
|
throw new Error('quitGroup 请先调用 open,建立一个会话');
|
870
1015
|
}
|
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
|
|
@@ -0,0 +1,42 @@
|
|
1
|
+
const { errCodeMap } = require('../../util/errCode');
|
2
|
+
const axios = require('axios');
|
3
|
+
const { URL } = require('../../polyfill/URL');
|
4
|
+
const errorHandler = require('../../util/errorHandler');
|
5
|
+
const path = require('path');
|
6
|
+
const locationStr = `core.${path.basename(__filename, path.extname(__filename))}`;
|
7
|
+
|
8
|
+
/**
|
9
|
+
* @description 删除群公告
|
10
|
+
* @param {string} baseUrl mirai-api-http server 的地址
|
11
|
+
* @param {string} sessionKey 会话标识
|
12
|
+
* @param {number} id 群号
|
13
|
+
* @param {string} fid 公告 id
|
14
|
+
* @returns {Object} { code, msg }
|
15
|
+
*/
|
16
|
+
module.exports = async ({ baseUrl, sessionKey, id, fid }) => {
|
17
|
+
try {
|
18
|
+
// 拼接 url
|
19
|
+
const url = new URL('/anno/delete', baseUrl).toString();
|
20
|
+
|
21
|
+
// 请求
|
22
|
+
const responseData = await axios.post(url, {
|
23
|
+
sessionKey, id, fid,
|
24
|
+
});
|
25
|
+
try {
|
26
|
+
var {
|
27
|
+
data: { msg: message, code }
|
28
|
+
} = responseData;
|
29
|
+
} catch (error) {
|
30
|
+
throw new Error(('请求返回格式出错,请检查 mirai-console'));
|
31
|
+
}
|
32
|
+
// 抛出 mirai 的异常,到 catch 中处理后再抛出
|
33
|
+
if (code in errCodeMap) {
|
34
|
+
throw new Error(message);
|
35
|
+
}
|
36
|
+
return { message, code };
|
37
|
+
} catch (error) {
|
38
|
+
console.error(`mirai-js: error ${locationStr}`);
|
39
|
+
errorHandler(error);
|
40
|
+
}
|
41
|
+
|
42
|
+
};
|
@@ -0,0 +1,43 @@
|
|
1
|
+
const { errCodeMap } = require('../../util/errCode');
|
2
|
+
const axios = require('axios').default;
|
3
|
+
const { URL } = require('../../polyfill/URL');
|
4
|
+
const errorHandler = require('../../util/errorHandler');
|
5
|
+
const path = require('path');
|
6
|
+
const locationStr = `core.${path.basename(__filename, path.extname(__filename))}`;
|
7
|
+
|
8
|
+
/**
|
9
|
+
* @description 获取群公告
|
10
|
+
* @param {string} baseUrl mirai-api-http server 的地址
|
11
|
+
* @param {string} sessionKey 会话标识
|
12
|
+
* @param {number} id 群号
|
13
|
+
* @param {number} offset 分页
|
14
|
+
* @param {number} size 分页, 默认 10
|
15
|
+
* @returns {Object[]}
|
16
|
+
*/
|
17
|
+
module.exports = async ({ baseUrl, sessionKey, id, offset, size = 10 }) => {
|
18
|
+
try {
|
19
|
+
// 拼接 url
|
20
|
+
const url = new URL('/anno/list', baseUrl).toString();
|
21
|
+
|
22
|
+
// 请求
|
23
|
+
const responseData = await axios.get(url, {
|
24
|
+
params: {
|
25
|
+
sessionKey, id, offset, size,
|
26
|
+
}
|
27
|
+
});
|
28
|
+
try {
|
29
|
+
var { data: { msg: message, code, data } } = responseData;
|
30
|
+
} catch (error) {
|
31
|
+
throw new Error(('请求返回格式出错,请检查 mirai-console'));
|
32
|
+
}
|
33
|
+
|
34
|
+
// 抛出 mirai 的异常,到 catch 中处理后再抛出
|
35
|
+
if (code in errCodeMap) {
|
36
|
+
throw new Error(message);
|
37
|
+
}
|
38
|
+
return data;
|
39
|
+
} catch (error) {
|
40
|
+
console.error(`mirai-js: error ${locationStr}`);
|
41
|
+
errorHandler(error);
|
42
|
+
}
|
43
|
+
};
|
@@ -0,0 +1,43 @@
|
|
1
|
+
const { errCodeMap } = require('../../util/errCode');
|
2
|
+
const axios = require('axios');
|
3
|
+
const { URL } = require('../../polyfill/URL');
|
4
|
+
const errorHandler = require('../../util/errorHandler');
|
5
|
+
const path = require('path');
|
6
|
+
const locationStr = `core.${path.basename(__filename, path.extname(__filename))}`;
|
7
|
+
|
8
|
+
/**
|
9
|
+
* @description 发布群公告
|
10
|
+
* @param {string} baseUrl mirai-api-http server 的地址
|
11
|
+
* @param {string} sessionKey 会话标识
|
12
|
+
* @param {number} target 群号
|
13
|
+
* @param {string} content 公告内容
|
14
|
+
* @param {boolean} pinned 是否置顶
|
15
|
+
* @returns {Object} { code, msg }
|
16
|
+
*/
|
17
|
+
module.exports = async ({ baseUrl, sessionKey, target, content, pinned }) => {
|
18
|
+
try {
|
19
|
+
// 拼接 url
|
20
|
+
const url = new URL('/anno/publish', baseUrl).toString();
|
21
|
+
|
22
|
+
// 请求
|
23
|
+
const responseData = await axios.post(url, {
|
24
|
+
sessionKey, target, content, pinned
|
25
|
+
});
|
26
|
+
try {
|
27
|
+
var {
|
28
|
+
data: { msg: message, code }
|
29
|
+
} = responseData;
|
30
|
+
} catch (error) {
|
31
|
+
throw new Error(('请求返回格式出错,请检查 mirai-console'));
|
32
|
+
}
|
33
|
+
// 抛出 mirai 的异常,到 catch 中处理后再抛出
|
34
|
+
if (code in errCodeMap) {
|
35
|
+
throw new Error(message);
|
36
|
+
}
|
37
|
+
return { message, code };
|
38
|
+
} catch (error) {
|
39
|
+
console.error(`mirai-js: error ${locationStr}`);
|
40
|
+
errorHandler(error);
|
41
|
+
}
|
42
|
+
|
43
|
+
};
|
package/src/core/auth.js
CHANGED
@@ -1,12 +1,9 @@
|
|
1
1
|
const { errCodeMap } = require('../util/errCode');
|
2
2
|
const axios = require('axios');
|
3
|
-
|
4
|
-
if (!process.browser) {
|
5
|
-
({ URL } = require('url'));
|
6
|
-
} else {
|
7
|
-
URL = window.URL;
|
8
|
-
}
|
3
|
+
const { URL } = require('../polyfill/URL');
|
9
4
|
const errorHandler = require('../util/errorHandler');
|
5
|
+
const path = require('path');
|
6
|
+
const locationStr = `core.${path.basename(__filename, path.extname(__filename))}`;
|
10
7
|
|
11
8
|
/**
|
12
9
|
*
|
@@ -27,7 +24,7 @@ module.exports = async ({ baseUrl, verifyKey }) => {
|
|
27
24
|
data: { msg: message, code, session: sessionKey },
|
28
25
|
} = responseData;
|
29
26
|
} catch (error) {
|
30
|
-
throw new Error('
|
27
|
+
throw new Error(('请求返回格式出错,请检查 mirai-console'));
|
31
28
|
}
|
32
29
|
|
33
30
|
// 抛出 mirai 的异常,到 catch 中处理后再抛出
|
@@ -36,6 +33,7 @@ module.exports = async ({ baseUrl, verifyKey }) => {
|
|
36
33
|
}
|
37
34
|
return sessionKey;
|
38
35
|
} catch (error) {
|
36
|
+
console.error(`mirai-js: error ${locationStr}`);
|
39
37
|
errorHandler(error);
|
40
38
|
}
|
41
39
|
};
|
@@ -0,0 +1,44 @@
|
|
1
|
+
const { errCodeMap } = require('../../util/errCode');
|
2
|
+
const axios = require('axios');
|
3
|
+
const { URL } = require('../../polyfill/URL');
|
4
|
+
const errorHandler = require('../../util/errorHandler');
|
5
|
+
const path = require('path');
|
6
|
+
const locationStr = `core.${path.basename(__filename, path.extname(__filename))}`;
|
7
|
+
|
8
|
+
/**
|
9
|
+
* @description 删除群文件
|
10
|
+
* @param {string} baseUrl mirai-api-http server 的地址
|
11
|
+
* @param {string} sessionKey 会话标识
|
12
|
+
* @param {string} id 文件夹id, 空串为根目录
|
13
|
+
* @param {string} path 文件夹路径, 文件夹允许重名, 不保证准确, 准确定位使用 id
|
14
|
+
* @param {number} group 群号
|
15
|
+
* @returns {Object} 结构 { message, code }
|
16
|
+
*/
|
17
|
+
module.exports = async ({ baseUrl, sessionKey, id, path, group }) => {
|
18
|
+
try {
|
19
|
+
// 拼接 url
|
20
|
+
const url = new URL('/file/delete', baseUrl).toString();
|
21
|
+
|
22
|
+
// 请求
|
23
|
+
const responseData = await axios.post(url, {
|
24
|
+
sessionKey, id, path, target: group, group,
|
25
|
+
});
|
26
|
+
|
27
|
+
try {
|
28
|
+
var {
|
29
|
+
data: { msg: message, code }
|
30
|
+
} = responseData;
|
31
|
+
} catch (error) {
|
32
|
+
throw new Error(('请求返回格式出错,请检查 mirai-console'));
|
33
|
+
}
|
34
|
+
// 抛出 mirai 的异常,到 catch 中处理后再抛出
|
35
|
+
if (code in errCodeMap) {
|
36
|
+
throw new Error(message);
|
37
|
+
}
|
38
|
+
return { message, code };
|
39
|
+
} catch (error) {
|
40
|
+
console.error(`mirai-js: error ${locationStr}`);
|
41
|
+
errorHandler(error);
|
42
|
+
}
|
43
|
+
|
44
|
+
};
|
@@ -0,0 +1,45 @@
|
|
1
|
+
const { errCodeMap } = require('../../util/errCode');
|
2
|
+
const axios = require('axios').default;
|
3
|
+
const { URL } = require('../../polyfill/URL');
|
4
|
+
const errorHandler = require('../../util/errorHandler');
|
5
|
+
const path = require('path');
|
6
|
+
const locationStr = `core.${path.basename(__filename, path.extname(__filename))}`;
|
7
|
+
|
8
|
+
/**
|
9
|
+
* @description 获取群文件详细信息
|
10
|
+
* @param {string} baseUrl mirai-api-http server 的地址
|
11
|
+
* @param {string} sessionKey 会话标识
|
12
|
+
* @param {string} id 文件夹id, 空串为根目录
|
13
|
+
* @param {string} path 文件夹路径, 文件夹允许重名, 不保证准确, 准确定位使用 id
|
14
|
+
* @param {number} group 群号
|
15
|
+
* @param {boolean} withDownloadInfo 是否携带下载信息,额外请求,无必要不要携带
|
16
|
+
* @returns {Object}
|
17
|
+
* 结构 { id, name, path, parent, contact, isFile, isDirectory, downloadInfo }
|
18
|
+
*/
|
19
|
+
module.exports = async ({ baseUrl, sessionKey, id, path, group/*, qq 字段保留 */, withDownloadInfo }) => {
|
20
|
+
try {
|
21
|
+
// 拼接 url
|
22
|
+
const url = new URL('/file/info', baseUrl).toString();
|
23
|
+
|
24
|
+
// 请求
|
25
|
+
const responseData = await axios.get(url, {
|
26
|
+
params: {
|
27
|
+
sessionKey, id, path, target: group, group, withDownloadInfo
|
28
|
+
}
|
29
|
+
});
|
30
|
+
try {
|
31
|
+
var { data: { msg: message, code, data } } = responseData;
|
32
|
+
} catch (error) {
|
33
|
+
throw new Error(('请求返回格式出错,请检查 mirai-console'));
|
34
|
+
}
|
35
|
+
|
36
|
+
// 抛出 mirai 的异常,到 catch 中处理后再抛出
|
37
|
+
if (code in errCodeMap) {
|
38
|
+
throw new Error(message);
|
39
|
+
}
|
40
|
+
return data;
|
41
|
+
} catch (error) {
|
42
|
+
console.error(`mirai-js: error ${locationStr}`);
|
43
|
+
errorHandler(error);
|
44
|
+
}
|
45
|
+
};
|
@@ -0,0 +1,46 @@
|
|
1
|
+
const { errCodeMap } = require('../../util/errCode');
|
2
|
+
const axios = require('axios').default;
|
3
|
+
const { URL } = require('../../polyfill/URL');
|
4
|
+
const errorHandler = require('../../util/errorHandler');
|
5
|
+
const path = require('path');
|
6
|
+
const locationStr = `core.${path.basename(__filename, path.extname(__filename))}`;
|
7
|
+
|
8
|
+
/**
|
9
|
+
* @description 获取群文件列表
|
10
|
+
* @param {string} baseUrl mirai-api-http server 的地址
|
11
|
+
* @param {string} sessionKey 会话标识
|
12
|
+
* @param {string} id 文件夹id, 空串为根目录
|
13
|
+
* @param {string} path 文件夹路径, 文件夹允许重名, 不保证准确, 准确定位使用 id
|
14
|
+
* @param {number} group 群号
|
15
|
+
* @param {boolern} withDownloadInfo 是否携带下载信息,额外请求,无必要不要携带
|
16
|
+
* @param {number} offset 分页偏移
|
17
|
+
* @param {number} size 分页大小
|
18
|
+
* @returns {Object[]} 结构 array[...{ id, name, path, parent, contact, isFile, isDirectory, downloadInfo }]
|
19
|
+
*/
|
20
|
+
module.exports = async ({ baseUrl, sessionKey, id, path, group/*, qq 字段保留 */, withDownloadInfo, offset, size }) => {
|
21
|
+
try {
|
22
|
+
// 拼接 url
|
23
|
+
const url = new URL('/file/list', baseUrl).toString();
|
24
|
+
|
25
|
+
// 请求
|
26
|
+
const responseData = await axios.get(url, {
|
27
|
+
params: {
|
28
|
+
sessionKey, id, path, target: group, group, withDownloadInfo, offset, size
|
29
|
+
}
|
30
|
+
});
|
31
|
+
try {
|
32
|
+
var { data: { msg: message, code, data } } = responseData;
|
33
|
+
} catch (error) {
|
34
|
+
throw new Error(('请求返回格式出错,请检查 mirai-console'));
|
35
|
+
}
|
36
|
+
|
37
|
+
// 抛出 mirai 的异常,到 catch 中处理后再抛出
|
38
|
+
if (code in errCodeMap) {
|
39
|
+
throw new Error(message);
|
40
|
+
}
|
41
|
+
return data;
|
42
|
+
} catch (error) {
|
43
|
+
console.error(`mirai-js: error ${locationStr}`);
|
44
|
+
errorHandler(error);
|
45
|
+
}
|
46
|
+
};
|
@@ -0,0 +1,44 @@
|
|
1
|
+
const { errCodeMap } = require('../../util/errCode');
|
2
|
+
const axios = require('axios');
|
3
|
+
const { URL } = require('../../polyfill/URL');
|
4
|
+
const errorHandler = require('../../util/errorHandler');
|
5
|
+
const path = require('path');
|
6
|
+
const locationStr = `core.${path.basename(__filename, path.extname(__filename))}`;
|
7
|
+
|
8
|
+
/**
|
9
|
+
* @description 新建群文件夹
|
10
|
+
* @param {string} baseUrl mirai-api-http server 的地址
|
11
|
+
* @param {string} sessionKey 会话标识
|
12
|
+
* @param {string} id 文件夹id, 空串为根目录
|
13
|
+
* @param {string} path 文件夹路径, 文件夹允许重名, 不保证准确, 准确定位使用 id
|
14
|
+
* @param {number} group 群号
|
15
|
+
* @param {boolern} withDownloadInfo 是否携带下载信息,额外请求,无必要不要携带
|
16
|
+
* @returns {Object} 结构 { id, name, path, parent, contact, isFile, isDirectory, downloadInfo }
|
17
|
+
*/
|
18
|
+
module.exports = async ({ baseUrl, sessionKey, id, rename, path, group, withDownloadInfo }) => {
|
19
|
+
try {
|
20
|
+
// 拼接 url
|
21
|
+
const url = new URL('/file/mkdir', baseUrl).toString();
|
22
|
+
|
23
|
+
// 请求
|
24
|
+
const responseData = await axios.post(url, {
|
25
|
+
sessionKey, id, rename, path, group, withDownloadInfo
|
26
|
+
});
|
27
|
+
|
28
|
+
try {
|
29
|
+
var {
|
30
|
+
data: { msg: message, code, data }
|
31
|
+
} = responseData;
|
32
|
+
} catch (error) {
|
33
|
+
throw new Error(('请求返回格式出错,请检查 mirai-console'));
|
34
|
+
}
|
35
|
+
// 抛出 mirai 的异常,到 catch 中处理后再抛出
|
36
|
+
if (code in errCodeMap) {
|
37
|
+
throw new Error(message);
|
38
|
+
}
|
39
|
+
return data;
|
40
|
+
} catch (error) {
|
41
|
+
console.error(`mirai-js: error ${locationStr}`);
|
42
|
+
errorHandler(error);
|
43
|
+
}
|
44
|
+
};
|
@@ -0,0 +1,46 @@
|
|
1
|
+
const { errCodeMap } = require('../../util/errCode');
|
2
|
+
const axios = require('axios');
|
3
|
+
const { URL } = require('../../polyfill/URL');
|
4
|
+
const errorHandler = require('../../util/errorHandler');
|
5
|
+
const path = require('path');
|
6
|
+
const locationStr = `core.${path.basename(__filename, path.extname(__filename))}`;
|
7
|
+
|
8
|
+
/**
|
9
|
+
* @description 移动群文件
|
10
|
+
* @param {string} baseUrl mirai-api-http server 的地址
|
11
|
+
* @param {string} sessionKey 会话标识
|
12
|
+
* @param {string} id 文件夹id, 空串为根目录
|
13
|
+
* @param {string} path 文件夹路径, 文件夹允许重名, 不保证准确, 准确定位使用 id
|
14
|
+
* @param {number} group 群号
|
15
|
+
* @param {string} moveTo 移动目标文件夹id
|
16
|
+
* @param {string} moveToPath 移动目标文件夹path
|
17
|
+
* @returns {Object} 结构 { message, code }
|
18
|
+
*/
|
19
|
+
module.exports = async ({ baseUrl, sessionKey, id, path, group, moveTo, moveToPath }) => {
|
20
|
+
try {
|
21
|
+
// 拼接 url
|
22
|
+
const url = new URL('/file/move', baseUrl).toString();
|
23
|
+
|
24
|
+
// 请求
|
25
|
+
const responseData = await axios.post(url, {
|
26
|
+
sessionKey, id, path, target: group, group, moveTo, moveToPath
|
27
|
+
});
|
28
|
+
|
29
|
+
try {
|
30
|
+
var {
|
31
|
+
data: { msg: message, code }
|
32
|
+
} = responseData;
|
33
|
+
} catch (error) {
|
34
|
+
throw new Error(('请求返回格式出错,请检查 mirai-console'));
|
35
|
+
}
|
36
|
+
// 抛出 mirai 的异常,到 catch 中处理后再抛出
|
37
|
+
if (code in errCodeMap) {
|
38
|
+
throw new Error(message);
|
39
|
+
}
|
40
|
+
return { message, code };
|
41
|
+
} catch (error) {
|
42
|
+
console.error(`mirai-js: error ${locationStr}`);
|
43
|
+
errorHandler(error);
|
44
|
+
}
|
45
|
+
|
46
|
+
};
|