onebots 0.4.28 → 0.4.30
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/lib/adapters/icqq/index.d.ts +2 -3
- package/lib/adapters/icqq/index.js +100 -56
- package/lib/adapters/qq/constans.d.ts +30 -30
- package/lib/adapters/qq/constans.js +6 -6
- package/lib/adapters/qq/elements.d.ts +1 -0
- package/lib/adapters/qq/sessionManager.js +3 -3
- package/lib/server/app.js +3 -3
- package/lib/service/V11/action/friend.d.ts +1 -1
- package/lib/service/V11/action/group.d.ts +1 -1
- package/lib/service/V11/index.d.ts +4 -3
- package/lib/service/V11/index.js +54 -68
- package/lib/service/V12/index.js +1 -1
- package/package.json +1 -1
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
import { Adapter } from "../../adapter";
|
|
2
2
|
import { App } from "../../server/app";
|
|
3
3
|
import { Config as IcqqConfig } from "icqq/lib/client";
|
|
4
|
-
import { Dict } from "@zhinjs/shared";
|
|
5
4
|
import { OneBot } from "../../onebot";
|
|
6
5
|
export default class IcqqAdapter extends Adapter<'icqq'> {
|
|
7
6
|
#private;
|
|
8
7
|
constructor(app: App, config: IcqqAdapter.Config);
|
|
9
|
-
createOneBot(uin: string, protocol:
|
|
8
|
+
createOneBot(uin: string, protocol: IcqqConfig, versions: OneBot.Config[]): OneBot;
|
|
10
9
|
formatEventPayload<V extends OneBot.Version>(version: V, event: string, data: any): OneBot.Payload<V>;
|
|
11
|
-
toMessageElement<V extends OneBot.Version>(event: any): OneBot.MessageElement<V>[];
|
|
12
10
|
sendPrivateMessage<V extends OneBot.Version>(uin: string, version: V, args: [string, OneBot.MessageElement<V>[]]): Promise<OneBot.MessageRet<V>>;
|
|
13
11
|
sendGroupMessage<V extends OneBot.Version>(uin: string, version: V, args: [string, OneBot.MessageElement<V>[]]): Promise<OneBot.MessageRet<V>>;
|
|
14
12
|
call<V extends OneBot.Version>(uin: string, version: V, method: string, args?: any[]): Promise<any>;
|
|
@@ -28,6 +26,7 @@ declare module '../../adapter' {
|
|
|
28
26
|
}
|
|
29
27
|
}
|
|
30
28
|
}
|
|
29
|
+
export declare const defaultIcqqConfig: IcqqConfig;
|
|
31
30
|
export declare namespace IcqqAdapter {
|
|
32
31
|
interface Config extends Adapter.Config<'icqq'> {
|
|
33
32
|
protocol?: IcqqConfig;
|
|
@@ -1,4 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
2
25
|
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
3
26
|
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
4
27
|
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
@@ -15,26 +38,55 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
15
38
|
};
|
|
16
39
|
var _IcqqAdapter_password, _IcqqAdapter_disposes;
|
|
17
40
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
41
|
+
exports.defaultIcqqConfig = void 0;
|
|
18
42
|
const adapter_1 = require("../../adapter");
|
|
19
43
|
const icqq_1 = require("icqq");
|
|
20
44
|
const process_1 = __importDefault(require("process"));
|
|
21
45
|
const fs_1 = require("fs");
|
|
22
46
|
const onebot_1 = require("../../onebot");
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
47
|
+
const utils_1 = require("../../utils");
|
|
48
|
+
const path = __importStar(require("path"));
|
|
49
|
+
const shareMusicCustom_1 = require("../../service/shareMusicCustom");
|
|
50
|
+
async function processMessages(target_id, target_type, list) {
|
|
51
|
+
let result = [];
|
|
52
|
+
for (const item of list) {
|
|
53
|
+
const { type, data, ...other } = item;
|
|
54
|
+
if (type === 'node') {
|
|
55
|
+
result.push({
|
|
28
56
|
type,
|
|
29
57
|
...data,
|
|
30
|
-
message: processMessages(data.message || [])
|
|
31
|
-
};
|
|
32
|
-
|
|
58
|
+
message: await processMessages.call(this, data.user_id, 'private', data.message || [])
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
if (type === 'music') {
|
|
62
|
+
if (String(item.data.platform) === 'custom') {
|
|
63
|
+
item.data.platform = item.data['subtype']; // gocq 的平台数据存储在 subtype 内,兼容 icqq 时要求前端必须发送 id 字段
|
|
64
|
+
}
|
|
65
|
+
const { type, data } = item;
|
|
66
|
+
await shareMusicCustom_1.shareMusic.call(this[target_type === 'private' ? 'pickFriend' : 'pickGroup'](target_id), {
|
|
67
|
+
type,
|
|
68
|
+
...data
|
|
69
|
+
});
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
if (type === 'share') {
|
|
73
|
+
await this[target_type === 'private' ? 'pickFriend' : 'pickGroup'](target_id).shareUrl(item.data);
|
|
74
|
+
continue;
|
|
75
|
+
}
|
|
76
|
+
if (['image', 'video', 'audio'].includes(item.type)) {
|
|
77
|
+
if (item['file_id']?.startsWith('base64://'))
|
|
78
|
+
item['file_id'] = Buffer.from(item['file_id'].slice(9), 'base64');
|
|
79
|
+
if (item['file']?.startsWith('base64://'))
|
|
80
|
+
item['file'] = Buffer.from(item['file'].slice(9), 'base64');
|
|
81
|
+
}
|
|
82
|
+
result.push({
|
|
33
83
|
type,
|
|
34
|
-
...data
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
84
|
+
...data,
|
|
85
|
+
...other
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
return result;
|
|
89
|
+
}
|
|
38
90
|
class IcqqAdapter extends adapter_1.Adapter {
|
|
39
91
|
constructor(app, config) {
|
|
40
92
|
super(app, 'icqq', config);
|
|
@@ -44,7 +96,7 @@ class IcqqAdapter extends adapter_1.Adapter {
|
|
|
44
96
|
createOneBot(uin, protocol, versions) {
|
|
45
97
|
const oneBot = super.createOneBot(uin, protocol, versions);
|
|
46
98
|
__classPrivateFieldSet(this, _IcqqAdapter_password, this.app.config[`icqq.${uin}`].password, "f");
|
|
47
|
-
oneBot.internal = new icqq_1.Client(protocol);
|
|
99
|
+
oneBot.internal = new icqq_1.Client((0, utils_1.deepMerge)(protocol, (0, utils_1.deepClone)(exports.defaultIcqqConfig)));
|
|
48
100
|
return oneBot;
|
|
49
101
|
}
|
|
50
102
|
formatEventPayload(version, event, data) {
|
|
@@ -59,48 +111,15 @@ class IcqqAdapter extends adapter_1.Adapter {
|
|
|
59
111
|
detail_type: data.message_type || data.notice_type || data.request_type,
|
|
60
112
|
platform: 'icqq',
|
|
61
113
|
...data,
|
|
62
|
-
message: this.toMessageElement(data)
|
|
63
114
|
};
|
|
64
115
|
}
|
|
65
|
-
|
|
66
|
-
if (!event || !event.message)
|
|
67
|
-
return null;
|
|
68
|
-
const messageArr = [].concat(event.message);
|
|
69
|
-
const result = [];
|
|
70
|
-
if (event.source) {
|
|
71
|
-
result.push({
|
|
72
|
-
type: 'quote',
|
|
73
|
-
data: {
|
|
74
|
-
id: `${event.source.rand}${event.source.seq}_${event.source.time}`,
|
|
75
|
-
}
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
for (const message of messageArr) {
|
|
79
|
-
if (typeof message === 'string') {
|
|
80
|
-
result.push({
|
|
81
|
-
type: 'text',
|
|
82
|
-
data: {
|
|
83
|
-
text: message
|
|
84
|
-
}
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
else {
|
|
88
|
-
const { type, ...data } = message;
|
|
89
|
-
result.push({
|
|
90
|
-
type,
|
|
91
|
-
data
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
return result;
|
|
96
|
-
}
|
|
97
|
-
sendPrivateMessage(uin, version, args) {
|
|
116
|
+
async sendPrivateMessage(uin, version, args) {
|
|
98
117
|
const [user_id, message] = args;
|
|
99
|
-
return this.oneBots.get(uin)?.internal.sendPrivateMsg(user_id, processMessages(message));
|
|
118
|
+
return this.oneBots.get(uin)?.internal.sendPrivateMsg(user_id, await processMessages.call(this, user_id, 'private', message));
|
|
100
119
|
}
|
|
101
|
-
sendGroupMessage(uin, version, args) {
|
|
120
|
+
async sendGroupMessage(uin, version, args) {
|
|
102
121
|
const [group_id, message] = args;
|
|
103
|
-
return this.oneBots.get(uin)?.internal.sendGroupMsg(group_id, processMessages(message));
|
|
122
|
+
return this.oneBots.get(uin)?.internal.sendGroupMsg(group_id, await processMessages.call(this, group_id, 'group', message));
|
|
104
123
|
}
|
|
105
124
|
call(uin, version, method, args = []) {
|
|
106
125
|
try {
|
|
@@ -121,10 +140,7 @@ class IcqqAdapter extends adapter_1.Adapter {
|
|
|
121
140
|
text: item
|
|
122
141
|
}
|
|
123
142
|
};
|
|
124
|
-
return
|
|
125
|
-
type: item.type,
|
|
126
|
-
data: item.data
|
|
127
|
-
};
|
|
143
|
+
return item;
|
|
128
144
|
});
|
|
129
145
|
}
|
|
130
146
|
toSegment(version, message) {
|
|
@@ -144,7 +160,7 @@ class IcqqAdapter extends adapter_1.Adapter {
|
|
|
144
160
|
});
|
|
145
161
|
}
|
|
146
162
|
fromCqcode(version, message) {
|
|
147
|
-
const regExpMatchArray = message.match(/\[CQ:([a-z]+),(!])+]/
|
|
163
|
+
const regExpMatchArray = message.match(/\[CQ:([a-z]+),(!])+]/);
|
|
148
164
|
if (!regExpMatchArray)
|
|
149
165
|
return [
|
|
150
166
|
{
|
|
@@ -155,7 +171,19 @@ class IcqqAdapter extends adapter_1.Adapter {
|
|
|
155
171
|
}
|
|
156
172
|
];
|
|
157
173
|
const result = [];
|
|
158
|
-
|
|
174
|
+
while (message.length) {
|
|
175
|
+
const [match] = message.match(/\[CQ:([a-z]+),(!])+]/) || [];
|
|
176
|
+
if (!match)
|
|
177
|
+
break;
|
|
178
|
+
const prevText = message.substring(0, match.length);
|
|
179
|
+
if (prevText) {
|
|
180
|
+
result.push({
|
|
181
|
+
type: 'text',
|
|
182
|
+
data: {
|
|
183
|
+
text: prevText
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
}
|
|
159
187
|
const [type, ...valueArr] = match.substring(1, match.length - 1).split(',');
|
|
160
188
|
result.push({
|
|
161
189
|
type: type,
|
|
@@ -164,11 +192,22 @@ class IcqqAdapter extends adapter_1.Adapter {
|
|
|
164
192
|
return [key, value];
|
|
165
193
|
}))
|
|
166
194
|
});
|
|
195
|
+
message = message.substring(match.length);
|
|
196
|
+
}
|
|
197
|
+
if (message.length) {
|
|
198
|
+
result.push({
|
|
199
|
+
type: 'text',
|
|
200
|
+
data: {
|
|
201
|
+
text: message
|
|
202
|
+
}
|
|
203
|
+
});
|
|
167
204
|
}
|
|
168
205
|
return result;
|
|
169
206
|
}
|
|
170
207
|
toCqcode(version, messageArr) {
|
|
171
208
|
return [].concat(messageArr).map(item => {
|
|
209
|
+
if (item.type === 'text')
|
|
210
|
+
return item.data.text;
|
|
172
211
|
const dataStr = Object.entries(item.data).map(([key, value]) => {
|
|
173
212
|
// is Buffer
|
|
174
213
|
if (value instanceof Buffer)
|
|
@@ -266,6 +305,7 @@ class IcqqAdapter extends adapter_1.Adapter {
|
|
|
266
305
|
}
|
|
267
306
|
};
|
|
268
307
|
client.trap('system.online', () => {
|
|
308
|
+
clearTimeout(timer);
|
|
269
309
|
resolve(clean);
|
|
270
310
|
});
|
|
271
311
|
const timer = setTimeout(() => {
|
|
@@ -301,3 +341,7 @@ class IcqqAdapter extends adapter_1.Adapter {
|
|
|
301
341
|
}
|
|
302
342
|
_IcqqAdapter_password = new WeakMap(), _IcqqAdapter_disposes = new WeakMap();
|
|
303
343
|
exports.default = IcqqAdapter;
|
|
344
|
+
exports.defaultIcqqConfig = {
|
|
345
|
+
platform: 2,
|
|
346
|
+
data_dir: path.join(process_1.default.cwd(), 'data')
|
|
347
|
+
};
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
export declare enum OpCode {
|
|
2
|
-
DISPATCH = 0
|
|
3
|
-
HEARTBEAT = 1
|
|
4
|
-
IDENTIFY = 2
|
|
5
|
-
RESUME = 6
|
|
6
|
-
RECONNECT = 7
|
|
7
|
-
INVALID_SESSION = 9
|
|
8
|
-
HELLO = 10
|
|
2
|
+
DISPATCH = 0,// 服务端进行消息推送
|
|
3
|
+
HEARTBEAT = 1,// 客户端发送心跳
|
|
4
|
+
IDENTIFY = 2,// 鉴权
|
|
5
|
+
RESUME = 6,// 恢复连接
|
|
6
|
+
RECONNECT = 7,// 服务端通知客户端重连
|
|
7
|
+
INVALID_SESSION = 9,// 当identify或resume的时候,如果参数有错,服务端会返回该消息
|
|
8
|
+
HELLO = 10,// 当客户端与网关建立ws连接之后,网关下发的第一条消息
|
|
9
9
|
HEARTBEAT_ACK = 11
|
|
10
10
|
}
|
|
11
11
|
export declare const SessionEvents: {
|
|
@@ -29,41 +29,41 @@ export declare const WebsocketCloseReason: ({
|
|
|
29
29
|
resume: boolean;
|
|
30
30
|
})[];
|
|
31
31
|
export declare enum Intends {
|
|
32
|
-
GUILDS = 1
|
|
33
|
-
GUILD_MEMBERS = 2
|
|
34
|
-
GUILD_MESSAGES = 512
|
|
35
|
-
GUILD_MESSAGE_REACTIONS = 1024
|
|
36
|
-
DIRECT_MESSAGE = 4096
|
|
32
|
+
GUILDS = 1,// 频道操作事件
|
|
33
|
+
GUILD_MEMBERS = 2,// 频道成员变更事件
|
|
34
|
+
GUILD_MESSAGES = 512,// 私域频道消息事件
|
|
35
|
+
GUILD_MESSAGE_REACTIONS = 1024,// 频道消息表态事件
|
|
36
|
+
DIRECT_MESSAGE = 4096,// 频道私信事件
|
|
37
37
|
OPEN_FORUMS_EVENTS = 262144,
|
|
38
|
-
AUDIO_OR_LIVE_CHANNEL_MEMBERS = 524288
|
|
39
|
-
C2C_MESSAGE_CREATE = 33554432
|
|
40
|
-
GROUP_AT_MESSAGE_CREATE = 33554432
|
|
41
|
-
INTERACTION = 67108864
|
|
42
|
-
MESSAGE_AUDIT = 134217728
|
|
43
|
-
FORUMS_EVENTS = 268435456
|
|
44
|
-
AUDIO_ACTIONS = 536870912
|
|
38
|
+
AUDIO_OR_LIVE_CHANNEL_MEMBERS = 524288,// 音频或直播频道成员
|
|
39
|
+
C2C_MESSAGE_CREATE = 33554432,// 私聊消息事件
|
|
40
|
+
GROUP_AT_MESSAGE_CREATE = 33554432,// 群聊@消息事件
|
|
41
|
+
INTERACTION = 67108864,// 互动事件
|
|
42
|
+
MESSAGE_AUDIT = 134217728,// 消息审核事件
|
|
43
|
+
FORUMS_EVENTS = 268435456,// 论坛事件(仅私域)
|
|
44
|
+
AUDIO_ACTIONS = 536870912,// 音频操作事件
|
|
45
45
|
PUBLIC_GUILD_MESSAGES = 1073741824
|
|
46
46
|
}
|
|
47
47
|
export declare enum ChannelType {
|
|
48
|
-
Content = 0
|
|
49
|
-
Record = 2
|
|
50
|
-
ChannelGroup = 4
|
|
51
|
-
Live = 10005
|
|
52
|
-
App = 10006
|
|
48
|
+
Content = 0,// 文本频道
|
|
49
|
+
Record = 2,// 语音频道
|
|
50
|
+
ChannelGroup = 4,// 频道分组
|
|
51
|
+
Live = 10005,// 直播频道
|
|
52
|
+
App = 10006,// 应用频道
|
|
53
53
|
Forms = 10007
|
|
54
54
|
}
|
|
55
55
|
export declare enum ChannelSubType {
|
|
56
|
-
Chat = 0
|
|
57
|
-
Announces = 1
|
|
58
|
-
Strategy = 2
|
|
56
|
+
Chat = 0,// 闲聊
|
|
57
|
+
Announces = 1,// 公告
|
|
58
|
+
Strategy = 2,// 攻略
|
|
59
59
|
Black = 3
|
|
60
60
|
}
|
|
61
61
|
export declare enum PrivateType {
|
|
62
|
-
Public = 0
|
|
63
|
-
Admin = 1
|
|
62
|
+
Public = 0,// 公开
|
|
63
|
+
Admin = 1,// 频道主和管理员
|
|
64
64
|
Some = 2
|
|
65
65
|
}
|
|
66
66
|
export declare enum SpeakPermission {
|
|
67
|
-
All = 1
|
|
67
|
+
All = 1,// 所有人
|
|
68
68
|
Some = 2
|
|
69
69
|
}
|
|
@@ -15,13 +15,13 @@ var OpCode;
|
|
|
15
15
|
})(OpCode || (exports.OpCode = OpCode = {}));
|
|
16
16
|
exports.SessionEvents = {
|
|
17
17
|
CLOSED: "CLOSED",
|
|
18
|
-
READY: "READY",
|
|
19
|
-
ERROR: "ERROR",
|
|
18
|
+
READY: "READY", // 已经可以通信
|
|
19
|
+
ERROR: "ERROR", // 会话错误
|
|
20
20
|
INVALID_SESSION: "INVALID_SESSION",
|
|
21
|
-
RECONNECT: "RECONNECT",
|
|
22
|
-
DISCONNECT: "DISCONNECT",
|
|
23
|
-
EVENT_WS: "EVENT_WS",
|
|
24
|
-
RESUMED: "RESUMED",
|
|
21
|
+
RECONNECT: "RECONNECT", // 服务端通知重新连接
|
|
22
|
+
DISCONNECT: "DISCONNECT", // 断线
|
|
23
|
+
EVENT_WS: "EVENT_WS", // 内部通信
|
|
24
|
+
RESUMED: "RESUMED", // 重连
|
|
25
25
|
DEAD: "DEAD" // 连接已死亡,请检查网络或重启
|
|
26
26
|
};
|
|
27
27
|
// websocket错误原因
|
|
@@ -155,11 +155,11 @@ class SessionManager extends events_1.EventEmitter {
|
|
|
155
155
|
authWs() {
|
|
156
156
|
// 鉴权参数
|
|
157
157
|
const authOp = {
|
|
158
|
-
op: constans_1.OpCode.IDENTIFY,
|
|
158
|
+
op: constans_1.OpCode.IDENTIFY, // 鉴权参数
|
|
159
159
|
d: {
|
|
160
160
|
// token: `Bot ${this.bot.appId}${this.token}`,
|
|
161
|
-
token: `QQBot ${this.access_token}`,
|
|
162
|
-
intents: this.getValidIntends(),
|
|
161
|
+
token: `QQBot ${this.access_token}`, // 根据配置转换token
|
|
162
|
+
intents: this.getValidIntends(), // todo 接受的类型
|
|
163
163
|
shard: [0, 1] // 分片信息,给一个默认值
|
|
164
164
|
}
|
|
165
165
|
};
|
package/lib/server/app.js
CHANGED
|
@@ -252,9 +252,9 @@ exports.defineConfig = defineConfig;
|
|
|
252
252
|
App.registerAdapter = registerAdapter;
|
|
253
253
|
function loadAdapter(platform) {
|
|
254
254
|
const maybeNames = [
|
|
255
|
-
path.join(__dirname, '../adapters', platform),
|
|
256
|
-
`@onebots/adapter-${platform}`,
|
|
257
|
-
`onebots-adapter-${platform}`,
|
|
255
|
+
path.join(__dirname, '../adapters', platform), // 内置的
|
|
256
|
+
`@onebots/adapter-${platform}`, // 我写的
|
|
257
|
+
`onebots-adapter-${platform}`, // 别人按照规范写的
|
|
258
258
|
platform // 别人写的
|
|
259
259
|
];
|
|
260
260
|
let adapter = null;
|
|
@@ -6,7 +6,7 @@ export declare class FriendAction {
|
|
|
6
6
|
* @param message {MessageElem[]} 发送的消息
|
|
7
7
|
* @param message_id {string} 引用的消息ID
|
|
8
8
|
*/
|
|
9
|
-
sendPrivateMsg(this: V11, user_id: number, message: V11.
|
|
9
|
+
sendPrivateMsg(this: V11, user_id: number, message: V11.Sendable, message_id?: string): Promise<any>;
|
|
10
10
|
/**
|
|
11
11
|
* 获取好友列表
|
|
12
12
|
*/
|
|
@@ -6,7 +6,7 @@ export declare class GroupAction {
|
|
|
6
6
|
* @param message {MessageElem[]} 消息
|
|
7
7
|
* @param message_id {string} 引用的消息ID
|
|
8
8
|
*/
|
|
9
|
-
sendGroupMsg(this: V11, group_id: number, message: V11.
|
|
9
|
+
sendGroupMsg(this: V11, group_id: number, message: V11.Sendable, message_id?: string): Promise<any>;
|
|
10
10
|
/**
|
|
11
11
|
* 群组踢人
|
|
12
12
|
* @param group_id {number} 群id
|
|
@@ -9,8 +9,8 @@ import { Database } from "./db_sqlite";
|
|
|
9
9
|
import { Service } from "../../service";
|
|
10
10
|
import { Dict } from "@zhinjs/shared";
|
|
11
11
|
export declare class V11 extends Service<"V11"> implements OneBot.Base {
|
|
12
|
-
oneBot: OneBot<
|
|
13
|
-
config: OneBot.Config<
|
|
12
|
+
oneBot: OneBot<"V11">;
|
|
13
|
+
config: OneBot.Config<"V11">;
|
|
14
14
|
action: Action;
|
|
15
15
|
version: OneBot.Version;
|
|
16
16
|
protected timestamp: number;
|
|
@@ -25,7 +25,7 @@ export declare class V11 extends Service<"V11"> implements OneBot.Base {
|
|
|
25
25
|
logger: Logger;
|
|
26
26
|
wss?: WebSocketServer;
|
|
27
27
|
wsr: Set<WebSocket>;
|
|
28
|
-
constructor(oneBot: OneBot<
|
|
28
|
+
constructor(oneBot: OneBot<"V11">, config: OneBot.Config<"V11">);
|
|
29
29
|
start(): void;
|
|
30
30
|
private startHttp;
|
|
31
31
|
private startHttpReverse;
|
|
@@ -136,6 +136,7 @@ export declare namespace V11 {
|
|
|
136
136
|
type: string;
|
|
137
137
|
data: Dict;
|
|
138
138
|
}
|
|
139
|
+
type Sendable = string | MessageElement | (string | MessageElement)[];
|
|
139
140
|
interface MessageRet {
|
|
140
141
|
message_id: number;
|
|
141
142
|
}
|
package/lib/service/V11/index.js
CHANGED
|
@@ -25,22 +25,22 @@ class V11 extends service_1.Service {
|
|
|
25
25
|
super(oneBot.adapter, config);
|
|
26
26
|
this.oneBot = oneBot;
|
|
27
27
|
this.config = config;
|
|
28
|
-
this.version =
|
|
28
|
+
this.version = "V11";
|
|
29
29
|
this.timestamp = Date.now();
|
|
30
30
|
this._queue = [];
|
|
31
31
|
this.queue_running = false;
|
|
32
32
|
this.wsr = new Set();
|
|
33
33
|
this.action = new action_1.Action();
|
|
34
34
|
this.logger = this.oneBot.adapter.getLogger(this.oneBot.uin, this.version);
|
|
35
|
-
this.db = new db_sqlite_1.Database((0, path_1.join)(app_1.App.configDir,
|
|
36
|
-
this.oneBot.on(
|
|
35
|
+
this.db = new db_sqlite_1.Database((0, path_1.join)(app_1.App.configDir, "data", this.oneBot.uin + ".db"), this.logger);
|
|
36
|
+
this.oneBot.on("online", async () => {
|
|
37
37
|
this.logger.info("【好友列表】");
|
|
38
|
-
const friendList = await this.oneBot.getFriendList(
|
|
38
|
+
const friendList = await this.oneBot.getFriendList("V11");
|
|
39
39
|
friendList.forEach((item) => this.logger.info(`\t${item.user_name}(${item.user_id})`));
|
|
40
40
|
this.logger.info("【群列表】");
|
|
41
|
-
const groupList = await this.oneBot.getGroupList(
|
|
41
|
+
const groupList = await this.oneBot.getGroupList("V11");
|
|
42
42
|
groupList.forEach(item => this.logger.info(`\t${item.group_name}(${item.group_id})`));
|
|
43
|
-
this.logger.info(
|
|
43
|
+
this.logger.info("");
|
|
44
44
|
});
|
|
45
45
|
}
|
|
46
46
|
start() {
|
|
@@ -53,14 +53,14 @@ class V11 extends service_1.Service {
|
|
|
53
53
|
config = {
|
|
54
54
|
url: config,
|
|
55
55
|
access_token: this.config.access_token,
|
|
56
|
-
secret: this.config.secret
|
|
56
|
+
secret: this.config.secret
|
|
57
57
|
};
|
|
58
58
|
}
|
|
59
59
|
else {
|
|
60
60
|
config = {
|
|
61
61
|
access_token: this.config.access_token,
|
|
62
62
|
secret: this.config.secret,
|
|
63
|
-
...config
|
|
63
|
+
...config
|
|
64
64
|
};
|
|
65
65
|
}
|
|
66
66
|
this.startHttpReverse(config);
|
|
@@ -69,26 +69,7 @@ class V11 extends service_1.Service {
|
|
|
69
69
|
this.startWsReverse(config);
|
|
70
70
|
});
|
|
71
71
|
this.on("dispatch", (serialized) => {
|
|
72
|
-
for (const ws of this.wss
|
|
73
|
-
ws.send(serialized, (err) => {
|
|
74
|
-
if (err)
|
|
75
|
-
this.logger.error(`正向WS(${ws.url})上报事件失败: ` + err.message);
|
|
76
|
-
else
|
|
77
|
-
this.logger.debug(`正向WS(${ws.url})上报事件成功: ` + serialized);
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
for (const ws of this.wsr) {
|
|
81
|
-
ws.send(serialized, (err) => {
|
|
82
|
-
if (err) {
|
|
83
|
-
this.logger.error(`反向WS(${ws.url})上报事件失败: ` + err.message);
|
|
84
|
-
}
|
|
85
|
-
else
|
|
86
|
-
this.logger.debug(`反向WS(${ws.url})上报事件成功: ` + serialized);
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
});
|
|
90
|
-
this.on("dispatch", (serialized) => {
|
|
91
|
-
for (const ws of this.wss.clients) {
|
|
72
|
+
for (const ws of this.wss?.clients) {
|
|
92
73
|
ws.send(serialized, (err) => {
|
|
93
74
|
if (err)
|
|
94
75
|
this.logger.error(`正向WS(${ws.url})上报事件失败: ` + err.message);
|
|
@@ -111,26 +92,26 @@ class V11 extends service_1.Service {
|
|
|
111
92
|
this.dispatch({
|
|
112
93
|
self_id: this.oneBot.uin,
|
|
113
94
|
status: {
|
|
114
|
-
online: this.adapter.getSelfInfo(this.oneBot.uin,
|
|
95
|
+
online: this.adapter.getSelfInfo(this.oneBot.uin, "V11").status === onebot_1.OneBotStatus.Online,
|
|
115
96
|
good: this.oneBot.status === onebot_1.OneBotStatus.Good
|
|
116
97
|
},
|
|
117
98
|
time: Math.floor(Date.now() / 1000),
|
|
118
99
|
post_type: "meta_event",
|
|
119
100
|
meta_event_type: "heartbeat",
|
|
120
|
-
interval: this.config.heartbeat * 1000
|
|
101
|
+
interval: this.config.heartbeat * 1000
|
|
121
102
|
});
|
|
122
103
|
}, this.config.heartbeat * 1000);
|
|
123
104
|
}
|
|
124
|
-
this.adapter.on(
|
|
125
|
-
const payload = this.adapter.formatEventPayload(
|
|
105
|
+
this.adapter.on("message.receive", (uin, event) => {
|
|
106
|
+
const payload = this.adapter.formatEventPayload("V11", "message", event);
|
|
126
107
|
this.dispatch(payload);
|
|
127
108
|
});
|
|
128
|
-
this.adapter.on(
|
|
129
|
-
const payload = this.adapter.formatEventPayload(
|
|
109
|
+
this.adapter.on("notice.receive", (uin, event) => {
|
|
110
|
+
const payload = this.adapter.formatEventPayload("V11", "notice", event);
|
|
130
111
|
this.dispatch(payload);
|
|
131
112
|
});
|
|
132
|
-
this.adapter.on(
|
|
133
|
-
const payload = this.adapter.formatEventPayload(
|
|
113
|
+
this.adapter.on("request.receive", (uin, event) => {
|
|
114
|
+
const payload = this.adapter.formatEventPayload("V11", "request", event);
|
|
134
115
|
this.dispatch(payload);
|
|
135
116
|
});
|
|
136
117
|
}
|
|
@@ -147,8 +128,8 @@ class V11 extends service_1.Service {
|
|
|
147
128
|
"Content-Type": "application/json",
|
|
148
129
|
"Content-Length": Buffer.byteLength(serialized),
|
|
149
130
|
"X-Self-ID": String(this.oneBot.uin),
|
|
150
|
-
"User-Agent": "OneBot"
|
|
151
|
-
}
|
|
131
|
+
"User-Agent": "OneBot"
|
|
132
|
+
}
|
|
152
133
|
};
|
|
153
134
|
if (this.config.secret) {
|
|
154
135
|
//@ts-ignore
|
|
@@ -230,10 +211,10 @@ class V11 extends service_1.Service {
|
|
|
230
211
|
return data;
|
|
231
212
|
}
|
|
232
213
|
async dispatch(data) {
|
|
233
|
-
data.post_type = data.post_type ||
|
|
234
|
-
if (data.message && data.post_type ===
|
|
235
|
-
if (this.config.post_message_format ===
|
|
236
|
-
data.message = this.adapter.toSegment(
|
|
214
|
+
data.post_type = data.post_type || "system";
|
|
215
|
+
if (data.message && data.post_type === "message") {
|
|
216
|
+
if (this.config.post_message_format === "array") {
|
|
217
|
+
data.message = this.adapter.toSegment("V11", data.message);
|
|
237
218
|
if (data.source) { // reply
|
|
238
219
|
let msg0 = data.message[0];
|
|
239
220
|
msg0.data["id"] = await this.getReplyMsgIdFromDB(data);
|
|
@@ -262,15 +243,15 @@ class V11 extends service_1.Service {
|
|
|
262
243
|
this.emit("dispatch", this._formatEvent(data));
|
|
263
244
|
}
|
|
264
245
|
_formatEvent(data) {
|
|
265
|
-
if (data.post_type ===
|
|
246
|
+
if (data.post_type === "notice") {
|
|
266
247
|
// console.log(JSON.stringify(data))
|
|
267
248
|
const data1 = { ...data };
|
|
268
249
|
if (data.notice_type === "group") {
|
|
269
250
|
delete data1.group;
|
|
270
251
|
delete data1.member;
|
|
271
252
|
switch (data.sub_type) {
|
|
272
|
-
case
|
|
273
|
-
data1.sub_type = data.operator_id === data.user_id ?
|
|
253
|
+
case "decrease":
|
|
254
|
+
data1.sub_type = data.operator_id === data.user_id ? "leave" : data.user_id === this.oneBot.uin ? "kick_me" : "kick";
|
|
274
255
|
data1.notice_type = `${data.notice_type}_${data.sub_type}`;
|
|
275
256
|
break;
|
|
276
257
|
case "increase":
|
|
@@ -369,7 +350,7 @@ class V11 extends service_1.Service {
|
|
|
369
350
|
.writeHead(200, {
|
|
370
351
|
"Access-Control-Allow-Origin": "*",
|
|
371
352
|
"Access-Control-Allow-Methods": "POST, GET, OPTIONS",
|
|
372
|
-
"Access-Control-Allow-Headers": "Content-Type, authorization"
|
|
353
|
+
"Access-Control-Allow-Headers": "Content-Type, authorization"
|
|
373
354
|
})
|
|
374
355
|
.end();
|
|
375
356
|
}
|
|
@@ -404,7 +385,7 @@ class V11 extends service_1.Service {
|
|
|
404
385
|
try {
|
|
405
386
|
const params = {
|
|
406
387
|
...(ctx.request.query || {}),
|
|
407
|
-
...(ctx.request.body || {})
|
|
388
|
+
...(ctx.request.body || {})
|
|
408
389
|
};
|
|
409
390
|
const ret = await this.apply({ action, params });
|
|
410
391
|
ctx.res.writeHead(200).end(ret);
|
|
@@ -436,7 +417,7 @@ class V11 extends service_1.Service {
|
|
|
436
417
|
status: "async",
|
|
437
418
|
data: null,
|
|
438
419
|
error: null,
|
|
439
|
-
echo: data.echo
|
|
420
|
+
echo: data.echo
|
|
440
421
|
});
|
|
441
422
|
}
|
|
442
423
|
else {
|
|
@@ -460,11 +441,11 @@ class V11 extends service_1.Service {
|
|
|
460
441
|
data: null,
|
|
461
442
|
error: {
|
|
462
443
|
code,
|
|
463
|
-
message
|
|
444
|
+
message
|
|
464
445
|
},
|
|
465
446
|
echo: data?.echo,
|
|
466
|
-
msg: e.message,
|
|
467
|
-
action: data.action
|
|
447
|
+
msg: e.message, // gocq 返回的消息里有这个字段且很多插件都在访问
|
|
448
|
+
action: data.action
|
|
468
449
|
}));
|
|
469
450
|
}
|
|
470
451
|
});
|
|
@@ -479,7 +460,7 @@ class V11 extends service_1.Service {
|
|
|
479
460
|
const headers = {
|
|
480
461
|
"X-Self-ID": String(this.oneBot.uin),
|
|
481
462
|
"X-Client-Role": "Universal",
|
|
482
|
-
"User-Agent": "OneBot"
|
|
463
|
+
"User-Agent": "OneBot"
|
|
483
464
|
};
|
|
484
465
|
if (this.config.access_token)
|
|
485
466
|
headers.Authorization = "Bearer " + this.config.access_token;
|
|
@@ -518,16 +499,16 @@ class V11 extends service_1.Service {
|
|
|
518
499
|
}
|
|
519
500
|
if (event.message_type === "group") {
|
|
520
501
|
if (res.delete)
|
|
521
|
-
this.adapter.deleteMessage(this.oneBot.uin,
|
|
502
|
+
this.adapter.deleteMessage(this.oneBot.uin, "V11", [event.message_id]);
|
|
522
503
|
if (res.kick && !event.anonymous)
|
|
523
|
-
this.adapter.call(this.oneBot.uin,
|
|
504
|
+
this.adapter.call(this.oneBot.uin, "V11", "setGroupKick", [event.group_id, event.user_id, res.reject_add_request]);
|
|
524
505
|
if (res.ban)
|
|
525
|
-
this.adapter.call(this.oneBot.uin,
|
|
506
|
+
this.adapter.call(this.oneBot.uin, "V11", "setGroupBan", [event.group_id, event.user_id, res.ban_duration > 0 ? res.ban_duration : 1800]);
|
|
526
507
|
}
|
|
527
508
|
}
|
|
528
509
|
if (event.post_type === "request" && "approve" in res) {
|
|
529
510
|
const action = event.request_type === "friend" ? "setFriendAddRequest" : "setGroupAddRequest";
|
|
530
|
-
this.adapter.call(this.oneBot.uin,
|
|
511
|
+
this.adapter.call(this.oneBot.uin, "V11", action, [event.flag, res.approve, res.reason ? res.reason : "", !!res.block]);
|
|
531
512
|
}
|
|
532
513
|
}
|
|
533
514
|
/**
|
|
@@ -535,6 +516,9 @@ class V11 extends service_1.Service {
|
|
|
535
516
|
*/
|
|
536
517
|
async apply(req) {
|
|
537
518
|
let { action, params, echo } = req;
|
|
519
|
+
if (typeof params.message_id == "number" || /^\d+$/.test(params.message_id)) {
|
|
520
|
+
params.message_id = (await this.db.getMsgById(params.message_id)).id; // 调用api时把本地的数字id转为base64发给icqq
|
|
521
|
+
}
|
|
538
522
|
action = (0, utils_1.toLine)(action);
|
|
539
523
|
let is_async = action.includes("_async");
|
|
540
524
|
if (is_async)
|
|
@@ -551,6 +535,8 @@ class V11 extends service_1.Service {
|
|
|
551
535
|
action = "send_group_msg";
|
|
552
536
|
else if (params.discuss_id)
|
|
553
537
|
action = "send_discuss_msg";
|
|
538
|
+
else if (params.guild_id)
|
|
539
|
+
action = params.channel_id === "direct" ? "send_direct_msg" : "send_group_msg";
|
|
554
540
|
else
|
|
555
541
|
throw new Error("required message_type or input (user_id/group_id)");
|
|
556
542
|
}
|
|
@@ -569,21 +555,21 @@ class V11 extends service_1.Service {
|
|
|
569
555
|
if (Reflect.has(params, k)) {
|
|
570
556
|
if (onebot_2.BOOLS.includes(k))
|
|
571
557
|
params[k] = (0, utils_1.toBool)(params[k]);
|
|
572
|
-
if (k ===
|
|
573
|
-
if (typeof params[k] ===
|
|
558
|
+
if (k === "message") {
|
|
559
|
+
if (typeof params[k] === "string") {
|
|
574
560
|
if (/[CQ:music,type=.+,id=.+]/.test(params[k])) {
|
|
575
|
-
params[k] = params[k].replace(
|
|
561
|
+
params[k] = params[k].replace(",type=", ",platform=");
|
|
576
562
|
}
|
|
577
|
-
params[k] = this.adapter.fromCqcode(
|
|
563
|
+
params[k] = this.adapter.fromCqcode("V11", params[k]);
|
|
578
564
|
}
|
|
579
565
|
else {
|
|
580
|
-
if (params[k][0].type ==
|
|
566
|
+
if (params[k][0].type == "music" && params[k][0]?.data?.type) {
|
|
581
567
|
params[k][0].data.platform = params[k][0].data.type;
|
|
582
568
|
delete params[k][0].data.type;
|
|
583
569
|
}
|
|
584
|
-
params[k] = this.adapter.fromSegment(
|
|
570
|
+
params[k] = this.adapter.fromSegment("V11", params[k]);
|
|
585
571
|
}
|
|
586
|
-
params[
|
|
572
|
+
params["message_id"] = params[k].find(e => e.type === "reply")?.message_id;
|
|
587
573
|
}
|
|
588
574
|
args.push(params[k]);
|
|
589
575
|
}
|
|
@@ -616,7 +602,7 @@ class V11 extends service_1.Service {
|
|
|
616
602
|
if (result.data instanceof Map)
|
|
617
603
|
result.data = [...result.data.values()];
|
|
618
604
|
if (result.data?.message)
|
|
619
|
-
result.data.message = this.adapter.toSegment(
|
|
605
|
+
result.data.message = this.adapter.toSegment("V11", result.data.message);
|
|
620
606
|
// send_msg_xxx 时提前把数据写入数据库(也有可能来的比message慢,后来的话会被数据库忽略)
|
|
621
607
|
if (result.status === "ok" && action.match(sendMsgMethodRegex) && result.data?.message_id && result.data?.seq) {
|
|
622
608
|
result.data.message_id = await this.addMsgToDBFromSendMsgResult(this.oneBot.uin, // msg send resp uin is always bot uin
|
|
@@ -653,7 +639,7 @@ exports.V11 = V11;
|
|
|
653
639
|
retcode,
|
|
654
640
|
status: pending ? "async" : "ok",
|
|
655
641
|
data,
|
|
656
|
-
error: null
|
|
642
|
+
error: null
|
|
657
643
|
};
|
|
658
644
|
}
|
|
659
645
|
V11.ok = ok;
|
|
@@ -662,7 +648,7 @@ exports.V11 = V11;
|
|
|
662
648
|
retcode,
|
|
663
649
|
status: "error",
|
|
664
650
|
data: null,
|
|
665
|
-
error
|
|
651
|
+
error
|
|
666
652
|
};
|
|
667
653
|
}
|
|
668
654
|
V11.error = error;
|
|
@@ -679,7 +665,7 @@ exports.V11 = V11;
|
|
|
679
665
|
enable_reissue: false,
|
|
680
666
|
use_ws: true,
|
|
681
667
|
http_reverse: [],
|
|
682
|
-
ws_reverse: []
|
|
668
|
+
ws_reverse: []
|
|
683
669
|
};
|
|
684
670
|
function genMetaEvent(uin, type) {
|
|
685
671
|
return {
|
|
@@ -687,7 +673,7 @@ exports.V11 = V11;
|
|
|
687
673
|
time: Math.floor(Date.now() / 1000),
|
|
688
674
|
post_type: "meta_event",
|
|
689
675
|
meta_event_type: "lifecycle",
|
|
690
|
-
sub_type: type
|
|
676
|
+
sub_type: type
|
|
691
677
|
};
|
|
692
678
|
}
|
|
693
679
|
V11.genMetaEvent = genMetaEvent;
|
package/lib/service/V12/index.js
CHANGED
|
@@ -106,7 +106,7 @@ class V12 extends service_1.Service {
|
|
|
106
106
|
});
|
|
107
107
|
this.on('dispatch', (unserialized) => {
|
|
108
108
|
const serialized = JSON.stringify(unserialized);
|
|
109
|
-
for (const ws of this.wss
|
|
109
|
+
for (const ws of this.wss?.clients) {
|
|
110
110
|
ws.send(serialized, (err) => {
|
|
111
111
|
if (err)
|
|
112
112
|
this.logger.error(`正向WS(${ws.url})上报事件失败: ` + err.message);
|