mirai-js 2.7.4 → 2.8.0-2
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/node/BaseType.d.ts +293 -47
- package/dist/node/Bot.d.ts +15 -10
- package/dist/node/index.d.ts +5 -3
- package/dist/node/typeHelpers.d.ts +2 -0
- package/package.json +2 -2
- package/src/BaseType.d.ts +293 -47
- package/src/Bot.d.ts +15 -10
- package/src/index.d.ts +5 -3
- package/src/typeHelpers.d.ts +2 -0
- package/src/util/isBrowserEnv.js +2 -2
- package/dist/node/ForwardNode.d.ts +0 -15
- package/dist/node/ForwardNode.js +0 -70
- package/dist/node/core/getGroupFileInfo.js +0 -77
- package/dist/node/core/getGroupFileList.js +0 -73
- package/dist/node/core/groupFileDelete.js +0 -73
- package/dist/node/core/groupFileMove.js +0 -76
- package/dist/node/core/groupFileRename.js +0 -76
- package/dist/node/core/sendFirendMessage.js +0 -68
- package/dist/node/core/uploadFileAndSend.js +0 -87
- package/index.ts +0 -7
@@ -1,73 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
const {
|
4
|
-
errCodeMap
|
5
|
-
} = require('../util/errCode');
|
6
|
-
|
7
|
-
const axios = require('axios').default;
|
8
|
-
|
9
|
-
let URL;
|
10
|
-
|
11
|
-
if (!process.browser) {
|
12
|
-
({
|
13
|
-
URL
|
14
|
-
} = require('url'));
|
15
|
-
} else {
|
16
|
-
URL = window.URL;
|
17
|
-
}
|
18
|
-
|
19
|
-
const errorHandler = require('../util/errorHandler');
|
20
|
-
|
21
|
-
const path = require('path');
|
22
|
-
|
23
|
-
const locationStr = `core.${path.basename(__filename, path.extname(__filename))}`;
|
24
|
-
/**
|
25
|
-
* @description 获取群文件列表
|
26
|
-
* @param {string} baseUrl mirai-api-http server 的地址
|
27
|
-
* @param {string} sessionKey 会话标识
|
28
|
-
* @param {number} target 群号
|
29
|
-
* @param {string} dir 可选,查询目录,默认为根目录
|
30
|
-
* @returns {Object[]} 结构 array[...{ id, name, path, isFile }]
|
31
|
-
*/
|
32
|
-
|
33
|
-
module.exports = async ({
|
34
|
-
baseUrl,
|
35
|
-
sessionKey,
|
36
|
-
target,
|
37
|
-
dir
|
38
|
-
}) => {
|
39
|
-
try {
|
40
|
-
// 拼接 url
|
41
|
-
const url = new URL('/groupFileList', baseUrl).toString(); // 请求
|
42
|
-
|
43
|
-
const responseData = await axios.get(url, {
|
44
|
-
params: {
|
45
|
-
sessionKey,
|
46
|
-
target,
|
47
|
-
dir
|
48
|
-
}
|
49
|
-
});
|
50
|
-
|
51
|
-
try {
|
52
|
-
var {
|
53
|
-
data,
|
54
|
-
data: {
|
55
|
-
msg: message,
|
56
|
-
code
|
57
|
-
}
|
58
|
-
} = responseData;
|
59
|
-
} catch (error) {
|
60
|
-
throw new Error('请求返回格式出错,请检查 mirai-console');
|
61
|
-
} // 抛出 mirai 的异常,到 catch 中处理后再抛出
|
62
|
-
|
63
|
-
|
64
|
-
if (code in errCodeMap) {
|
65
|
-
throw new Error(message);
|
66
|
-
}
|
67
|
-
|
68
|
-
return data;
|
69
|
-
} catch (error) {
|
70
|
-
console.error(`mirai-js: error ${locationStr}`);
|
71
|
-
errorHandler(error);
|
72
|
-
}
|
73
|
-
};
|
@@ -1,73 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
const {
|
4
|
-
errCodeMap
|
5
|
-
} = require('../util/errCode');
|
6
|
-
|
7
|
-
const axios = require('axios');
|
8
|
-
|
9
|
-
let URL;
|
10
|
-
|
11
|
-
if (!process.browser) {
|
12
|
-
({
|
13
|
-
URL
|
14
|
-
} = require('url'));
|
15
|
-
} else {
|
16
|
-
URL = window.URL;
|
17
|
-
}
|
18
|
-
|
19
|
-
const errorHandler = require('../util/errorHandler');
|
20
|
-
|
21
|
-
const path = require('path');
|
22
|
-
|
23
|
-
const locationStr = `core.${path.basename(__filename, path.extname(__filename))}`;
|
24
|
-
/**
|
25
|
-
* @description 删除群文件
|
26
|
-
* @param {string} baseUrl mirai-api-http server 的地址
|
27
|
-
* @param {string} sessionKey 会话标识
|
28
|
-
* @param {number} target 群号
|
29
|
-
* @param {number} id 文件 id
|
30
|
-
* @returns {Object} 结构 { message, code }
|
31
|
-
*/
|
32
|
-
|
33
|
-
module.exports = async ({
|
34
|
-
baseUrl,
|
35
|
-
sessionKey,
|
36
|
-
target,
|
37
|
-
id
|
38
|
-
}) => {
|
39
|
-
try {
|
40
|
-
// 拼接 url
|
41
|
-
const url = new URL('/groupFileDelete', baseUrl).toString(); // 请求
|
42
|
-
|
43
|
-
const responseData = await axios.post(url, {
|
44
|
-
sessionKey,
|
45
|
-
target,
|
46
|
-
id
|
47
|
-
});
|
48
|
-
|
49
|
-
try {
|
50
|
-
var {
|
51
|
-
data: {
|
52
|
-
msg: message,
|
53
|
-
code
|
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 {
|
66
|
-
message,
|
67
|
-
code
|
68
|
-
};
|
69
|
-
} catch (error) {
|
70
|
-
console.error(`mirai-js: error ${locationStr}`);
|
71
|
-
errorHandler(error);
|
72
|
-
}
|
73
|
-
};
|
@@ -1,76 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
const {
|
4
|
-
errCodeMap
|
5
|
-
} = require('../util/errCode');
|
6
|
-
|
7
|
-
const axios = require('axios');
|
8
|
-
|
9
|
-
let URL;
|
10
|
-
|
11
|
-
if (!process.browser) {
|
12
|
-
({
|
13
|
-
URL
|
14
|
-
} = require('url'));
|
15
|
-
} else {
|
16
|
-
URL = window.URL;
|
17
|
-
}
|
18
|
-
|
19
|
-
const errorHandler = require('../util/errorHandler');
|
20
|
-
|
21
|
-
const path = require('path');
|
22
|
-
|
23
|
-
const locationStr = `core.${path.basename(__filename, path.extname(__filename))}`;
|
24
|
-
/**
|
25
|
-
* @description 移动群文件
|
26
|
-
* @param {string} baseUrl mirai-api-http server 的地址
|
27
|
-
* @param {string} sessionKey 会话标识
|
28
|
-
* @param {number} target 群号
|
29
|
-
* @param {number} id 文件 id
|
30
|
-
* @param {string} movePath 目标 path
|
31
|
-
* @returns {Object} 结构 { message, code }
|
32
|
-
*/
|
33
|
-
|
34
|
-
module.exports = async ({
|
35
|
-
baseUrl,
|
36
|
-
sessionKey,
|
37
|
-
target,
|
38
|
-
id,
|
39
|
-
movePath
|
40
|
-
}) => {
|
41
|
-
try {
|
42
|
-
// 拼接 url
|
43
|
-
const url = new URL('/groupFileMove', baseUrl).toString(); // 请求
|
44
|
-
|
45
|
-
const responseData = await axios.post(url, {
|
46
|
-
sessionKey,
|
47
|
-
target,
|
48
|
-
id,
|
49
|
-
movePath
|
50
|
-
});
|
51
|
-
|
52
|
-
try {
|
53
|
-
var {
|
54
|
-
data: {
|
55
|
-
msg: message,
|
56
|
-
code
|
57
|
-
}
|
58
|
-
} = responseData;
|
59
|
-
} catch (error) {
|
60
|
-
throw new Error('请求返回格式出错,请检查 mirai-console');
|
61
|
-
} // 抛出 mirai 的异常,到 catch 中处理后再抛出
|
62
|
-
|
63
|
-
|
64
|
-
if (code in errCodeMap) {
|
65
|
-
throw new Error(message);
|
66
|
-
}
|
67
|
-
|
68
|
-
return {
|
69
|
-
message,
|
70
|
-
code
|
71
|
-
};
|
72
|
-
} catch (error) {
|
73
|
-
console.error(`mirai-js: error ${locationStr}`);
|
74
|
-
errorHandler(error);
|
75
|
-
}
|
76
|
-
};
|
@@ -1,76 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
const {
|
4
|
-
errCodeMap
|
5
|
-
} = require('../util/errCode');
|
6
|
-
|
7
|
-
const axios = require('axios');
|
8
|
-
|
9
|
-
let URL;
|
10
|
-
|
11
|
-
if (!process.browser) {
|
12
|
-
({
|
13
|
-
URL
|
14
|
-
} = require('url'));
|
15
|
-
} else {
|
16
|
-
URL = window.URL;
|
17
|
-
}
|
18
|
-
|
19
|
-
const errorHandler = require('../util/errorHandler');
|
20
|
-
|
21
|
-
const path = require('path');
|
22
|
-
|
23
|
-
const locationStr = `core.${path.basename(__filename, path.extname(__filename))}`;
|
24
|
-
/**
|
25
|
-
* @description 重命名群文件
|
26
|
-
* @param {string} baseUrl mirai-api-http server 的地址
|
27
|
-
* @param {string} sessionKey 会话标识
|
28
|
-
* @param {number} target 群号
|
29
|
-
* @param {number} id 文件 id
|
30
|
-
* @param {string} rename 重命名
|
31
|
-
* @returns {Object} 结构 { message, code }
|
32
|
-
*/
|
33
|
-
|
34
|
-
module.exports = async ({
|
35
|
-
baseUrl,
|
36
|
-
sessionKey,
|
37
|
-
target,
|
38
|
-
id,
|
39
|
-
rename
|
40
|
-
}) => {
|
41
|
-
try {
|
42
|
-
// 拼接 url
|
43
|
-
const url = new URL('/groupFileRename', baseUrl).toString(); // 请求
|
44
|
-
|
45
|
-
const responseData = await axios.post(url, {
|
46
|
-
sessionKey,
|
47
|
-
target,
|
48
|
-
id,
|
49
|
-
rename
|
50
|
-
});
|
51
|
-
|
52
|
-
try {
|
53
|
-
var {
|
54
|
-
data: {
|
55
|
-
msg: message,
|
56
|
-
code
|
57
|
-
}
|
58
|
-
} = responseData;
|
59
|
-
} catch (error) {
|
60
|
-
throw new Error('请求返回格式出错,请检查 mirai-console');
|
61
|
-
} // 抛出 mirai 的异常,到 catch 中处理后再抛出
|
62
|
-
|
63
|
-
|
64
|
-
if (code in errCodeMap) {
|
65
|
-
throw new Error(message);
|
66
|
-
}
|
67
|
-
|
68
|
-
return {
|
69
|
-
message,
|
70
|
-
code
|
71
|
-
};
|
72
|
-
} catch (error) {
|
73
|
-
console.error(`mirai-js: error ${locationStr}`);
|
74
|
-
errorHandler(error);
|
75
|
-
}
|
76
|
-
};
|
@@ -1,68 +0,0 @@
|
|
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 向 qq 好友发送消息
|
20
|
-
* @param {string} baseUrl mirai-api-http server 的地址
|
21
|
-
* @param {string} sessionKey 会话标识
|
22
|
-
* @param {number} target 目标好友 qq 号
|
23
|
-
* @param {number} quote 消息引用,使用发送时返回的 messageId
|
24
|
-
* @param {MessageType[]} messageChain 消息链,MessageType 数组
|
25
|
-
* @returns {Object} 结构 { message, code, messageId }
|
26
|
-
*/
|
27
|
-
|
28
|
-
module.exports = async ({
|
29
|
-
baseUrl,
|
30
|
-
sessionKey,
|
31
|
-
target,
|
32
|
-
quote,
|
33
|
-
messageChain
|
34
|
-
}) => {
|
35
|
-
try {
|
36
|
-
// 拼接 url
|
37
|
-
const url = new URL('/sendFriendMessage', baseUrl).toString(); // 请求
|
38
|
-
|
39
|
-
const responseData = await axios.post(url, {
|
40
|
-
sessionKey,
|
41
|
-
target,
|
42
|
-
quote,
|
43
|
-
messageChain
|
44
|
-
});
|
45
|
-
|
46
|
-
try {
|
47
|
-
var {
|
48
|
-
data: {
|
49
|
-
msg: message,
|
50
|
-
code,
|
51
|
-
messageId
|
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 messageId;
|
64
|
-
} catch (error) {
|
65
|
-
console.error(`mirai-js: error ${locationStr}`);
|
66
|
-
errorHandler(error);
|
67
|
-
}
|
68
|
-
};
|
@@ -1,87 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
const {
|
4
|
-
errCodeMap
|
5
|
-
} = require('../util/errCode');
|
6
|
-
|
7
|
-
const axios = require('axios').default;
|
8
|
-
|
9
|
-
let URL;
|
10
|
-
|
11
|
-
if (!process.browser) {
|
12
|
-
({
|
13
|
-
URL
|
14
|
-
} = require('url'));
|
15
|
-
} else {
|
16
|
-
URL = window.URL;
|
17
|
-
}
|
18
|
-
|
19
|
-
const errorHandler = require('../util/errorHandler');
|
20
|
-
|
21
|
-
const path = require('path');
|
22
|
-
|
23
|
-
const locationStr = `core.${path.basename(__filename, path.extname(__filename))}`;
|
24
|
-
|
25
|
-
const FormData = require('form-data');
|
26
|
-
/**
|
27
|
-
* @description 上传文件至服务器并发送,返回文件 id
|
28
|
-
* @param {string} baseUrl mirai-api-http server 的地址
|
29
|
-
* @param {string} sessionKey 会话标识
|
30
|
-
* @param {string} type "friend" 或 "group",目前仅支持 group
|
31
|
-
* @param {string} target 群/好友号
|
32
|
-
* @param {string} path 上传目录
|
33
|
-
* @param {Buffer} file 文件二进制数据
|
34
|
-
* @returns {string} 文件 id
|
35
|
-
*/
|
36
|
-
|
37
|
-
|
38
|
-
module.exports = async ({
|
39
|
-
baseUrl,
|
40
|
-
sessionKey,
|
41
|
-
type,
|
42
|
-
target,
|
43
|
-
path,
|
44
|
-
file
|
45
|
-
}) => {
|
46
|
-
try {
|
47
|
-
// 拼接 url
|
48
|
-
const targetUrl = new URL('/uploadFileAndSend', baseUrl).toString(); // 构造 fromdata
|
49
|
-
|
50
|
-
const form = new FormData();
|
51
|
-
form.append('sessionKey', sessionKey);
|
52
|
-
form.append('type', type);
|
53
|
-
form.append('target', target);
|
54
|
-
form.append('path', path);
|
55
|
-
form.append('file', file, {
|
56
|
-
filename: 'payload'
|
57
|
-
}); // 请求
|
58
|
-
|
59
|
-
const responseData = await axios.post(targetUrl, form, {
|
60
|
-
// formdata.getHeaders 将会指定 content-type,同时给定随
|
61
|
-
// 机生成的 boundary,即分隔符,用以分隔多个表单项而不会造成混乱
|
62
|
-
headers: form.getHeaders()
|
63
|
-
});
|
64
|
-
|
65
|
-
try {
|
66
|
-
var {
|
67
|
-
data: {
|
68
|
-
msg: message,
|
69
|
-
code,
|
70
|
-
id
|
71
|
-
}
|
72
|
-
} = responseData;
|
73
|
-
} catch (error) {
|
74
|
-
throw new Error('请求返回格式出错,请检查 mirai-console');
|
75
|
-
} // 抛出 mirai 的异常,到 catch 中处理后再抛出
|
76
|
-
|
77
|
-
|
78
|
-
if (code in errCodeMap) {
|
79
|
-
throw new Error(message);
|
80
|
-
}
|
81
|
-
|
82
|
-
return id;
|
83
|
-
} catch (error) {
|
84
|
-
console.error(`mirai-js: error ${locationStr}`);
|
85
|
-
errorHandler(error);
|
86
|
-
}
|
87
|
-
};
|