mirai-js 2.2.0 → 2.3.0
Sign up to get free protection for your applications and to get access to all the features.
- package/.github/FUNDING.yml +1 -1
- package/demo.html +1 -1
- package/demo.js +19 -73
- package/dist/browser/mirai-js.js +1 -1
- package/dist/node/Bot.d.ts +16 -4
- package/dist/node/Bot.js +67 -11
- package/dist/node/FileManager.js +15 -6
- 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 +6 -2
- 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 +6 -2
- 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 +5 -1
- 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/package.json +2 -2
- package/src/Bot.d.ts +16 -4
- package/src/Bot.js +48 -7
- package/src/FileManager.js +10 -6
- 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 +4 -1
- 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 +4 -1
- 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 +3 -0
- 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
@@ -7,6 +7,8 @@ if (!process.browser) {
|
|
7
7
|
URL = window.URL;
|
8
8
|
}
|
9
9
|
const errorHandler = require('../util/errorHandler');
|
10
|
+
const path = require('path');
|
11
|
+
const locationStr = `core.${path.basename(__filename, path.extname(__filename))}`;
|
10
12
|
|
11
13
|
/**
|
12
14
|
* @description 向 qq 群发送消息
|
@@ -31,7 +33,7 @@ module.exports = async ({ baseUrl, sessionKey, target, quote, messageChain }) =>
|
|
31
33
|
data: { msg: message, code, messageId }
|
32
34
|
} = responseData;
|
33
35
|
} catch (error) {
|
34
|
-
throw new Error('
|
36
|
+
throw new Error(('请求返回格式出错,请检查 mirai-console'));
|
35
37
|
}
|
36
38
|
// 抛出 mirai 的异常,到 catch 中处理后再抛出
|
37
39
|
if (code in errCodeMap) {
|
@@ -39,6 +41,7 @@ module.exports = async ({ baseUrl, sessionKey, target, quote, messageChain }) =>
|
|
39
41
|
}
|
40
42
|
return messageId;
|
41
43
|
} catch (error) {
|
44
|
+
console.error(`mirai-js: error ${locationStr}`);
|
42
45
|
errorHandler(error);
|
43
46
|
}
|
44
47
|
};
|
package/src/core/sendNudge.js
CHANGED
@@ -7,6 +7,8 @@ if (!process.browser) {
|
|
7
7
|
URL = window.URL;
|
8
8
|
}
|
9
9
|
const errorHandler = require('../util/errorHandler');
|
10
|
+
const path = require('path');
|
11
|
+
const locationStr = `core.${path.basename(__filename, path.extname(__filename))}`;
|
10
12
|
|
11
13
|
/**
|
12
14
|
* @description 发送戳一戳消息
|
@@ -31,7 +33,7 @@ module.exports = async ({ baseUrl, sessionKey, target, subject, kind }) => {
|
|
31
33
|
data: { msg: message, code }
|
32
34
|
} = responseData;
|
33
35
|
} catch (error) {
|
34
|
-
throw new Error('
|
36
|
+
throw new Error(('请求返回格式出错,请检查 mirai-console'));
|
35
37
|
}
|
36
38
|
// 抛出 mirai 的异常,到 catch 中处理后再抛出
|
37
39
|
if (code in errCodeMap) {
|
@@ -39,6 +41,7 @@ module.exports = async ({ baseUrl, sessionKey, target, subject, kind }) => {
|
|
39
41
|
}
|
40
42
|
return { message, code };
|
41
43
|
} catch (error) {
|
44
|
+
console.error(`mirai-js: error ${locationStr}`);
|
42
45
|
errorHandler(error);
|
43
46
|
}
|
44
47
|
};
|
@@ -7,6 +7,8 @@ if (!process.browser) {
|
|
7
7
|
URL = window.URL;
|
8
8
|
}
|
9
9
|
const errorHandler = require('../util/errorHandler');
|
10
|
+
const path = require('path');
|
11
|
+
const locationStr = `core.${path.basename(__filename, path.extname(__filename))}`;
|
10
12
|
|
11
13
|
/**
|
12
14
|
* @description 向临时对象发送消息
|
@@ -41,7 +43,7 @@ module.exports = async ({ baseUrl, sessionKey, qq, group, quote, messageChain })
|
|
41
43
|
data: { msg: message, code, messageId }
|
42
44
|
} = responseData;
|
43
45
|
} catch (error) {
|
44
|
-
throw new Error('
|
46
|
+
throw new Error(('请求返回格式出错,请检查 mirai-console'));
|
45
47
|
}
|
46
48
|
|
47
49
|
// 抛出 mirai 的异常,到 catch 中处理后再抛出
|
@@ -50,6 +52,7 @@ module.exports = async ({ baseUrl, sessionKey, qq, group, quote, messageChain })
|
|
50
52
|
}
|
51
53
|
return messageId;
|
52
54
|
} catch (error) {
|
55
|
+
console.error(`mirai-js: error ${locationStr}`);
|
53
56
|
errorHandler(error);
|
54
57
|
}
|
55
58
|
|
package/src/core/setEssence.js
CHANGED
@@ -7,6 +7,8 @@ if (!process.browser) {
|
|
7
7
|
URL = window.URL;
|
8
8
|
}
|
9
9
|
const errorHandler = require('../util/errorHandler');
|
10
|
+
const path = require('path');
|
11
|
+
const locationStr = `core.${path.basename(__filename, path.extname(__filename))}`;
|
10
12
|
|
11
13
|
|
12
14
|
/**
|
@@ -32,7 +34,7 @@ module.exports = async ({
|
|
32
34
|
data: { msg: message, code }
|
33
35
|
} = responseData;
|
34
36
|
} catch (error) {
|
35
|
-
throw new Error('
|
37
|
+
throw new Error(('请求返回格式出错,请检查 mirai-console'));
|
36
38
|
}
|
37
39
|
// 抛出 mirai 的异常,到 catch 中处理后再抛出
|
38
40
|
if (code in errCodeMap) {
|
@@ -40,6 +42,7 @@ module.exports = async ({
|
|
40
42
|
}
|
41
43
|
return { message, code };
|
42
44
|
} catch (error) {
|
45
|
+
console.error(`mirai-js: error ${locationStr}`);
|
43
46
|
errorHandler(error);
|
44
47
|
}
|
45
48
|
};
|
@@ -7,6 +7,8 @@ if (!process.browser) {
|
|
7
7
|
URL = window.URL;
|
8
8
|
}
|
9
9
|
const errorHandler = require('../util/errorHandler');
|
10
|
+
const path = require('path');
|
11
|
+
const locationStr = `core.${path.basename(__filename, path.extname(__filename))}`;
|
10
12
|
|
11
13
|
|
12
14
|
/**
|
@@ -46,7 +48,7 @@ module.exports = async ({
|
|
46
48
|
data: { msg: message, code }
|
47
49
|
} = responseData;
|
48
50
|
} catch (error) {
|
49
|
-
throw new Error('
|
51
|
+
throw new Error(('请求返回格式出错,请检查 mirai-console'));
|
50
52
|
}
|
51
53
|
// 抛出 mirai 的异常,到 catch 中处理后再抛出
|
52
54
|
if (code in errCodeMap) {
|
@@ -54,6 +56,7 @@ module.exports = async ({
|
|
54
56
|
}
|
55
57
|
return { message, code };
|
56
58
|
} catch (error) {
|
59
|
+
console.error(`mirai-js: error ${locationStr}`);
|
57
60
|
errorHandler(error);
|
58
61
|
}
|
59
62
|
};
|
@@ -0,0 +1,48 @@
|
|
1
|
+
const { errCodeMap } = require('../util/errCode');
|
2
|
+
const axios = require('axios');
|
3
|
+
let URL;
|
4
|
+
if (!process.browser) {
|
5
|
+
({ URL } = require('url'));
|
6
|
+
} else {
|
7
|
+
URL = window.URL;
|
8
|
+
}
|
9
|
+
const errorHandler = require('../util/errorHandler');
|
10
|
+
const path = require('path');
|
11
|
+
const locationStr = `core.${path.basename(__filename, path.extname(__filename))}`;
|
12
|
+
|
13
|
+
/**
|
14
|
+
* @description 设置群成员权限
|
15
|
+
* @param {string} baseUrl mirai-api-http server 的地址
|
16
|
+
* @param {string} sessionKey 会话标识
|
17
|
+
* @param {number} target 群成员所在群号
|
18
|
+
* @param {number} memberId 群成员的 qq 号
|
19
|
+
* @param {string} assign 是否设置为管理员
|
20
|
+
* @returns {Object} 结构 { message, code }
|
21
|
+
*/
|
22
|
+
module.exports = async ({ baseUrl, sessionKey, target, memberId, assign }) => {
|
23
|
+
try {
|
24
|
+
// 拼接 url
|
25
|
+
const url = new URL('/memberAdmin', baseUrl).toString();
|
26
|
+
|
27
|
+
// 请求
|
28
|
+
const responseData = await axios.post(url, {
|
29
|
+
sessionKey, target, memberId, assign
|
30
|
+
});
|
31
|
+
try {
|
32
|
+
var {
|
33
|
+
data: { msg: message, code }
|
34
|
+
} = responseData;
|
35
|
+
} catch (error) {
|
36
|
+
throw new Error(('请求返回格式出错,请检查 mirai-console'));
|
37
|
+
}
|
38
|
+
// 抛出 mirai 的异常,到 catch 中处理后再抛出
|
39
|
+
if (code in errCodeMap) {
|
40
|
+
throw new Error(message);
|
41
|
+
}
|
42
|
+
return { message, code };
|
43
|
+
} catch (error) {
|
44
|
+
console.error(`mirai-js: error ${locationStr}`);
|
45
|
+
errorHandler(error);
|
46
|
+
}
|
47
|
+
|
48
|
+
};
|
@@ -7,6 +7,8 @@ if (!process.browser) {
|
|
7
7
|
URL = window.URL;
|
8
8
|
}
|
9
9
|
const errorHandler = require('../util/errorHandler');
|
10
|
+
const path = require('path');
|
11
|
+
const locationStr = `core.${path.basename(__filename, path.extname(__filename))}`;
|
10
12
|
|
11
13
|
/**
|
12
14
|
* @description 设置群成员信息
|
@@ -35,7 +37,7 @@ module.exports = async ({ baseUrl, sessionKey, target, memberId, name, specialTi
|
|
35
37
|
data: { msg: message, code }
|
36
38
|
} = responseData;
|
37
39
|
} catch (error) {
|
38
|
-
throw new Error('
|
40
|
+
throw new Error(('请求返回格式出错,请检查 mirai-console'));
|
39
41
|
}
|
40
42
|
// 抛出 mirai 的异常,到 catch 中处理后再抛出
|
41
43
|
if (code in errCodeMap) {
|
@@ -43,6 +45,7 @@ module.exports = async ({ baseUrl, sessionKey, target, memberId, name, specialTi
|
|
43
45
|
}
|
44
46
|
return { message, code };
|
45
47
|
} catch (error) {
|
48
|
+
console.error(`mirai-js: error ${locationStr}`);
|
46
49
|
errorHandler(error);
|
47
50
|
}
|
48
51
|
|
@@ -7,6 +7,8 @@ if (!process.browser) {
|
|
7
7
|
URL = window.URL;
|
8
8
|
}
|
9
9
|
const errorHandler = require('../util/errorHandler');
|
10
|
+
const path = require('path');
|
11
|
+
const locationStr = `core.${path.basename(__filename, path.extname(__filename))}`;
|
10
12
|
|
11
13
|
|
12
14
|
/**
|
@@ -29,7 +31,7 @@ module.exports = async ({ baseUrl, sessionKey, cacheSize, enableWebsocket }) =>
|
|
29
31
|
data: { msg: message, code }
|
30
32
|
} = responseData;
|
31
33
|
} catch (error) {
|
32
|
-
throw new Error('
|
34
|
+
throw new Error(('请求返回格式出错,请检查 mirai-console'));
|
33
35
|
}
|
34
36
|
// 抛出 mirai 的异常,到 catch 中处理后再抛出
|
35
37
|
if (code in errCodeMap) {
|
@@ -37,6 +39,7 @@ module.exports = async ({ baseUrl, sessionKey, cacheSize, enableWebsocket }) =>
|
|
37
39
|
}
|
38
40
|
return { message, code };
|
39
41
|
} catch (error) {
|
42
|
+
console.error(`mirai-js: error ${locationStr}`);
|
40
43
|
errorHandler(error);
|
41
44
|
}
|
42
45
|
};
|
@@ -6,6 +6,8 @@ if (!process.browser) {
|
|
6
6
|
URL = window.URL;
|
7
7
|
}
|
8
8
|
const errorHandler = require('../util/errorHandler');
|
9
|
+
const path = require('path');
|
10
|
+
const locationStr = `core.${path.basename(__filename, path.extname(__filename))}`;
|
9
11
|
|
10
12
|
/**
|
11
13
|
* @description 开始侦听事件
|
@@ -58,6 +60,7 @@ module.exports = async ({ baseUrl, sessionKey, verifyKey, message, error, close
|
|
58
60
|
};
|
59
61
|
return ws;
|
60
62
|
} catch (error) {
|
63
|
+
console.error(`mirai-js: error ${locationStr}`);
|
61
64
|
errorHandler(error);
|
62
65
|
}
|
63
66
|
};
|
@@ -6,6 +6,8 @@ if (!process.browser) {
|
|
6
6
|
URL = window.URL;
|
7
7
|
}
|
8
8
|
const errorHandler = require('../util/errorHandler');
|
9
|
+
const path = require('path');
|
10
|
+
const locationStr = `core.${path.basename(__filename, path.extname(__filename))}`;
|
9
11
|
|
10
12
|
/**
|
11
13
|
* @description 开始侦听事件
|
@@ -70,6 +72,7 @@ module.exports = async ({ baseUrl, sessionKey, verifyKey, message, error, close,
|
|
70
72
|
});
|
71
73
|
return ws;
|
72
74
|
} catch (error) {
|
75
|
+
console.error(`mirai-js: error ${locationStr}`);
|
73
76
|
errorHandler(error);
|
74
77
|
}
|
75
78
|
};
|
@@ -1,4 +1,6 @@
|
|
1
1
|
const errorHandler = require('../util/errorHandler');
|
2
|
+
const path = require('path');
|
3
|
+
const locationStr = `core.${path.basename(__filename, path.extname(__filename))}`;
|
2
4
|
|
3
5
|
/**
|
4
6
|
* @description 停止侦听事件
|
@@ -25,6 +27,7 @@ module.exports = async (wsConnection) => {
|
|
25
27
|
// do nothing
|
26
28
|
}
|
27
29
|
} catch (error) {
|
30
|
+
console.error(`mirai-js: error ${locationStr}`);
|
28
31
|
errorHandler(error);
|
29
32
|
}
|
30
33
|
};
|
@@ -1,4 +1,6 @@
|
|
1
1
|
const errorHandler = require('../util/errorHandler');
|
2
|
+
const path = require('path');
|
3
|
+
const locationStr = `core.${path.basename(__filename, path.extname(__filename))}`;
|
2
4
|
|
3
5
|
/**
|
4
6
|
* @description 停止侦听事件
|
@@ -25,6 +27,7 @@ module.exports = async (wsConnection) => {
|
|
25
27
|
// do nothing
|
26
28
|
}
|
27
29
|
} catch (error) {
|
30
|
+
console.error(`mirai-js: error ${locationStr}`);
|
28
31
|
errorHandler(error);
|
29
32
|
}
|
30
33
|
};
|
package/src/core/unmute.js
CHANGED
@@ -7,6 +7,8 @@ if (!process.browser) {
|
|
7
7
|
URL = window.URL;
|
8
8
|
}
|
9
9
|
const errorHandler = require('../util/errorHandler');
|
10
|
+
const path = require('path');
|
11
|
+
const locationStr = `core.${path.basename(__filename, path.extname(__filename))}`;
|
10
12
|
|
11
13
|
/**
|
12
14
|
* @description 解除禁言
|
@@ -28,7 +30,7 @@ module.exports = async ({ baseUrl, sessionKey, target, memberId }) => {
|
|
28
30
|
data: { code, msg: message }
|
29
31
|
} = responseData;
|
30
32
|
} catch (error) {
|
31
|
-
throw new Error('
|
33
|
+
throw new Error(('请求返回格式出错,请检查 mirai-console'));
|
32
34
|
}
|
33
35
|
// 抛出 mirai 的异常,到 catch 中处理后再抛出
|
34
36
|
if (code in errCodeMap) {
|
@@ -36,6 +38,7 @@ module.exports = async ({ baseUrl, sessionKey, target, memberId }) => {
|
|
36
38
|
}
|
37
39
|
return { message, code };
|
38
40
|
} catch (error) {
|
41
|
+
console.error(`mirai-js: error ${locationStr}`);
|
39
42
|
errorHandler(error);
|
40
43
|
}
|
41
44
|
};
|
package/src/core/unmuteAll.js
CHANGED
@@ -7,6 +7,8 @@ if (!process.browser) {
|
|
7
7
|
URL = window.URL;
|
8
8
|
}
|
9
9
|
const errorHandler = require('../util/errorHandler');
|
10
|
+
const path = require('path');
|
11
|
+
const locationStr = `core.${path.basename(__filename, path.extname(__filename))}`;
|
10
12
|
|
11
13
|
/**
|
12
14
|
* @description 解除全员禁言
|
@@ -27,7 +29,7 @@ module.exports = async ({ baseUrl, sessionKey, target }) => {
|
|
27
29
|
data: { code, msg: message }
|
28
30
|
} = responseData;
|
29
31
|
} catch (error) {
|
30
|
-
throw new Error('
|
32
|
+
throw new Error(('请求返回格式出错,请检查 mirai-console'));
|
31
33
|
}
|
32
34
|
// 抛出 mirai 的异常,到 catch 中处理后再抛出
|
33
35
|
if (code in errCodeMap) {
|
@@ -35,6 +37,7 @@ module.exports = async ({ baseUrl, sessionKey, target }) => {
|
|
35
37
|
}
|
36
38
|
return { message, code };
|
37
39
|
} catch (error) {
|
40
|
+
console.error(`mirai-js: error ${locationStr}`);
|
38
41
|
errorHandler(error);
|
39
42
|
}
|
40
43
|
};
|
package/src/core/uploadImage.js
CHANGED
@@ -7,6 +7,8 @@ if (!process.browser) {
|
|
7
7
|
URL = window.URL;
|
8
8
|
}
|
9
9
|
const errorHandler = require('../util/errorHandler');
|
10
|
+
const path = require('path');
|
11
|
+
const locationStr = `core.${path.basename(__filename, path.extname(__filename))}`;
|
10
12
|
const FormData = require('form-data');
|
11
13
|
|
12
14
|
|
@@ -42,7 +44,7 @@ module.exports = async ({ baseUrl, sessionKey, type, img }) => {
|
|
42
44
|
data: { msg: message, code, imageId, url, path }
|
43
45
|
} = responseData;
|
44
46
|
} catch (error) {
|
45
|
-
throw new Error('
|
47
|
+
throw new Error(('请求返回格式出错,请检查 mirai-console'));
|
46
48
|
}
|
47
49
|
|
48
50
|
// 抛出 mirai 的异常,到 catch 中处理后再抛出
|
@@ -51,6 +53,7 @@ module.exports = async ({ baseUrl, sessionKey, type, img }) => {
|
|
51
53
|
}
|
52
54
|
return { imageId, url, path };
|
53
55
|
} catch (error) {
|
56
|
+
console.error(`mirai-js: error ${locationStr}`);
|
54
57
|
errorHandler(error);
|
55
58
|
}
|
56
59
|
};
|
package/src/core/uploadVoice.js
CHANGED
@@ -7,6 +7,8 @@ if (!process.browser) {
|
|
7
7
|
URL = window.URL;
|
8
8
|
}
|
9
9
|
const errorHandler = require('../util/errorHandler');
|
10
|
+
const path = require('path');
|
11
|
+
const locationStr = `core.${path.basename(__filename, path.extname(__filename))}`;
|
10
12
|
const FormData = require('form-data');
|
11
13
|
|
12
14
|
|
@@ -42,7 +44,7 @@ module.exports = async ({ baseUrl, sessionKey, type, voice }) => {
|
|
42
44
|
data: { msg: message, code, voiceId, url, path }
|
43
45
|
} = responseData;
|
44
46
|
} catch (error) {
|
45
|
-
throw new Error('
|
47
|
+
throw new Error(('请求返回格式出错,请检查 mirai-console'));
|
46
48
|
}
|
47
49
|
// 抛出 mirai 的异常,到 catch 中处理后再抛出
|
48
50
|
if (code in errCodeMap) {
|
@@ -50,6 +52,7 @@ module.exports = async ({ baseUrl, sessionKey, type, voice }) => {
|
|
50
52
|
}
|
51
53
|
return { voiceId, url, path };
|
52
54
|
} catch (error) {
|
55
|
+
console.error(`mirai-js: error ${locationStr}`);
|
53
56
|
errorHandler(error);
|
54
57
|
}
|
55
58
|
};
|
package/src/core/verify.js
CHANGED
@@ -7,6 +7,8 @@ if (!process.browser) {
|
|
7
7
|
URL = window.URL;
|
8
8
|
}
|
9
9
|
const errorHandler = require('../util/errorHandler');
|
10
|
+
const path = require('path');
|
11
|
+
const locationStr = `core.${path.basename(__filename, path.extname(__filename))}`;
|
10
12
|
|
11
13
|
/**
|
12
14
|
* @description 校验 sessionKey,将一个 session 绑定到指定的 qq 上
|
@@ -28,7 +30,7 @@ module.exports = async ({ baseUrl, sessionKey, qq, throwable = true }) => {
|
|
28
30
|
data: { msg: message, code },
|
29
31
|
} = responseData;
|
30
32
|
} catch (error) {
|
31
|
-
throw new Error('
|
33
|
+
throw new Error(('请求返回格式出错,请检查 mirai-console'));
|
32
34
|
}
|
33
35
|
// 抛出 mirai 的异常,到 catch 中处理后再抛出
|
34
36
|
if (code in errCodeMap) {
|
@@ -36,6 +38,7 @@ module.exports = async ({ baseUrl, sessionKey, qq, throwable = true }) => {
|
|
36
38
|
}
|
37
39
|
return { message, code };
|
38
40
|
} catch (error) {
|
41
|
+
console.error(`mirai-js: error ${locationStr}`);
|
39
42
|
errorHandler(error);
|
40
43
|
}
|
41
44
|
|
package/webpack.config.js
CHANGED
@@ -1,44 +0,0 @@
|
|
1
|
-
const { errCodeMap } = require('../util/errCode');
|
2
|
-
const axios = require('axios').default;
|
3
|
-
let URL;
|
4
|
-
if (!process.browser) {
|
5
|
-
({ URL } = require('url'));
|
6
|
-
} else {
|
7
|
-
URL = window.URL;
|
8
|
-
}
|
9
|
-
const errorHandler = require('../util/errorHandler');
|
10
|
-
|
11
|
-
/**
|
12
|
-
* @description 获取群文件详细信息
|
13
|
-
* @param {string} baseUrl mirai-api-http server 的地址
|
14
|
-
* @param {string} sessionKey 会话标识
|
15
|
-
* @param {number} target 群号
|
16
|
-
* @param {string} id 文件 id
|
17
|
-
* @returns {Object}
|
18
|
-
* 结构 {
|
19
|
-
* id, name, path, length, downloadTimes, uploaderId,
|
20
|
-
* uploadTime, lastModifyTime, downloadUrl, sha1, md5
|
21
|
-
* }
|
22
|
-
*/
|
23
|
-
module.exports = async ({ baseUrl, sessionKey, target, id }) => {
|
24
|
-
try {
|
25
|
-
// 拼接 url
|
26
|
-
const url = new URL('/groupFileInfo', baseUrl).toString();
|
27
|
-
|
28
|
-
// 请求
|
29
|
-
const responseData = await axios.get(url, { params: { sessionKey, target, id } });
|
30
|
-
try {
|
31
|
-
var { data, data: { msg: message, code } } = responseData;
|
32
|
-
} catch (error) {
|
33
|
-
throw new Error('core.getGroupFileInfo 请求返回格式出错,请检查 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
|
-
errorHandler(error);
|
43
|
-
}
|
44
|
-
};
|
@@ -1,40 +0,0 @@
|
|
1
|
-
const { errCodeMap } = require('../util/errCode');
|
2
|
-
const axios = require('axios').default;
|
3
|
-
let URL;
|
4
|
-
if (!process.browser) {
|
5
|
-
({ URL } = require('url'));
|
6
|
-
} else {
|
7
|
-
URL = window.URL;
|
8
|
-
}
|
9
|
-
const errorHandler = require('../util/errorHandler');
|
10
|
-
|
11
|
-
/**
|
12
|
-
* @description 获取群文件列表
|
13
|
-
* @param {string} baseUrl mirai-api-http server 的地址
|
14
|
-
* @param {string} sessionKey 会话标识
|
15
|
-
* @param {number} target 群号
|
16
|
-
* @param {string} dir 可选,查询目录,默认为根目录
|
17
|
-
* @returns {Object[]} 结构 array[...{ id, name, path, isFile }]
|
18
|
-
*/
|
19
|
-
module.exports = async ({ baseUrl, sessionKey, target, dir }) => {
|
20
|
-
try {
|
21
|
-
// 拼接 url
|
22
|
-
const url = new URL('/groupFileList', baseUrl).toString();
|
23
|
-
|
24
|
-
// 请求
|
25
|
-
const responseData = await axios.get(url, { params: { sessionKey, target, dir } });
|
26
|
-
try {
|
27
|
-
var { data, data: { msg: message, code } } = responseData;
|
28
|
-
} catch (error) {
|
29
|
-
throw new Error('core.getGroupFileList 请求返回格式出错,请检查 mirai-console');
|
30
|
-
}
|
31
|
-
|
32
|
-
// 抛出 mirai 的异常,到 catch 中处理后再抛出
|
33
|
-
if (code in errCodeMap) {
|
34
|
-
throw new Error(message);
|
35
|
-
}
|
36
|
-
return data;
|
37
|
-
} catch (error) {
|
38
|
-
errorHandler(error);
|
39
|
-
}
|
40
|
-
};
|
@@ -1,46 +0,0 @@
|
|
1
|
-
const { errCodeMap } = require('../util/errCode');
|
2
|
-
const axios = require('axios');
|
3
|
-
let URL;
|
4
|
-
if (!process.browser) {
|
5
|
-
({ URL } = require('url'));
|
6
|
-
} else {
|
7
|
-
URL = window.URL;
|
8
|
-
}
|
9
|
-
const errorHandler = require('../util/errorHandler');
|
10
|
-
|
11
|
-
/**
|
12
|
-
* @description 移动群文件
|
13
|
-
* @param {string} baseUrl mirai-api-http server 的地址
|
14
|
-
* @param {string} sessionKey 会话标识
|
15
|
-
* @param {number} target 群号
|
16
|
-
* @param {number} id 文件 id
|
17
|
-
* @param {string} movePath 目标 path
|
18
|
-
* @returns {Object} 结构 { message, code }
|
19
|
-
*/
|
20
|
-
module.exports = async ({ baseUrl, sessionKey, target, id, movePath }) => {
|
21
|
-
try {
|
22
|
-
// 拼接 url
|
23
|
-
const url = new URL('/groupFileMove', baseUrl).toString();
|
24
|
-
|
25
|
-
// 请求
|
26
|
-
const responseData = await axios.post(url, {
|
27
|
-
sessionKey, target, id, movePath
|
28
|
-
});
|
29
|
-
|
30
|
-
try {
|
31
|
-
var {
|
32
|
-
data: { msg: message, code }
|
33
|
-
} = responseData;
|
34
|
-
} catch (error) {
|
35
|
-
throw new Error('core.groupFileRename 请求返回格式出错,请检查 mirai-console');
|
36
|
-
}
|
37
|
-
// 抛出 mirai 的异常,到 catch 中处理后再抛出
|
38
|
-
if (code in errCodeMap) {
|
39
|
-
throw new Error(message);
|
40
|
-
}
|
41
|
-
return { message, code };
|
42
|
-
} catch (error) {
|
43
|
-
errorHandler(error);
|
44
|
-
}
|
45
|
-
|
46
|
-
};
|