onebots 0.4.21 → 0.4.23
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 +163 -62
- package/lib/bin.js +1 -1
- package/lib/config.sample.yaml +1 -1
- package/lib/db.js +6 -6
- package/lib/index.d.ts +5 -5
- package/lib/onebot.d.ts +9 -6
- package/lib/onebot.js +63 -49
- package/lib/service/V11/action/common.d.ts +3 -2
- package/lib/service/V11/action/common.js +34 -38
- package/lib/service/V11/action/friend.d.ts +7 -7
- package/lib/service/V11/action/friend.js +6 -6
- package/lib/service/V11/action/group.d.ts +3 -3
- package/lib/service/V11/action/group.js +6 -6
- package/lib/service/V11/db_sqlite.js +7 -9
- package/lib/service/V11/index.d.ts +11 -12
- package/lib/service/V11/index.js +223 -172
- package/lib/service/V11/utils.d.ts +1 -4
- package/lib/service/V11/utils.js +11 -16
- package/lib/service/V12/index.d.ts +3 -5
- package/lib/service/V12/index.js +24 -26
- package/lib/service/shareMusicCustom.js +2 -2
- package/lib/service.d.ts +29 -0
- package/lib/service.js +85 -0
- package/lib/types.d.ts +2 -2
- package/lib/types.js +3 -3
- package/lib/utils.js +27 -15
- package/package.json +73 -70
package/lib/onebot.js
CHANGED
|
@@ -37,7 +37,7 @@ const process = __importStar(require("process"));
|
|
|
37
37
|
class NotFoundError extends Error {
|
|
38
38
|
constructor() {
|
|
39
39
|
super(...arguments);
|
|
40
|
-
this.message =
|
|
40
|
+
this.message = "不支持的API";
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
43
|
exports.NotFoundError = NotFoundError;
|
|
@@ -48,35 +48,35 @@ class OneBot extends events_1.EventEmitter {
|
|
|
48
48
|
this.uin = uin;
|
|
49
49
|
config = [].concat(config);
|
|
50
50
|
const protocolConfig = {
|
|
51
|
-
data_dir: (0, path_1.join)(app_1.App.configDir,
|
|
52
|
-
...this.app.config.general.protocol
|
|
51
|
+
data_dir: (0, path_1.join)(app_1.App.configDir, "data"),
|
|
52
|
+
...this.app.config.general.protocol,
|
|
53
53
|
};
|
|
54
54
|
this.config = config.map(c => {
|
|
55
55
|
if (!c.version)
|
|
56
|
-
c.version =
|
|
56
|
+
c.version = "V11";
|
|
57
57
|
if (!c.protocol)
|
|
58
58
|
c.protocol = {};
|
|
59
59
|
if (c.password)
|
|
60
60
|
this.password = c.password;
|
|
61
61
|
Object.assign(protocolConfig, c.protocol);
|
|
62
62
|
switch (c.version) {
|
|
63
|
-
case
|
|
63
|
+
case "V11":
|
|
64
64
|
return (0, utils_1.deepMerge)((0, utils_1.deepClone)(this.app.config.general.V11), c);
|
|
65
|
-
case
|
|
65
|
+
case "V12":
|
|
66
66
|
return (0, utils_1.deepMerge)((0, utils_1.deepClone)(this.app.config.general.V12), c);
|
|
67
67
|
default:
|
|
68
|
-
throw new Error(
|
|
68
|
+
throw new Error("不支持的oneBot版本:" + c.version);
|
|
69
69
|
}
|
|
70
70
|
});
|
|
71
71
|
this.client = new icqq_1.Client(protocolConfig);
|
|
72
72
|
this.instances = this.config.map(c => {
|
|
73
73
|
switch (c.version) {
|
|
74
|
-
case
|
|
74
|
+
case "V11":
|
|
75
75
|
return new V11_1.V11(this, this.client, c);
|
|
76
|
-
case
|
|
76
|
+
case "V12":
|
|
77
77
|
return new V12_1.V12(this, this.client, c);
|
|
78
78
|
default:
|
|
79
|
-
throw new Error(
|
|
79
|
+
throw new Error("不支持的oneBot版本:" + c.version);
|
|
80
80
|
}
|
|
81
81
|
});
|
|
82
82
|
this.status = OneBotStatus.Good;
|
|
@@ -89,60 +89,60 @@ class OneBot extends events_1.EventEmitter {
|
|
|
89
89
|
disposeArr.shift()();
|
|
90
90
|
}
|
|
91
91
|
};
|
|
92
|
-
this.client.trap(
|
|
93
|
-
console.log(
|
|
94
|
-
process.stdin.once(
|
|
92
|
+
this.client.trap("system.login.qrcode", function qrcodeHelper() {
|
|
93
|
+
console.log("扫码后回车继续");
|
|
94
|
+
process.stdin.once("data", () => {
|
|
95
95
|
this.login();
|
|
96
96
|
});
|
|
97
97
|
disposeArr.push(() => {
|
|
98
|
-
this.off(
|
|
98
|
+
this.off("system.login.qrcode", qrcodeHelper);
|
|
99
99
|
});
|
|
100
100
|
});
|
|
101
|
-
this.client.trap(
|
|
102
|
-
console.log(
|
|
103
|
-
process.stdin.once(
|
|
101
|
+
this.client.trap("system.login.device", function deviceHelper(e) {
|
|
102
|
+
console.log("请选择验证方式:1.短信验证 2.url验证");
|
|
103
|
+
process.stdin.once("data", buf => {
|
|
104
104
|
const input = buf.toString().trim();
|
|
105
|
-
if (input ===
|
|
105
|
+
if (input === "1") {
|
|
106
106
|
this.sendSmsCode();
|
|
107
|
-
console.log(
|
|
108
|
-
process.stdin.once(
|
|
107
|
+
console.log("请输入短信验证码:");
|
|
108
|
+
process.stdin.once("data", buf => {
|
|
109
109
|
this.submitSmsCode(buf.toString().trim());
|
|
110
110
|
});
|
|
111
111
|
}
|
|
112
112
|
else {
|
|
113
113
|
console.log(`请前往:${e.url} 完成验证后回车继续`);
|
|
114
|
-
process.stdin.once(
|
|
114
|
+
process.stdin.once("data", () => {
|
|
115
115
|
this.login();
|
|
116
116
|
});
|
|
117
117
|
}
|
|
118
118
|
});
|
|
119
119
|
disposeArr.push(() => {
|
|
120
|
-
this.off(
|
|
120
|
+
this.off("system.login.device", deviceHelper);
|
|
121
121
|
});
|
|
122
122
|
});
|
|
123
|
-
this.client.trap(
|
|
124
|
-
if (e.message.includes(
|
|
125
|
-
process.stdin.once(
|
|
123
|
+
this.client.trap("system.login.error", function errorHandler(e) {
|
|
124
|
+
if (e.message.includes("密码错误")) {
|
|
125
|
+
process.stdin.once("data", e => {
|
|
126
126
|
this.login(e.toString().trim());
|
|
127
127
|
});
|
|
128
128
|
}
|
|
129
129
|
else {
|
|
130
130
|
process.exit();
|
|
131
131
|
}
|
|
132
|
-
this.off(
|
|
132
|
+
this.off("system.login.error", errorHandler);
|
|
133
133
|
});
|
|
134
|
-
this.client.trap(
|
|
135
|
-
console.log(
|
|
136
|
-
process.stdin.once(
|
|
134
|
+
this.client.trap("system.login.slider", function sliderHelper(e) {
|
|
135
|
+
console.log("请输入滑块验证返回的ticket");
|
|
136
|
+
process.stdin.once("data", e => {
|
|
137
137
|
this.submitSlider(e.toString().trim());
|
|
138
138
|
});
|
|
139
139
|
disposeArr.push(() => {
|
|
140
|
-
this.off(
|
|
140
|
+
this.off("system.login.slider", sliderHelper);
|
|
141
141
|
});
|
|
142
142
|
});
|
|
143
|
-
this.client.trap(
|
|
143
|
+
this.client.trap("system.online", clean);
|
|
144
144
|
return new Promise(async (resolve) => {
|
|
145
|
-
const callback =
|
|
145
|
+
const callback = result => {
|
|
146
146
|
if (timer) {
|
|
147
147
|
clearTimeout(timer);
|
|
148
148
|
timer = null;
|
|
@@ -154,21 +154,25 @@ class OneBot extends events_1.EventEmitter {
|
|
|
154
154
|
}
|
|
155
155
|
};
|
|
156
156
|
let timer = setTimeout(() => {
|
|
157
|
-
callback([false,
|
|
157
|
+
callback([false, "登录超时"]);
|
|
158
158
|
}, this.app.config.timeout * 1000);
|
|
159
159
|
await this.client.login(this.uin, this.password);
|
|
160
|
-
const disposes = [
|
|
161
|
-
this.client.trapOnce(
|
|
160
|
+
const disposes = [
|
|
161
|
+
this.client.trapOnce("system.online", () => {
|
|
162
|
+
callback([true, null]);
|
|
163
|
+
}),
|
|
164
|
+
this.client.trapOnce("system.login.error", e => callback([false, e.message])),
|
|
165
|
+
];
|
|
162
166
|
});
|
|
163
167
|
}
|
|
164
168
|
startListen() {
|
|
165
|
-
this.client.on(
|
|
166
|
-
this.client.trap(
|
|
167
|
-
this.client.trap(
|
|
168
|
-
this.client.trap(
|
|
169
|
-
this.client.trap(
|
|
169
|
+
this.client.on("system.online", this.system_online.bind(this, "system.online"));
|
|
170
|
+
this.client.trap("system", this.dispatch.bind(this, "system"));
|
|
171
|
+
this.client.trap("notice", this.dispatch.bind(this, "notice"));
|
|
172
|
+
this.client.trap("request", this.dispatch.bind(this, "request"));
|
|
173
|
+
this.client.trap("message", this.dispatch.bind(this, "message"));
|
|
170
174
|
for (const instance of this.instances) {
|
|
171
|
-
instance.start(this.instances.length > 1 ?
|
|
175
|
+
instance.start(this.instances.length > 1 ? "/" + instance.version : undefined);
|
|
172
176
|
}
|
|
173
177
|
}
|
|
174
178
|
async stop(force) {
|
|
@@ -192,20 +196,21 @@ class OneBot extends events_1.EventEmitter {
|
|
|
192
196
|
continue;
|
|
193
197
|
}
|
|
194
198
|
const result = instance.format(event, data);
|
|
195
|
-
if (data.source) {
|
|
199
|
+
if (data.source) {
|
|
200
|
+
// 有 data.source 字段代表这是个回复
|
|
196
201
|
switch (data.message_type) {
|
|
197
|
-
case
|
|
202
|
+
case "group":
|
|
198
203
|
data.message.unshift({
|
|
199
|
-
type:
|
|
204
|
+
type: "reply",
|
|
200
205
|
seq: data.source.seq,
|
|
201
|
-
id: (0, icqq_2.genGroupMessageId)(data.group_id, data.source.user_id, data.source.seq, data.source.rand, data.source.time)
|
|
206
|
+
id: (0, icqq_2.genGroupMessageId)(data.group_id, data.source.user_id, data.source.seq, data.source.rand, data.source.time),
|
|
202
207
|
});
|
|
203
208
|
break;
|
|
204
|
-
case
|
|
209
|
+
case "private":
|
|
205
210
|
data.message.unshift({
|
|
206
|
-
type:
|
|
211
|
+
type: "reply",
|
|
207
212
|
seq: data.source.seq,
|
|
208
|
-
id: (0, icqq_2.genDmMessageId)(data.source.user_id, data.source.seq, data.source.rand, data.source.time)
|
|
213
|
+
id: (0, icqq_2.genDmMessageId)(data.source.user_id, data.source.seq, data.source.rand, data.source.time),
|
|
209
214
|
});
|
|
210
215
|
break;
|
|
211
216
|
}
|
|
@@ -220,4 +225,13 @@ var OneBotStatus;
|
|
|
220
225
|
OneBotStatus[OneBotStatus["Good"] = 0] = "Good";
|
|
221
226
|
OneBotStatus[OneBotStatus["Bad"] = 1] = "Bad";
|
|
222
227
|
})(OneBotStatus || (exports.OneBotStatus = OneBotStatus = {}));
|
|
223
|
-
exports.BOOLS = [
|
|
228
|
+
exports.BOOLS = [
|
|
229
|
+
"no_cache",
|
|
230
|
+
"auto_escape",
|
|
231
|
+
"as_long",
|
|
232
|
+
"enable",
|
|
233
|
+
"reject_add_request",
|
|
234
|
+
"is_dismiss",
|
|
235
|
+
"approve",
|
|
236
|
+
"block",
|
|
237
|
+
];
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Message } from "icqq";
|
|
2
1
|
import { V11 } from "../../../service/V11";
|
|
2
|
+
import { Message } from "icqq";
|
|
3
3
|
export declare class CommonAction {
|
|
4
4
|
/**
|
|
5
5
|
* 获取登录信息
|
|
@@ -16,8 +16,9 @@ export declare class CommonAction {
|
|
|
16
16
|
/**
|
|
17
17
|
* 获取消息
|
|
18
18
|
* @param message_id {string} 消息id
|
|
19
|
+
* @param onebot_id {number}
|
|
19
20
|
*/
|
|
20
|
-
getMsg(this: V11, message_id: number): Promise<Message>;
|
|
21
|
+
getMsg(this: V11, message_id: string, onebot_id: number): Promise<Message>;
|
|
21
22
|
/**
|
|
22
23
|
* 获取合并消息
|
|
23
24
|
* @param id {string} 合并id
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.CommonAction = void 0;
|
|
4
|
-
const icqq_1 = require("icqq");
|
|
5
4
|
const onebot_1 = require("../../../onebot");
|
|
5
|
+
const icqq_1 = require("icqq");
|
|
6
6
|
class CommonAction {
|
|
7
7
|
/**
|
|
8
8
|
* 获取登录信息
|
|
@@ -10,29 +10,25 @@ class CommonAction {
|
|
|
10
10
|
getLoginInfo() {
|
|
11
11
|
return {
|
|
12
12
|
user_id: this.oneBot.uin,
|
|
13
|
-
nickname: this.client.nickname
|
|
13
|
+
nickname: this.client.nickname,
|
|
14
14
|
};
|
|
15
15
|
}
|
|
16
16
|
/**
|
|
17
17
|
* 撤回消息
|
|
18
18
|
* @param message_id {string} 消息id
|
|
19
19
|
*/
|
|
20
|
-
deleteMsg(message_id) {
|
|
20
|
+
async deleteMsg(message_id) {
|
|
21
21
|
return this.client.deleteMsg(message_id);
|
|
22
22
|
}
|
|
23
23
|
/**
|
|
24
24
|
* 获取消息
|
|
25
25
|
* @param message_id {string} 消息id
|
|
26
|
+
* @param onebot_id {number}
|
|
26
27
|
*/
|
|
27
|
-
async getMsg(message_id) {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
if (!msg_entry)
|
|
32
|
-
throw new Error(`getMsg: can not find msg[${message_id}] in db`);
|
|
33
|
-
let msg = await this.client.getMsg(msg_entry.base64_id);
|
|
34
|
-
msg.message_id = String(message_id); // nonebot v11 要求 message_id 是 number 类型
|
|
35
|
-
msg["real_id"] = msg.message_id; // nonebot 的reply类型会检测real_id是否存在,虽然它从未使用
|
|
28
|
+
async getMsg(message_id, onebot_id) {
|
|
29
|
+
let msg = await this.client.getMsg(message_id);
|
|
30
|
+
msg.message_id = String(onebot_id); // nonebot v11 要求 message_id 是 number 类型
|
|
31
|
+
msg["real_id"] = onebot_id; // nonebot 的reply类型会检测real_id是否存在,虽然它从未使用
|
|
36
32
|
return msg;
|
|
37
33
|
}
|
|
38
34
|
/**
|
|
@@ -62,7 +58,7 @@ class CommonAction {
|
|
|
62
58
|
getCredentials(domain) {
|
|
63
59
|
return {
|
|
64
60
|
cookies: this.client.cookies[domain],
|
|
65
|
-
csrf_token: this.client.getCsrfToken()
|
|
61
|
+
csrf_token: this.client.getCsrfToken(),
|
|
66
62
|
};
|
|
67
63
|
}
|
|
68
64
|
/**
|
|
@@ -70,9 +66,9 @@ class CommonAction {
|
|
|
70
66
|
*/
|
|
71
67
|
getVersion() {
|
|
72
68
|
return {
|
|
73
|
-
app_name:
|
|
74
|
-
app_version:
|
|
75
|
-
protocol_version:
|
|
69
|
+
app_name: "icqq",
|
|
70
|
+
app_version: "2.x",
|
|
71
|
+
protocol_version: "v11",
|
|
76
72
|
};
|
|
77
73
|
}
|
|
78
74
|
/**
|
|
@@ -80,28 +76,28 @@ class CommonAction {
|
|
|
80
76
|
* @param delay {number} 要延迟的毫秒数
|
|
81
77
|
*/
|
|
82
78
|
setRestart(delay) {
|
|
83
|
-
return this.emit(
|
|
79
|
+
return this.emit("restart", delay);
|
|
84
80
|
}
|
|
85
81
|
getStatus() {
|
|
86
82
|
return {
|
|
87
83
|
online: this.client.status === icqq_1.OnlineStatus.Online,
|
|
88
|
-
good: this.oneBot.status === onebot_1.OneBotStatus.Good
|
|
84
|
+
good: this.oneBot.status === onebot_1.OneBotStatus.Good,
|
|
89
85
|
};
|
|
90
86
|
}
|
|
91
87
|
callLogin(func, ...args) {
|
|
92
88
|
return new Promise(async (resolve) => {
|
|
93
89
|
const receiveResult = (event) => {
|
|
94
|
-
this.client.offTrap(
|
|
95
|
-
this.client.offTrap(
|
|
96
|
-
this.client.offTrap(
|
|
97
|
-
this.client.offTrap(
|
|
90
|
+
this.client.offTrap("system.login.qrcode");
|
|
91
|
+
this.client.offTrap("system.login.device");
|
|
92
|
+
this.client.offTrap("system.login.slider");
|
|
93
|
+
this.client.offTrap("system.login.error");
|
|
98
94
|
resolve(event);
|
|
99
95
|
};
|
|
100
|
-
this.client.trap(
|
|
101
|
-
this.client.trap(
|
|
102
|
-
this.client.trap(
|
|
103
|
-
this.client.trap(
|
|
104
|
-
this.client.trapOnce(
|
|
96
|
+
this.client.trap("system.login.qrcode", receiveResult);
|
|
97
|
+
this.client.trap("system.login.device", receiveResult);
|
|
98
|
+
this.client.trap("system.login.slider", receiveResult);
|
|
99
|
+
this.client.trap("system.login.error", receiveResult);
|
|
100
|
+
this.client.trapOnce("system.online", receiveResult);
|
|
105
101
|
try {
|
|
106
102
|
await this.client[func](...args);
|
|
107
103
|
}
|
|
@@ -111,38 +107,38 @@ class CommonAction {
|
|
|
111
107
|
});
|
|
112
108
|
}
|
|
113
109
|
async submitSlider(ticket) {
|
|
114
|
-
return this.action.callLogin.apply(this, [
|
|
110
|
+
return this.action.callLogin.apply(this, ["submitSlider", ticket]);
|
|
115
111
|
}
|
|
116
112
|
async submitSmsCode(code) {
|
|
117
|
-
return this.action.callLogin.apply(this, [
|
|
113
|
+
return this.action.callLogin.apply(this, ["submitSmsCode", code]);
|
|
118
114
|
}
|
|
119
115
|
sendSmsCode() {
|
|
120
|
-
return new Promise(resolve => {
|
|
116
|
+
return new Promise((resolve) => {
|
|
121
117
|
const receiveResult = (e) => {
|
|
122
118
|
const callback = (data) => {
|
|
123
|
-
this.client.offTrap(
|
|
124
|
-
this.client.offTrap(
|
|
119
|
+
this.client.offTrap("internal.verbose");
|
|
120
|
+
this.client.offTrap("system.login.error");
|
|
125
121
|
resolve(data);
|
|
126
122
|
};
|
|
127
|
-
if ((typeof e ===
|
|
123
|
+
if ((typeof e === "string" && e.includes("已发送")) || typeof e !== "string") {
|
|
128
124
|
callback(e);
|
|
129
125
|
}
|
|
130
126
|
};
|
|
131
|
-
this.client.trap(
|
|
132
|
-
this.client.trap(
|
|
127
|
+
this.client.trap("internal.verbose", receiveResult);
|
|
128
|
+
this.client.trap("system.login.error", receiveResult);
|
|
133
129
|
this.client.sendSmsCode();
|
|
134
130
|
});
|
|
135
131
|
}
|
|
136
132
|
login(password) {
|
|
137
|
-
return this.action.callLogin.apply(this, [
|
|
133
|
+
return this.action.callLogin.apply(this, ["login", password]);
|
|
138
134
|
}
|
|
139
135
|
logout(keepalive) {
|
|
140
136
|
return new Promise(async (resolve) => {
|
|
141
137
|
const receiveResult = (e) => {
|
|
142
|
-
this.client.offTrap(
|
|
138
|
+
this.client.offTrap("system.offline");
|
|
143
139
|
resolve(e);
|
|
144
140
|
};
|
|
145
|
-
this.client.trap(
|
|
141
|
+
this.client.trap("system.offline", receiveResult);
|
|
146
142
|
await this.client.logout(keepalive);
|
|
147
143
|
});
|
|
148
144
|
}
|
|
@@ -1,30 +1,30 @@
|
|
|
1
1
|
import { OneBot } from "../../../onebot";
|
|
2
2
|
import { V11 } from "../../../service/V11";
|
|
3
|
-
import {
|
|
3
|
+
import { MessageElem } from "icqq/lib/message";
|
|
4
4
|
export declare class FriendAction {
|
|
5
5
|
/**
|
|
6
6
|
* 发送私聊消息
|
|
7
7
|
* @param user_id {number} 用户id
|
|
8
|
-
* @param message {
|
|
8
|
+
* @param message {MessageElem[]} 发送的消息
|
|
9
9
|
* @param message_id {string} 引用的消息ID
|
|
10
10
|
*/
|
|
11
|
-
sendPrivateMsg(this: V11, user_id: number, message:
|
|
11
|
+
sendPrivateMsg(this: V11, user_id: number, message: MessageElem[], message_id?: string): Promise<any>;
|
|
12
12
|
/**
|
|
13
13
|
* 获取好友列表
|
|
14
14
|
*/
|
|
15
|
-
getFriendList(this: OneBot<
|
|
15
|
+
getFriendList(this: OneBot<"V11">): Promise<import("icqq").FriendInfo[]>;
|
|
16
16
|
/**
|
|
17
17
|
* 处理好友添加请求
|
|
18
18
|
* @param flag {string} 请求flag
|
|
19
19
|
* @param approve {boolean} 是否同意
|
|
20
20
|
* @param remark {string} 添加后的备注
|
|
21
21
|
*/
|
|
22
|
-
setFriendAddRequest(this: OneBot<
|
|
22
|
+
setFriendAddRequest(this: OneBot<"V11">, flag: string, approve?: boolean, remark?: string): Promise<boolean>;
|
|
23
23
|
/**
|
|
24
24
|
* 获取陌生人信息
|
|
25
25
|
* @param user_id {number} 用户id
|
|
26
26
|
*/
|
|
27
|
-
getStrangerInfo(this: OneBot<
|
|
27
|
+
getStrangerInfo(this: OneBot<"V11">, user_id: number): Promise<{
|
|
28
28
|
user_id: number;
|
|
29
29
|
nickname: string;
|
|
30
30
|
sex: import("icqq").Gender;
|
|
@@ -36,5 +36,5 @@ export declare class FriendAction {
|
|
|
36
36
|
* @param user_id {number} 用户id
|
|
37
37
|
* @param times 点赞次数
|
|
38
38
|
*/
|
|
39
|
-
sendUserLike(this: OneBot<
|
|
39
|
+
sendUserLike(this: OneBot<"V11">, user_id: number, times?: number): Promise<boolean>;
|
|
40
40
|
}
|
|
@@ -7,19 +7,19 @@ class FriendAction {
|
|
|
7
7
|
/**
|
|
8
8
|
* 发送私聊消息
|
|
9
9
|
* @param user_id {number} 用户id
|
|
10
|
-
* @param message {
|
|
10
|
+
* @param message {MessageElem[]} 发送的消息
|
|
11
11
|
* @param message_id {string} 引用的消息ID
|
|
12
12
|
*/
|
|
13
13
|
async sendPrivateMsg(user_id, message, message_id) {
|
|
14
14
|
const msg = message_id ? await this.client.getMsg(message_id) : undefined;
|
|
15
|
-
const { element,
|
|
15
|
+
const { element, music, share } = await utils_1.processMessage.apply(this.client, [message]);
|
|
16
16
|
if (music)
|
|
17
17
|
return await shareMusicCustom_1.shareMusic.call(this.client.pickFriend(user_id), music);
|
|
18
18
|
if (share)
|
|
19
19
|
return await this.client.pickFriend(user_id).shareUrl(music.data);
|
|
20
|
-
if (element.length)
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
if (!element.length)
|
|
21
|
+
throw new Error("Empty message");
|
|
22
|
+
return await this.client.sendPrivateMsg(user_id, element, msg);
|
|
23
23
|
}
|
|
24
24
|
/**
|
|
25
25
|
* 获取好友列表
|
|
@@ -33,7 +33,7 @@ class FriendAction {
|
|
|
33
33
|
* @param approve {boolean} 是否同意
|
|
34
34
|
* @param remark {string} 添加后的备注
|
|
35
35
|
*/
|
|
36
|
-
async setFriendAddRequest(flag, approve = true, remark =
|
|
36
|
+
async setFriendAddRequest(flag, approve = true, remark = "") {
|
|
37
37
|
return await this.client.setFriendAddRequest(flag, approve, remark);
|
|
38
38
|
}
|
|
39
39
|
/**
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { V11 } from "../../../service/V11";
|
|
2
|
-
import {
|
|
2
|
+
import { MessageElem } from "icqq/lib/message";
|
|
3
3
|
export declare class GroupAction {
|
|
4
4
|
/**
|
|
5
5
|
* 发送群聊消息
|
|
6
6
|
* @param group_id {number} 群id
|
|
7
|
-
* @param message {
|
|
7
|
+
* @param message {MessageElem[]} 消息
|
|
8
8
|
* @param message_id {string} 引用的消息ID
|
|
9
9
|
*/
|
|
10
|
-
sendGroupMsg(this: V11, group_id: number, message:
|
|
10
|
+
sendGroupMsg(this: V11, group_id: number, message: MessageElem[], message_id?: string): Promise<any>;
|
|
11
11
|
/**
|
|
12
12
|
* 群组踢人
|
|
13
13
|
* @param group_id {number} 群id
|
|
@@ -7,19 +7,19 @@ class GroupAction {
|
|
|
7
7
|
/**
|
|
8
8
|
* 发送群聊消息
|
|
9
9
|
* @param group_id {number} 群id
|
|
10
|
-
* @param message {
|
|
10
|
+
* @param message {MessageElem[]} 消息
|
|
11
11
|
* @param message_id {string} 引用的消息ID
|
|
12
12
|
*/
|
|
13
13
|
async sendGroupMsg(group_id, message, message_id) {
|
|
14
14
|
const msg = message_id ? await this.client.getMsg(message_id) : undefined;
|
|
15
|
-
const { element,
|
|
15
|
+
const { element, music, share } = await utils_1.processMessage.apply(this.client, [message]);
|
|
16
16
|
if (music)
|
|
17
17
|
return await shareMusicCustom_1.shareMusic.call(this.client.pickGroup(group_id), music);
|
|
18
18
|
if (share)
|
|
19
19
|
return await this.client.pickGroup(group_id).shareUrl(music.data);
|
|
20
|
-
if (element.length)
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
if (!element.length)
|
|
21
|
+
throw new Error("Empty message");
|
|
22
|
+
return await this.client.sendGroupMsg(group_id, element, msg);
|
|
23
23
|
}
|
|
24
24
|
/**
|
|
25
25
|
* 群组踢人
|
|
@@ -135,7 +135,7 @@ class GroupAction {
|
|
|
135
135
|
* @param reason {string} 拒绝理由,approve为false时有效(默认为空)
|
|
136
136
|
* @param block {boolean} 拒绝时是否加入黑名单,(默认:false)
|
|
137
137
|
*/
|
|
138
|
-
setGroupAddRequest(flag, approve = true, reason =
|
|
138
|
+
setGroupAddRequest(flag, approve = true, reason = "", block = false) {
|
|
139
139
|
return this.client.setGroupAddRequest(flag, approve, reason, block);
|
|
140
140
|
}
|
|
141
141
|
/**
|
|
@@ -15,7 +15,7 @@ class Database {
|
|
|
15
15
|
this.logger = logger;
|
|
16
16
|
this.dbLock = new types_1.AsyncLock();
|
|
17
17
|
this.dataSource = new typeorm_1.DataSource({
|
|
18
|
-
type: "
|
|
18
|
+
type: "sqlite",
|
|
19
19
|
database: dbPath,
|
|
20
20
|
entities: [db_entities_1.MsgEntry],
|
|
21
21
|
});
|
|
@@ -47,7 +47,7 @@ class Database {
|
|
|
47
47
|
if (msgDataExists) {
|
|
48
48
|
// send_msg() 返回值和同步的 message 消息哪个先来不确定,send_msg 返回值后来时不允许更新数据库
|
|
49
49
|
if (msgData.content.length == 0) {
|
|
50
|
-
return;
|
|
50
|
+
return msgDataExists.id;
|
|
51
51
|
}
|
|
52
52
|
msgData.id = msgDataExists.id;
|
|
53
53
|
await this.msgRepo.update({ id: msgData.id }, msgData);
|
|
@@ -96,7 +96,10 @@ class Database {
|
|
|
96
96
|
*/
|
|
97
97
|
async markMsgAsRecalled(base64_id, id) {
|
|
98
98
|
if (base64_id || id)
|
|
99
|
-
await this.msgRepo.update(base64_id ? { base64_id: base64_id } : { id: id }, {
|
|
99
|
+
await this.msgRepo.update(base64_id ? { base64_id: base64_id } : { id: id }, {
|
|
100
|
+
recalled: true,
|
|
101
|
+
recall_time: new Date(),
|
|
102
|
+
});
|
|
100
103
|
else
|
|
101
104
|
throw new Error("base64_id 或 id 参数至少一个应该被赋值");
|
|
102
105
|
}
|
|
@@ -106,12 +109,7 @@ class Database {
|
|
|
106
109
|
async shrinkDB() {
|
|
107
110
|
let dt = new Date();
|
|
108
111
|
dt.setDate(dt.getDate() - this.msgHistoryPreserveDays);
|
|
109
|
-
await this.msgRepo
|
|
110
|
-
.createQueryBuilder()
|
|
111
|
-
.delete()
|
|
112
|
-
.from(db_entities_1.MsgEntry)
|
|
113
|
-
.where("create_time < :dt", { dt: dt })
|
|
114
|
-
.execute();
|
|
112
|
+
await this.msgRepo.createQueryBuilder().delete().from(db_entities_1.MsgEntry).where("create_time < :dt", { dt: dt }).execute();
|
|
115
113
|
}
|
|
116
114
|
}
|
|
117
115
|
exports.Database = Database;
|
|
@@ -1,18 +1,16 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
/// <reference types="node" />
|
|
3
|
-
import { Client } from "icqq";
|
|
4
|
-
import { Config } from "./config";
|
|
5
|
-
import { Action } from "./action";
|
|
6
2
|
import { OneBot } from "../../onebot";
|
|
3
|
+
import { Service } from "../../service";
|
|
4
|
+
import { Dispose } from "../../types";
|
|
5
|
+
import { Client } from "icqq";
|
|
7
6
|
import { Logger } from "log4js";
|
|
8
7
|
import { WebSocket, WebSocketServer } from "ws";
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
8
|
+
import { Action } from "./action";
|
|
9
|
+
import { Config } from "./config";
|
|
11
10
|
import { Database } from "./db_sqlite";
|
|
12
|
-
export declare class V11 extends
|
|
13
|
-
oneBot: OneBot<
|
|
11
|
+
export declare class V11 extends Service<"V11"> implements OneBot.Base {
|
|
12
|
+
oneBot: OneBot<"V11">;
|
|
14
13
|
client: Client;
|
|
15
|
-
config: V11.Config;
|
|
16
14
|
action: Action;
|
|
17
15
|
version: string;
|
|
18
16
|
protected timestamp: number;
|
|
@@ -28,7 +26,7 @@ export declare class V11 extends EventEmitter implements OneBot.Base {
|
|
|
28
26
|
logger: Logger;
|
|
29
27
|
wss?: WebSocketServer;
|
|
30
28
|
wsr: Set<WebSocket>;
|
|
31
|
-
constructor(oneBot: OneBot<
|
|
29
|
+
constructor(oneBot: OneBot<"V11">, client: Client, config: OneBot.Config<"V11">);
|
|
32
30
|
start(path?: string): void;
|
|
33
31
|
private startHttp;
|
|
34
32
|
private startHttpReverse;
|
|
@@ -75,9 +73,10 @@ export declare class V11 extends EventEmitter implements OneBot.Base {
|
|
|
75
73
|
export declare namespace V11 {
|
|
76
74
|
interface Result<T extends any> {
|
|
77
75
|
retcode: number;
|
|
78
|
-
status: "ok" |
|
|
76
|
+
status: "ok" | "async" | "error";
|
|
79
77
|
data: T;
|
|
80
78
|
error: string;
|
|
79
|
+
echo?: string;
|
|
81
80
|
}
|
|
82
81
|
function ok<T extends any>(data: T, retcode?: number, pending?: boolean): Result<T>;
|
|
83
82
|
function error(error: string, retcode?: number): Result<any>;
|
|
@@ -100,7 +99,7 @@ export declare namespace V11 {
|
|
|
100
99
|
enable_cors?: boolean;
|
|
101
100
|
enable_reissue?: boolean;
|
|
102
101
|
rate_limit_interval?: number;
|
|
103
|
-
post_message_format?:
|
|
102
|
+
post_message_format?: "string" | "array";
|
|
104
103
|
heartbeat?: number;
|
|
105
104
|
secret?: string;
|
|
106
105
|
reconnect_interval?: number;
|