mirai-js 2.3.0 → 2.4.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/README.md +17 -283
- package/demo.js +13 -17
- package/dist/browser/mirai-js.js +1 -1
- package/dist/node/BaseType.d.ts +3 -0
- package/dist/node/Bot.d.ts +79 -4
- package/dist/node/Bot.js +171 -4
- 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 +3 -9
- package/dist/node/core/fs/deleteGroupFile.js +3 -9
- package/dist/node/core/fs/getGroupFileInfo.js +3 -9
- package/dist/node/core/fs/getGroupFileList.js +3 -9
- package/dist/node/core/fs/makeGroupDir.js +3 -9
- package/dist/node/core/fs/moveGroupFile.js +3 -9
- package/dist/node/core/fs/renameGroupFile.js +3 -9
- package/dist/node/core/fs/uploadGroupFIle.js +3 -9
- package/dist/node/core/getFriendList.js +3 -9
- package/dist/node/core/getGroupConfig.js +3 -9
- package/dist/node/core/getGroupList.js +3 -9
- package/dist/node/core/getMemberInfo.js +7 -17
- package/dist/node/core/getMemberList.js +3 -9
- package/dist/node/core/getSessionConfig.js +3 -9
- package/dist/node/core/getUserProfile.js +78 -0
- package/dist/node/core/mute.js +3 -9
- package/dist/node/core/muteAll.js +3 -9
- package/dist/node/core/quitGroup.js +3 -9
- package/dist/node/core/recall.js +3 -9
- package/dist/node/core/releaseSession.js +3 -9
- package/dist/node/core/removeFriend.js +3 -9
- package/dist/node/core/removeMember.js +3 -9
- package/dist/node/core/responseBotInvitedJoinGroupRequest.js +3 -9
- package/dist/node/core/responseFirendRequest.js +3 -9
- package/dist/node/core/responseMemberJoinRequest.js +3 -9
- package/dist/node/core/sendCommand.js +3 -9
- package/dist/node/core/sendFirendMessage.js +3 -9
- package/dist/node/core/sendGroupMessage.js +3 -9
- package/dist/node/core/sendNudge.js +3 -9
- package/dist/node/core/sendTempMessage.js +3 -9
- package/dist/node/core/setEssence.js +3 -9
- package/dist/node/core/setGroupConfig.js +3 -9
- package/dist/node/core/setMemberAdmin.js +3 -9
- package/dist/node/core/setMemberInfo.js +3 -9
- package/dist/node/core/setSessionConfig.js +3 -9
- package/dist/node/core/startListeningBrowser.js +3 -8
- package/dist/node/core/startListeningNode.js +3 -9
- package/dist/node/core/unmute.js +3 -9
- package/dist/node/core/unmuteAll.js +3 -9
- package/dist/node/core/uploadImage.js +3 -9
- package/dist/node/core/uploadVoice.js +3 -9
- package/dist/node/core/verify.js +3 -9
- package/dist/node/polyfill/URL.js +5 -0
- package/dist/node/polyfill/wsListener.js +6 -0
- package/package.json +1 -1
- package/src/BaseType.d.ts +3 -0
- package/src/Bot.d.ts +79 -4
- package/src/Bot.js +107 -3
- 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 +1 -6
- package/src/core/fs/deleteGroupFile.js +1 -6
- package/src/core/fs/getGroupFileInfo.js +1 -6
- package/src/core/fs/getGroupFileList.js +1 -6
- package/src/core/fs/makeGroupDir.js +1 -6
- package/src/core/fs/moveGroupFile.js +1 -6
- package/src/core/fs/renameGroupFile.js +1 -6
- package/src/core/fs/uploadGroupFIle.js +1 -6
- package/src/core/getFriendList.js +1 -6
- package/src/core/getGroupConfig.js +1 -6
- package/src/core/getGroupList.js +1 -6
- package/src/core/getMemberInfo.js +4 -9
- package/src/core/getMemberList.js +1 -6
- package/src/core/getSessionConfig.js +1 -6
- package/src/core/getUserProfile.js +39 -0
- package/src/core/mute.js +1 -6
- package/src/core/muteAll.js +1 -6
- package/src/core/quitGroup.js +1 -6
- package/src/core/recall.js +1 -6
- package/src/core/releaseSession.js +1 -6
- package/src/core/removeFriend.js +1 -6
- package/src/core/removeMember.js +1 -6
- package/src/core/responseBotInvitedJoinGroupRequest.js +1 -6
- package/src/core/responseFirendRequest.js +1 -6
- package/src/core/responseMemberJoinRequest.js +1 -6
- package/src/core/sendCommand.js +1 -6
- package/src/core/sendFirendMessage.js +1 -6
- package/src/core/sendGroupMessage.js +1 -6
- package/src/core/sendNudge.js +1 -6
- package/src/core/sendTempMessage.js +1 -6
- package/src/core/setEssence.js +1 -6
- package/src/core/setGroupConfig.js +1 -6
- package/src/core/setMemberAdmin.js +1 -6
- package/src/core/setMemberInfo.js +1 -6
- package/src/core/setSessionConfig.js +1 -6
- package/src/core/startListeningBrowser.js +1 -6
- package/src/core/startListeningNode.js +1 -6
- package/src/core/unmute.js +1 -6
- package/src/core/unmuteAll.js +1 -6
- package/src/core/uploadImage.js +1 -6
- package/src/core/uploadVoice.js +1 -6
- package/src/core/verify.js +1 -6
- package/src/polyfill/URL.js +3 -0
- package/src/polyfill/wsListener.js +4 -0
package/src/BaseType.d.ts
CHANGED
package/src/Bot.d.ts
CHANGED
@@ -2,8 +2,8 @@ import {
|
|
2
2
|
// 图片 id 语音 id 消息 id
|
3
3
|
ImageId, VoiceId, MessageId,
|
4
4
|
|
5
|
-
// 事件类型 群成员权限
|
6
|
-
EventType, GroupPermission,
|
5
|
+
// 事件类型 群成员权限 性别
|
6
|
+
EventType, GroupPermission, SEX,
|
7
7
|
|
8
8
|
// 接口 原始消息类型 事件处理器类型
|
9
9
|
MessageChainGetable, BotConfigGetable, MessageType, Processor
|
@@ -173,7 +173,13 @@ export class Bot implements BotConfigGetable {
|
|
173
173
|
* @param group 必选,群成员所在群号
|
174
174
|
* @param qq 必选,群成员的 qq 号
|
175
175
|
*/
|
176
|
-
getMemberInfo(): Promise<Bot.MemberDetails>;
|
176
|
+
getMemberInfo({ group, qq }: Bot.GetMemberInfoOptions): Promise<Bot.MemberDetails>;
|
177
|
+
|
178
|
+
/**
|
179
|
+
* @description 获取群成员信息
|
180
|
+
* @param qq 必选,用户的 qq 号
|
181
|
+
*/
|
182
|
+
getUserProfile({ qq }: Bot.GetUserProfileOptions): Promise<Bot.UserProfile>;
|
177
183
|
|
178
184
|
/**
|
179
185
|
* @description 设置群成员信息
|
@@ -185,6 +191,28 @@ export class Bot implements BotConfigGetable {
|
|
185
191
|
*/
|
186
192
|
setMemberInfo({ group, qq, name, title, permission }: Bot.SetMemberInfoOptions): Promise<void>;
|
187
193
|
|
194
|
+
/**
|
195
|
+
* @description 获取群公告列表迭代器
|
196
|
+
* @param group 必选,群号
|
197
|
+
* @returns 迭代器
|
198
|
+
*/
|
199
|
+
getAnnoIter({ group }: Bot.GetAnnoIterOptions): AsyncGenerator<Bot.AnnoInfo>;
|
200
|
+
|
201
|
+
/**
|
202
|
+
* @description 发布群公告
|
203
|
+
* @param group 必选,群号
|
204
|
+
* @param content 必选,公告内容
|
205
|
+
*/
|
206
|
+
async publishAnno({ group, content, pinned }: Bot.PublishAnnoOptions): Promise<void>;
|
207
|
+
|
208
|
+
/**
|
209
|
+
* @description 删除群公告
|
210
|
+
* @param {number} group 必选,群号
|
211
|
+
* @param {string} fid 必选,公告 id
|
212
|
+
* @reaturns {void}
|
213
|
+
*/
|
214
|
+
async deleteAnno({ group, fid }: Bot.DeleteAnnoOptions): Promise<void>;
|
215
|
+
|
188
216
|
/**
|
189
217
|
* @description 禁言群成员
|
190
218
|
* @param group 必选,欲禁言成员所在群号
|
@@ -370,8 +398,18 @@ declare namespace Bot {
|
|
370
398
|
permission: GroupPermission;
|
371
399
|
}
|
372
400
|
|
401
|
+
interface GetMemberInfoOptions {
|
402
|
+
group: number;
|
403
|
+
qq: number;
|
404
|
+
}
|
405
|
+
|
373
406
|
interface MemberDetails {
|
374
|
-
|
407
|
+
id: number;
|
408
|
+
joinTimestamp: number;
|
409
|
+
lastSpeakTimestamp: number;
|
410
|
+
memberName: string;
|
411
|
+
nuteTimeRemaining: number;
|
412
|
+
permission: GroupPermission;
|
375
413
|
title: string;
|
376
414
|
}
|
377
415
|
|
@@ -379,6 +417,19 @@ declare namespace Bot {
|
|
379
417
|
group: number;
|
380
418
|
}
|
381
419
|
|
420
|
+
interface GetUserProfileOptions {
|
421
|
+
qq: number;
|
422
|
+
}
|
423
|
+
|
424
|
+
interface UserProfile {
|
425
|
+
nickname: string;
|
426
|
+
email: string;
|
427
|
+
age: number;
|
428
|
+
level: number;
|
429
|
+
sign: string;
|
430
|
+
sex: SEX;
|
431
|
+
}
|
432
|
+
|
382
433
|
interface SetMemberInfoOptions {
|
383
434
|
group: number;
|
384
435
|
qq: number;
|
@@ -387,6 +438,30 @@ declare namespace Bot {
|
|
387
438
|
permission?: GroupPermission
|
388
439
|
}
|
389
440
|
|
441
|
+
interface GetAnnoIterOptions {
|
442
|
+
gourp: number;
|
443
|
+
}
|
444
|
+
|
445
|
+
interface PublishAnnoOptions {
|
446
|
+
group: number;
|
447
|
+
content: string;
|
448
|
+
pinned: boolean;
|
449
|
+
}
|
450
|
+
|
451
|
+
interface DeleteAnnoOptions {
|
452
|
+
group: number;
|
453
|
+
fid: string;
|
454
|
+
}
|
455
|
+
interface AnnoInfo {
|
456
|
+
group: { id: number; name: string; permission: GroupPermission; };
|
457
|
+
content: string;
|
458
|
+
senderId: number;
|
459
|
+
fid: string;
|
460
|
+
allConfirmed: boolean;
|
461
|
+
confirmedMembersCount: number;
|
462
|
+
publicationTime: number;
|
463
|
+
}
|
464
|
+
|
390
465
|
interface MuteOptions {
|
391
466
|
group: number;
|
392
467
|
qq: number;
|
package/src/Bot.js
CHANGED
@@ -15,8 +15,12 @@ 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');
|
19
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');
|
20
24
|
const _recall = require('./core/recall');
|
21
25
|
const _mute = require('./core/mute');
|
22
26
|
const _muteAll = require('./core/muteAll');
|
@@ -28,8 +32,7 @@ const _quitGroup = require('./core/quitGroup');
|
|
28
32
|
const _getGroupConfig = require('./core/getGroupConfig');
|
29
33
|
const _setGroupConfig = require('./core/setGroupConfig');
|
30
34
|
const _setEssence = require('./core/setEssence');
|
31
|
-
const _startListening
|
32
|
-
const _stopListening = process.browser ? require('./core/stopListeningBrowser') : require('./core/stopListeningNode');
|
35
|
+
const { wsStartListening: _startListening, wsStopListening: _stopListening } = require('./polyfill/wsListener');
|
33
36
|
|
34
37
|
// 其他
|
35
38
|
const random = require('./util/random')(0, 2E16);
|
@@ -693,7 +696,7 @@ class Bot extends BotConfigGetable {
|
|
693
696
|
* @description 获取群成员信息
|
694
697
|
* @param {number} group 必选,群成员所在群号
|
695
698
|
* @param {number} qq 必选,群成员的 qq 号
|
696
|
-
* @returns {Object
|
699
|
+
* @returns {Object}
|
697
700
|
*/
|
698
701
|
async getMemberInfo({ group, qq }) {
|
699
702
|
// 检查对象状态
|
@@ -721,6 +724,26 @@ class Bot extends BotConfigGetable {
|
|
721
724
|
return memberInfo;
|
722
725
|
}
|
723
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
|
+
|
724
747
|
/**
|
725
748
|
* @description 设置群成员信息
|
726
749
|
* @param {number} group 必选,群成员所在群号
|
@@ -767,6 +790,87 @@ class Bot extends BotConfigGetable {
|
|
767
790
|
}
|
768
791
|
}
|
769
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
|
+
}
|
808
|
+
|
809
|
+
// 获取列表
|
810
|
+
const { baseUrl, sessionKey } = this.config;
|
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 });
|
872
|
+
}
|
873
|
+
|
770
874
|
/**
|
771
875
|
* @description 禁言群成员
|
772
876
|
* @param {number} group 必选,欲禁言成员所在群号
|
@@ -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,11 +1,6 @@
|
|
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');
|
10
5
|
const path = require('path');
|
11
6
|
const locationStr = `core.${path.basename(__filename, path.extname(__filename))}`;
|
@@ -1,11 +1,6 @@
|
|
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');
|
10
5
|
const path = require('path');
|
11
6
|
const locationStr = `core.${path.basename(__filename, path.extname(__filename))}`;
|
@@ -1,11 +1,6 @@
|
|
1
1
|
const { errCodeMap } = require('../../util/errCode');
|
2
2
|
const axios = require('axios').default;
|
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');
|
10
5
|
const path = require('path');
|
11
6
|
const locationStr = `core.${path.basename(__filename, path.extname(__filename))}`;
|
@@ -1,11 +1,6 @@
|
|
1
1
|
const { errCodeMap } = require('../../util/errCode');
|
2
2
|
const axios = require('axios').default;
|
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');
|
10
5
|
const path = require('path');
|
11
6
|
const locationStr = `core.${path.basename(__filename, path.extname(__filename))}`;
|
@@ -1,11 +1,6 @@
|
|
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');
|
10
5
|
const path = require('path');
|
11
6
|
const locationStr = `core.${path.basename(__filename, path.extname(__filename))}`;
|
@@ -1,11 +1,6 @@
|
|
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');
|
10
5
|
const path = require('path');
|
11
6
|
const locationStr = `core.${path.basename(__filename, path.extname(__filename))}`;
|
@@ -1,11 +1,6 @@
|
|
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');
|
10
5
|
const path = require('path');
|
11
6
|
const locationStr = `core.${path.basename(__filename, path.extname(__filename))}`;
|
@@ -1,11 +1,6 @@
|
|
1
1
|
const { errCodeMap } = require('../../util/errCode');
|
2
2
|
const axios = require('axios').default;
|
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');
|
10
5
|
const path = require('path');
|
11
6
|
const locationStr = `core.${path.basename(__filename, path.extname(__filename))}`;
|
@@ -1,11 +1,6 @@
|
|
1
1
|
const { errCodeMap } = require('../util/errCode');
|
2
2
|
const axios = require('axios').default;
|
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');
|
10
5
|
const path = require('path');
|
11
6
|
const locationStr = `core.${path.basename(__filename, path.extname(__filename))}`;
|
@@ -1,11 +1,6 @@
|
|
1
1
|
const { errCodeMap } = require('../util/errCode');
|
2
2
|
const axios = require('axios').default;
|
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');
|
10
5
|
const path = require('path');
|
11
6
|
const locationStr = `core.${path.basename(__filename, path.extname(__filename))}`;
|
package/src/core/getGroupList.js
CHANGED
@@ -1,11 +1,6 @@
|
|
1
1
|
const { errCodeMap } = require('../util/errCode');
|
2
2
|
const axios = require('axios').default;
|
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');
|
10
5
|
const path = require('path');
|
11
6
|
const locationStr = `core.${path.basename(__filename, path.extname(__filename))}`;
|
@@ -1,11 +1,6 @@
|
|
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');
|
10
5
|
const path = require('path');
|
11
6
|
const locationStr = `core.${path.basename(__filename, path.extname(__filename))}`;
|
@@ -16,7 +11,7 @@ const locationStr = `core.${path.basename(__filename, path.extname(__filename))}
|
|
16
11
|
* @param {string} sessionKey 会话标识
|
17
12
|
* @param {number} target 群成员所在群号
|
18
13
|
* @param {number} memberId 群成员的 qq 号
|
19
|
-
* @returns {Object}
|
14
|
+
* @returns {Object}
|
20
15
|
*/
|
21
16
|
module.exports = async ({ baseUrl, sessionKey, target, memberId }) => {
|
22
17
|
try {
|
@@ -27,7 +22,7 @@ module.exports = async ({ baseUrl, sessionKey, target, memberId }) => {
|
|
27
22
|
const responseData = await axios.get(url, { params: { sessionKey, target, memberId } });
|
28
23
|
try {
|
29
24
|
var {
|
30
|
-
data: { msg: message, code
|
25
|
+
data, data: { msg: message, code }
|
31
26
|
} = responseData;
|
32
27
|
} catch (error) {
|
33
28
|
throw new Error(('请求返回格式出错,请检查 mirai-console'));
|
@@ -36,7 +31,7 @@ module.exports = async ({ baseUrl, sessionKey, target, memberId }) => {
|
|
36
31
|
if (code in errCodeMap) {
|
37
32
|
throw new Error(message);
|
38
33
|
}
|
39
|
-
return
|
34
|
+
return data;
|
40
35
|
} catch (error) {
|
41
36
|
console.error(`mirai-js: error ${locationStr}`);
|
42
37
|
errorHandler(error);
|
@@ -1,11 +1,6 @@
|
|
1
1
|
const { errCodeMap } = require('../util/errCode');
|
2
2
|
const axios = require('axios').default;
|
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');
|
10
5
|
const path = require('path');
|
11
6
|
const locationStr = `core.${path.basename(__filename, path.extname(__filename))}`;
|
@@ -1,11 +1,6 @@
|
|
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');
|
10
5
|
const path = require('path');
|
11
6
|
const locationStr = `core.${path.basename(__filename, path.extname(__filename))}`;
|
@@ -0,0 +1,39 @@
|
|
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 qq 号
|
13
|
+
* @returns {Object} 结构 { nickname, email, age, level, sign, sex }
|
14
|
+
*/
|
15
|
+
module.exports = async ({ baseUrl, sessionKey, target, memberId }) => {
|
16
|
+
try {
|
17
|
+
// 拼接 url
|
18
|
+
const url = new URL('/userProfile', baseUrl).toString();
|
19
|
+
|
20
|
+
// 请求
|
21
|
+
const responseData = await axios.get(url, { params: { sessionKey, target, memberId } });
|
22
|
+
try {
|
23
|
+
var {
|
24
|
+
data: { msg: message, code, nickname, email, age, level, sign, sex }
|
25
|
+
} = responseData;
|
26
|
+
} catch (error) {
|
27
|
+
throw new Error('请求返回格式出错,请检查 mirai-console');
|
28
|
+
}
|
29
|
+
// 抛出 mirai 的异常,到 catch 中处理后再抛出
|
30
|
+
if (code in errCodeMap) {
|
31
|
+
throw new Error(message);
|
32
|
+
}
|
33
|
+
return { nickname, email, age, level, sign, sex };
|
34
|
+
} catch (error) {
|
35
|
+
console.error(`mirai-js: error ${locationStr}`);
|
36
|
+
errorHandler(error);
|
37
|
+
}
|
38
|
+
|
39
|
+
};
|