onebots 0.4.43 → 0.4.45
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/dist/assets/index-VSQZ6fYD.js +3 -0
- package/dist/index.html +1 -1
- package/lib/adapter.d.ts +6 -3
- package/lib/adapters/dingtalk/index.d.ts +4 -3
- package/lib/adapters/dingtalk/index.js +30 -3
- package/lib/adapters/icqq/index.d.ts +5 -3
- package/lib/adapters/icqq/index.js +94 -40
- package/lib/adapters/qq/index.d.ts +6 -1
- package/lib/adapters/qq/index.js +81 -1
- package/lib/adapters/wechat/index.d.ts +6 -3
- package/lib/adapters/wechat/index.js +67 -3
- package/lib/db.js +1 -1
- package/lib/onebot.d.ts +2 -0
- package/lib/onebot.js +7 -1
- package/lib/server/app.d.ts +3 -2
- package/lib/server/app.js +15 -6
- package/lib/service/V11/action/common.js +2 -6
- package/lib/service/V11/action/friend.d.ts +3 -3
- package/lib/service/V11/action/friend.js +5 -3
- package/lib/service/V11/action/group.d.ts +3 -3
- package/lib/service/V11/action/group.js +5 -3
- package/lib/service/V11/index.d.ts +3 -10
- package/lib/service/V11/index.js +39 -85
- package/lib/service/V12/action/friend.d.ts +4 -4
- package/lib/service/V12/action/friend.js +2 -2
- package/lib/service/V12/action/group.d.ts +3 -3
- package/lib/service/V12/action/group.js +2 -2
- package/lib/service/V12/action/guild.d.ts +5 -5
- package/lib/service/V12/action/guild.js +7 -10
- package/lib/service/V12/index.js +9 -7
- package/package.json +3 -3
- package/dist/assets/index-LkcQDeZE.js +0 -3
|
@@ -47,43 +47,59 @@ const onebot_1 = require("../../onebot");
|
|
|
47
47
|
const utils_1 = require("../../utils");
|
|
48
48
|
const path = __importStar(require("path"));
|
|
49
49
|
const shareMusicCustom_1 = require("../../service/shareMusicCustom");
|
|
50
|
-
|
|
50
|
+
const message_1 = require("icqq/lib/message");
|
|
51
|
+
async function processMessages(uin, target_id, target_type, list) {
|
|
51
52
|
let result = [];
|
|
52
53
|
for (const item of list) {
|
|
53
54
|
const { type, data, ...other } = item;
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
55
|
+
switch (type) {
|
|
56
|
+
case 'node': {
|
|
57
|
+
result.push({
|
|
58
|
+
type,
|
|
59
|
+
...data,
|
|
60
|
+
message: await processMessages.call(this, uin, data.user_id, 'private', data.content || [])
|
|
61
|
+
});
|
|
62
|
+
break;
|
|
63
|
+
}
|
|
64
|
+
case 'music': {
|
|
65
|
+
if (String(item.data.platform) === 'custom') {
|
|
66
|
+
item.data.platform = item.data['subtype']; // gocq 的平台数据存储在 subtype 内,兼容 icqq 时要求前端必须发送 id 字段
|
|
67
|
+
}
|
|
68
|
+
const { type, data } = item;
|
|
69
|
+
await shareMusicCustom_1.shareMusic.call(this[target_type === 'private' ? 'pickFriend' : 'pickGroup'](target_id), {
|
|
70
|
+
type,
|
|
71
|
+
...data
|
|
72
|
+
});
|
|
73
|
+
break;
|
|
74
|
+
}
|
|
75
|
+
case 'share': {
|
|
76
|
+
await this[target_type === 'private' ? 'pickFriend' : 'pickGroup'](target_id).shareUrl(item.data);
|
|
77
|
+
break;
|
|
78
|
+
}
|
|
79
|
+
case 'video':
|
|
80
|
+
case 'audio':
|
|
81
|
+
case 'image': {
|
|
82
|
+
if (item['file_id']?.startsWith('base64://'))
|
|
83
|
+
item['file_id'] = Buffer.from(item['file_id'].slice(9), 'base64');
|
|
84
|
+
if (item['file']?.startsWith('base64://'))
|
|
85
|
+
item['file'] = Buffer.from(item['file'].slice(9), 'base64');
|
|
86
|
+
result.push({
|
|
87
|
+
type,
|
|
88
|
+
...data,
|
|
89
|
+
...other
|
|
90
|
+
});
|
|
91
|
+
break;
|
|
92
|
+
}
|
|
93
|
+
case 'reply': {
|
|
94
|
+
const oneBot = this.getOneBot(uin);
|
|
95
|
+
const message_id = oneBot.V11.getStrByInt('message_id', data.id);
|
|
96
|
+
const msg = await oneBot.internal.getMsg(message_id);
|
|
97
|
+
result.push({
|
|
98
|
+
type: 'quote',
|
|
99
|
+
...msg
|
|
100
|
+
});
|
|
64
101
|
}
|
|
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
102
|
}
|
|
82
|
-
result.push({
|
|
83
|
-
type,
|
|
84
|
-
...data,
|
|
85
|
-
...other
|
|
86
|
-
});
|
|
87
103
|
}
|
|
88
104
|
return result;
|
|
89
105
|
}
|
|
@@ -120,27 +136,65 @@ class IcqqAdapter extends adapter_1.Adapter {
|
|
|
120
136
|
})));
|
|
121
137
|
return oneBot;
|
|
122
138
|
}
|
|
123
|
-
formatEventPayload(version, event, data) {
|
|
124
|
-
|
|
139
|
+
formatEventPayload(uin, version, event, data) {
|
|
140
|
+
const oneBot = this.getOneBot(uin);
|
|
141
|
+
const result = {
|
|
125
142
|
id: data.id,
|
|
126
143
|
type: event,
|
|
127
144
|
version: version,
|
|
128
145
|
self: {
|
|
129
|
-
platform: '
|
|
146
|
+
platform: 'qq',
|
|
130
147
|
user_id: data.self_id
|
|
131
148
|
},
|
|
132
149
|
detail_type: data.message_type || data.notice_type || data.request_type,
|
|
133
|
-
platform: '
|
|
150
|
+
platform: 'qq',
|
|
134
151
|
...data,
|
|
135
152
|
};
|
|
153
|
+
if (data.source) {
|
|
154
|
+
const message_id = data.message_type === 'group' ? (0, message_1.genGroupMessageId)(data.group_id, data.sender.user_id, data.source?.seq, data.source?.rand, data.source?.time, data.source?.pktnum) :
|
|
155
|
+
(0, message_1.genDmMessageId)(data.sender.user_id, data.source?.seq, data.source?.rand, data.source?.time);
|
|
156
|
+
data.message[0] = {
|
|
157
|
+
type: 'reply',
|
|
158
|
+
id: version === 'V11' ? oneBot.V11.transformToInt('message_id', message_id) : message_id,
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
return result;
|
|
136
162
|
}
|
|
137
163
|
async sendPrivateMessage(uin, version, args) {
|
|
138
|
-
const [user_id, message] = args;
|
|
139
|
-
|
|
164
|
+
const [user_id, message, source] = args;
|
|
165
|
+
const client = this.oneBots.get(uin)?.internal;
|
|
166
|
+
let quote;
|
|
167
|
+
if (source)
|
|
168
|
+
quote = await client.getMsg(source);
|
|
169
|
+
const result = await client.sendPrivateMsg(parseInt(user_id), await processMessages.call(this, uin, user_id, 'private', message), quote);
|
|
170
|
+
return {
|
|
171
|
+
message_id: version === 'V11' ? this.oneBots.get(uin).V11.transformToInt('message_id', result.message_id) : result.message_id
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
deleteMessage(uin, version, args) {
|
|
175
|
+
const bot = this.getOneBot(uin).internal;
|
|
176
|
+
return bot.deleteMsg(args[0]);
|
|
140
177
|
}
|
|
141
178
|
async sendGroupMessage(uin, version, args) {
|
|
142
|
-
const [group_id, message] = args;
|
|
143
|
-
|
|
179
|
+
const [group_id, message, source] = args;
|
|
180
|
+
const client = this.oneBots.get(uin)?.internal;
|
|
181
|
+
let quote;
|
|
182
|
+
if (source)
|
|
183
|
+
quote = await client.getMsg(source);
|
|
184
|
+
const result = await client.sendGroupMsg(parseInt(group_id), await processMessages.call(this, group_id, 'group', message), quote);
|
|
185
|
+
return {
|
|
186
|
+
message_id: version === 'V11' ? this.oneBots.get(uin).V11.transformToInt('message_id', result.message_id) : result.message_id
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
async sendGuildMessage(uin, version, args) {
|
|
190
|
+
const [target_id, message, source] = args;
|
|
191
|
+
const client = this.oneBots.get(uin)?.internal;
|
|
192
|
+
const [guild_id, channel_id] = target_id.split(':');
|
|
193
|
+
const result = await client.sendGuildMsg(guild_id, channel_id, await processMessages.call(this, target_id, 'channel', message));
|
|
194
|
+
const message_id = `${result.seq}:${result.rand}:${result.time}`;
|
|
195
|
+
return {
|
|
196
|
+
message_id: version === 'V11' ? this.oneBots.get(uin).V11.transformToInt('message_id', message_id) : message_id
|
|
197
|
+
};
|
|
144
198
|
}
|
|
145
199
|
call(uin, version, method, args = []) {
|
|
146
200
|
try {
|
|
@@ -9,12 +9,17 @@ export default class QQAdapter extends Adapter<'qq'> {
|
|
|
9
9
|
setOnline(uin: string): Promise<void>;
|
|
10
10
|
setOffline(uin: string): Promise<void>;
|
|
11
11
|
createOneBot(uin: string, protocol: Bot.Config, versions: OneBot.Config[]): OneBot;
|
|
12
|
+
sendGroupMessage<V extends OneBot.Version>(uin: string, version: V, args: [string, OneBot.MessageElement<V>[], string]): Promise<OneBot.MessageRet<V>>;
|
|
13
|
+
sendPrivateMessage<V extends OneBot.Version>(uin: string, version: V, args: [string, OneBot.MessageElement<V>[], string]): Promise<OneBot.MessageRet<V>>;
|
|
14
|
+
sendGuildMessage<V extends OneBot.Version>(uin: string, version: V, args: [string, OneBot.MessageElement<V>[], string]): Promise<OneBot.MessageRet<V>>;
|
|
15
|
+
sendDirectMessage<V extends OneBot.Version>(uin: string, version: V, args: [string, OneBot.MessageElement<V>[], string]): Promise<OneBot.MessageRet<V>>;
|
|
16
|
+
deleteMessage(uin: string, message_id: string): Promise<boolean>;
|
|
12
17
|
call(uin: string, version: string, method: string, args?: any[]): Promise<any>;
|
|
13
18
|
fromSegment<V extends OneBot.Version>(version: V, segment: OneBot.Segment<V> | OneBot.Segment<V>[]): OneBot.MessageElement<V>[];
|
|
14
19
|
toSegment<V extends OneBot.Version, M = Sendable>(version: V, message: M): OneBot.Segment<V>[];
|
|
15
20
|
fromCqcode<V extends OneBot.Version>(version: V, message: string): OneBot.MessageElement<V>[];
|
|
16
21
|
toCqcode<V extends OneBot.Version>(version: V, messageArr: OneBot.MessageElement<V>[]): string;
|
|
17
|
-
formatEventPayload<V extends OneBot.Version>(version: V, event: string, data: any): OneBot.Payload<V>;
|
|
22
|
+
formatEventPayload<V extends OneBot.Version>(uin: string, version: V, event: string, data: any): OneBot.Payload<V>;
|
|
18
23
|
start(uin: string): Promise<void>;
|
|
19
24
|
stop(uin?: string): Promise<void>;
|
|
20
25
|
getSelfInfo<V extends OneBot.Version>(uin: string, version: V): OneBot.SelfInfo<V>;
|
package/lib/adapters/qq/index.js
CHANGED
|
@@ -82,6 +82,75 @@ class QQAdapter extends adapter_1.Adapter {
|
|
|
82
82
|
oneBot.status = onebot_1.OneBotStatus.Online;
|
|
83
83
|
return oneBot;
|
|
84
84
|
}
|
|
85
|
+
async sendGroupMessage(uin, version, args) {
|
|
86
|
+
const [group_id, message, source] = args;
|
|
87
|
+
const bot = this.getOneBot(uin);
|
|
88
|
+
let quote;
|
|
89
|
+
if (source)
|
|
90
|
+
quote = { id: source };
|
|
91
|
+
const result = await bot.internal.sendGroupMessage(group_id, message.map(({ type, data }) => ({ type, ...data })), quote);
|
|
92
|
+
if (result.msg === 'success') {
|
|
93
|
+
return {
|
|
94
|
+
message_id: version === 'V11' ? bot.V11.transformToInt('message_id', `group:${group_id}${result.msg_id}`) : `group:${group_id}${result.msg_id}`,
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
throw new Error(result.msg);
|
|
98
|
+
}
|
|
99
|
+
async sendPrivateMessage(uin, version, args) {
|
|
100
|
+
const [user_id, message, source] = args;
|
|
101
|
+
const bot = this.getOneBot(uin);
|
|
102
|
+
let quote;
|
|
103
|
+
if (source)
|
|
104
|
+
quote = { id: source };
|
|
105
|
+
const result = await bot.internal.sendPrivateMessage(user_id, message.map(({ type, data }) => ({ type, ...data })), quote);
|
|
106
|
+
if (result.msg === 'success') {
|
|
107
|
+
return {
|
|
108
|
+
message_id: version === 'V11' ? bot.V11.transformToInt('message_id', `private:${user_id}${result.msg_id}`) : `private:${user_id}${result.msg_id}`,
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
throw new Error(result.msg);
|
|
112
|
+
}
|
|
113
|
+
async sendGuildMessage(uin, version, args) {
|
|
114
|
+
const [channel_id, message, source] = args;
|
|
115
|
+
const bot = this.getOneBot(uin);
|
|
116
|
+
let quote;
|
|
117
|
+
if (source)
|
|
118
|
+
quote = { id: source };
|
|
119
|
+
const result = await bot.internal.sendGuildMessage(channel_id, message.map(({ type, data }) => ({ type, ...data })), quote);
|
|
120
|
+
if (result.msg === 'success') {
|
|
121
|
+
return {
|
|
122
|
+
message_id: version === 'V11' ? bot.V11.transformToInt('message_id', `guild:${channel_id}${result.msg_id}`) : `guild:${channel_id}${result.msg_id}`,
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
throw new Error(result.msg);
|
|
126
|
+
}
|
|
127
|
+
async sendDirectMessage(uin, version, args) {
|
|
128
|
+
const [guild_id, message, source] = args;
|
|
129
|
+
const bot = this.getOneBot(uin);
|
|
130
|
+
let quote;
|
|
131
|
+
if (source)
|
|
132
|
+
quote = { id: source };
|
|
133
|
+
const result = await bot.internal.sendDirectMessage(guild_id, message.map(({ type, data }) => ({ type, ...data })), quote);
|
|
134
|
+
if (result.msg === 'success') {
|
|
135
|
+
return {
|
|
136
|
+
message_id: version === 'V11' ? bot.V11.transformToInt('message_id', `direct:${guild_id}${result.msg_id}`) : `direct:${guild_id}${result.msg_id}`,
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
throw new Error(result.msg);
|
|
140
|
+
}
|
|
141
|
+
deleteMessage(uin, message_id) {
|
|
142
|
+
const [from_type, from_id, ...msg_idArr] = message_id.split(':');
|
|
143
|
+
const bot = this.getOneBot(uin).internal;
|
|
144
|
+
switch (from_type) {
|
|
145
|
+
case 'private':
|
|
146
|
+
case 'group':
|
|
147
|
+
throw new Error(`暂不支持撤回${from_type}类型的消息`);
|
|
148
|
+
case 'direct':
|
|
149
|
+
return bot.recallDirectMessage(from_id, msg_idArr.join(':'));
|
|
150
|
+
case 'guild':
|
|
151
|
+
return bot.recallGuildMessage(from_id, msg_idArr.join(':'));
|
|
152
|
+
}
|
|
153
|
+
}
|
|
85
154
|
call(uin, version, method, args) {
|
|
86
155
|
const oneBot = this.oneBots.get(uin);
|
|
87
156
|
if (!oneBot) {
|
|
@@ -171,7 +240,7 @@ class QQAdapter extends adapter_1.Adapter {
|
|
|
171
240
|
return `[CQ:${item.type},${dataStr.join(',')}]`;
|
|
172
241
|
}).join('');
|
|
173
242
|
}
|
|
174
|
-
formatEventPayload(version, event, data) {
|
|
243
|
+
formatEventPayload(uin, version, event, data) {
|
|
175
244
|
const result = {
|
|
176
245
|
id: data.id,
|
|
177
246
|
[version === 'V12' ? 'type' : 'post_type']: event,
|
|
@@ -185,7 +254,18 @@ class QQAdapter extends adapter_1.Adapter {
|
|
|
185
254
|
time: data.timestamp,
|
|
186
255
|
...data,
|
|
187
256
|
};
|
|
257
|
+
if (data.message_id) {
|
|
258
|
+
data.message_id = `${data.message_type}:${data.channel_id || data.guild_id || data.group_id || data.user_id}:${data.message_id}`;
|
|
259
|
+
}
|
|
188
260
|
delete result.bot;
|
|
261
|
+
const oneBot = this.getOneBot(uin);
|
|
262
|
+
switch (version) {
|
|
263
|
+
case "V11":
|
|
264
|
+
oneBot.V11.transformStrToIntForObj(result, ['message_id', 'user_id', 'group_id']);
|
|
265
|
+
oneBot.V11.transformStrToIntForObj(result.sender, ['user_id ']);
|
|
266
|
+
oneBot.V11.transformStrToIntForObj(result.self, ['user_id ']);
|
|
267
|
+
break;
|
|
268
|
+
}
|
|
189
269
|
return result;
|
|
190
270
|
}
|
|
191
271
|
async start(uin) {
|
|
@@ -11,13 +11,16 @@ export default class WechatAdapter extends Adapter<'wechat'> {
|
|
|
11
11
|
setOffline(uin: string): Promise<void>;
|
|
12
12
|
createOneBot(uin: string, protocol: WechatConfig, versions: OneBot.Config[]): OneBot;
|
|
13
13
|
call(uin: string, version: string, method: string, args?: any[]): Promise<any>;
|
|
14
|
-
sendPrivateMessage<V extends OneBot.Version>(uin: string, version: V, args: [string, OneBot.MessageElement<V>[]]): Promise<OneBot.MessageRet<V>>;
|
|
15
|
-
sendGroupMessage<V extends OneBot.Version>(uin: string, version: V, args: [string, OneBot.MessageElement<V>[]]): Promise<OneBot.MessageRet<V>>;
|
|
14
|
+
sendPrivateMessage<V extends OneBot.Version>(uin: string, version: V, args: [string, OneBot.MessageElement<V>[], string]): Promise<OneBot.MessageRet<V>>;
|
|
15
|
+
sendGroupMessage<V extends OneBot.Version>(uin: string, version: V, args: [string, OneBot.MessageElement<V>[], string]): Promise<OneBot.MessageRet<V>>;
|
|
16
|
+
deleteMessage<V extends OneBot.Version>(uin: string, version: V, [str]: [string]): Promise<boolean>;
|
|
16
17
|
fromSegment<V extends OneBot.Version>(version: V, segment: OneBot.Segment<V> | OneBot.Segment<V>[]): OneBot.MessageElement<V>[];
|
|
17
18
|
toSegment<V extends OneBot.Version, M = Sendable>(version: V, message: M): OneBot.Segment<V>[];
|
|
18
19
|
fromCqcode<V extends OneBot.Version>(version: V, message: string): OneBot.MessageElement<V>[];
|
|
19
20
|
toCqcode<V extends OneBot.Version>(version: V, messageArr: OneBot.MessageElement<V>[]): string;
|
|
20
|
-
|
|
21
|
+
getFriendList<V extends OneBot.Version>(uin: string, version: V): Promise<OneBot.UserInfo<V>[]>;
|
|
22
|
+
getGroupList<V extends OneBot.Version>(uin: string, version: V): Promise<OneBot.GroupInfo<V>[]>;
|
|
23
|
+
formatEventPayload<V extends OneBot.Version>(uin: string, version: V, event: string, data: any): OneBot.Payload<V>;
|
|
21
24
|
start(uin: string): Promise<void>;
|
|
22
25
|
stop(uin?: string): Promise<void>;
|
|
23
26
|
getSelfInfo<V extends OneBot.Version>(uin: string, version: V): OneBot.SelfInfo<V>;
|
|
@@ -99,23 +99,57 @@ class WechatAdapter extends adapter_1.Adapter {
|
|
|
99
99
|
}
|
|
100
100
|
async sendPrivateMessage(uin, version, args) {
|
|
101
101
|
const [user_id, message] = args;
|
|
102
|
-
|
|
102
|
+
const bot = this.getOneBot(uin);
|
|
103
|
+
let result = await bot.internal.sendPrivateMsg(user_id, message.map(item => {
|
|
103
104
|
const { type, data } = item;
|
|
104
105
|
return {
|
|
105
106
|
type,
|
|
106
107
|
...data
|
|
107
108
|
};
|
|
108
109
|
}));
|
|
110
|
+
if (Array.isArray(result))
|
|
111
|
+
result = JSON.stringify(result);
|
|
112
|
+
return {
|
|
113
|
+
message_id: version === 'V11' ? bot.V11.transformToInt('message_id', `${user_id}:${result}`) : `${user_id}:${result}`
|
|
114
|
+
};
|
|
109
115
|
}
|
|
110
116
|
async sendGroupMessage(uin, version, args) {
|
|
111
117
|
const [group_id, message] = args;
|
|
112
|
-
|
|
118
|
+
const bot = this.getOneBot(uin);
|
|
119
|
+
let result = await bot.internal.sendGroupMsg(group_id, message.map(item => {
|
|
113
120
|
const { type, data } = item;
|
|
114
121
|
return {
|
|
115
122
|
type,
|
|
116
123
|
...data
|
|
117
124
|
};
|
|
118
125
|
}));
|
|
126
|
+
if (Array.isArray(result))
|
|
127
|
+
result = JSON.stringify(result);
|
|
128
|
+
return {
|
|
129
|
+
message_id: version === 'V11' ? bot.V11.transformToInt('message_id', `${group_id}:${result}`) : `${group_id}:${result}`
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
async deleteMessage(uin, version, [str]) {
|
|
133
|
+
const [username, ...message_idArr] = str.split(':');
|
|
134
|
+
const bot = this.getOneBot(uin);
|
|
135
|
+
try {
|
|
136
|
+
const message_ids = JSON.parse(message_idArr.join(':'));
|
|
137
|
+
if (Array.isArray(message_ids)) {
|
|
138
|
+
let success = false;
|
|
139
|
+
for (const message_id in message_ids) {
|
|
140
|
+
success = await bot.internal.recallMsg(username, message_id);
|
|
141
|
+
if (!success)
|
|
142
|
+
return success;
|
|
143
|
+
}
|
|
144
|
+
return success;
|
|
145
|
+
}
|
|
146
|
+
else if (message_ids && typeof message_ids === 'string') {
|
|
147
|
+
return await bot.internal.recallMsg(username, message_ids);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
catch {
|
|
151
|
+
return bot.internal.recallMsg(username, message_idArr.join(':'));
|
|
152
|
+
}
|
|
119
153
|
}
|
|
120
154
|
fromSegment(version, segment) {
|
|
121
155
|
return [].concat(segment).map(item => {
|
|
@@ -190,7 +224,29 @@ class WechatAdapter extends adapter_1.Adapter {
|
|
|
190
224
|
return `[CQ:${item.type},${dataStr.join(',')}]`;
|
|
191
225
|
}).join('');
|
|
192
226
|
}
|
|
193
|
-
|
|
227
|
+
async getFriendList(uin, version) {
|
|
228
|
+
const bot = this.getOneBot(uin);
|
|
229
|
+
const result = bot.internal.getFriendList();
|
|
230
|
+
return result.map(friend => {
|
|
231
|
+
return {
|
|
232
|
+
...friend,
|
|
233
|
+
user_name: friend.nickname,
|
|
234
|
+
user_id: version === "V11" ? bot.V11.transformToInt('friend', friend.user_id) : friend.user_id,
|
|
235
|
+
};
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
async getGroupList(uin, version) {
|
|
239
|
+
const bot = this.getOneBot(uin);
|
|
240
|
+
const result = bot.internal.getGroupList();
|
|
241
|
+
return result.map(group => {
|
|
242
|
+
return {
|
|
243
|
+
...group,
|
|
244
|
+
group_id: version === "V11" ? bot.V11.transformToInt('group', group.group_id) : group.group_id,
|
|
245
|
+
};
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
formatEventPayload(uin, version, event, data) {
|
|
249
|
+
const bot = this.getOneBot(uin);
|
|
194
250
|
const result = {
|
|
195
251
|
id: data.id,
|
|
196
252
|
[version === 'V12' ? 'type' : 'post_type']: event,
|
|
@@ -210,6 +266,14 @@ class WechatAdapter extends adapter_1.Adapter {
|
|
|
210
266
|
delete result.bot;
|
|
211
267
|
delete result.c;
|
|
212
268
|
delete result.parser;
|
|
269
|
+
if (version === 'V11') {
|
|
270
|
+
bot.V11.transformStrToIntForObj(result, ['user_id', 'group_id', 'message_id']);
|
|
271
|
+
bot.V11.transformStrToIntForObj(result.self, ['user_id']);
|
|
272
|
+
bot.V11.transformStrToIntForObj(result.sender, ['user_id']);
|
|
273
|
+
bot.V11.transformStrToIntForObj(result.group, ['user_id', 'group_id']);
|
|
274
|
+
bot.V11.transformStrToIntForObj(result.member, ['user_id', 'member_id']);
|
|
275
|
+
bot.V11.transformStrToIntForObj(result.friend, ['user_id']);
|
|
276
|
+
}
|
|
213
277
|
return result;
|
|
214
278
|
}
|
|
215
279
|
async start(uin) {
|
package/lib/db.js
CHANGED
|
@@ -76,7 +76,7 @@ class JsonDB {
|
|
|
76
76
|
return initialValue;
|
|
77
77
|
}
|
|
78
78
|
set(route, data) {
|
|
79
|
-
const parentPath = route.split('.');
|
|
79
|
+
const parentPath = route.split('.').filter(c => c.length);
|
|
80
80
|
const key = parentPath.pop();
|
|
81
81
|
if (!key)
|
|
82
82
|
throw new SyntaxError(`route can't empty`);
|
package/lib/onebot.d.ts
CHANGED
package/lib/onebot.js
CHANGED
|
@@ -28,6 +28,12 @@ class OneBot extends events_1.EventEmitter {
|
|
|
28
28
|
get app() {
|
|
29
29
|
return this.adapter.app;
|
|
30
30
|
}
|
|
31
|
+
get V11() {
|
|
32
|
+
return this.instances.find(i => i.version === 'V11');
|
|
33
|
+
}
|
|
34
|
+
get V12() {
|
|
35
|
+
return this.instances.find(i => i.version === 'V12');
|
|
36
|
+
}
|
|
31
37
|
get platform() {
|
|
32
38
|
return this.adapter.platform;
|
|
33
39
|
}
|
|
@@ -95,7 +101,7 @@ class OneBot extends events_1.EventEmitter {
|
|
|
95
101
|
}
|
|
96
102
|
async dispatch(event, data) {
|
|
97
103
|
for (const instance of this.instances) {
|
|
98
|
-
instance.dispatch(instance.format(event, this.adapter.formatEventPayload(instance.version, event, data)));
|
|
104
|
+
instance.dispatch(instance.format(event, this.adapter.formatEventPayload(this.uin, instance.version, event, data)));
|
|
99
105
|
}
|
|
100
106
|
}
|
|
101
107
|
}
|
package/lib/server/app.d.ts
CHANGED
|
@@ -29,11 +29,12 @@ export declare class App extends Koa {
|
|
|
29
29
|
httpServer: Server;
|
|
30
30
|
logger: Logger;
|
|
31
31
|
static configDir: string;
|
|
32
|
-
static configPath: string;
|
|
32
|
+
static get configPath(): string;
|
|
33
|
+
static get dataDir(): string;
|
|
34
|
+
static get logFile(): string;
|
|
33
35
|
adapters: Map<string, Adapter>;
|
|
34
36
|
ws: WsServer;
|
|
35
37
|
router: Router;
|
|
36
|
-
static logFile: string;
|
|
37
38
|
get info(): {
|
|
38
39
|
system_platform: NodeJS.Platform;
|
|
39
40
|
system_arch: NodeJS.Architecture;
|
package/lib/server/app.js
CHANGED
|
@@ -46,6 +46,15 @@ const path = __importStar(require("path"));
|
|
|
46
46
|
const process_1 = __importDefault(require("process"));
|
|
47
47
|
const fs = __importStar(require("fs"));
|
|
48
48
|
class App extends koa_1.default {
|
|
49
|
+
static get configPath() {
|
|
50
|
+
return path.join(App.configDir, 'config.yaml');
|
|
51
|
+
}
|
|
52
|
+
static get dataDir() {
|
|
53
|
+
return path.join(App.configDir, 'data');
|
|
54
|
+
}
|
|
55
|
+
static get logFile() {
|
|
56
|
+
return path.join(App.configDir, 'onebots.log');
|
|
57
|
+
}
|
|
49
58
|
get info() {
|
|
50
59
|
const pkg = require(path.resolve(__dirname, '../../package.json'));
|
|
51
60
|
const free_memory = os.freemem();
|
|
@@ -166,10 +175,10 @@ class App extends koa_1.default {
|
|
|
166
175
|
this.httpServer.listen(this.config.port);
|
|
167
176
|
const fileListener = (e) => {
|
|
168
177
|
if (e === 'change')
|
|
169
|
-
this.ws.clients.forEach(client => {
|
|
178
|
+
this.ws.clients.forEach(async (client) => {
|
|
170
179
|
client.send(JSON.stringify({
|
|
171
180
|
event: 'system.log',
|
|
172
|
-
data: (0, utils_1.readLine)(1, App.logFile)
|
|
181
|
+
data: await (0, utils_1.readLine)(1, App.logFile)
|
|
173
182
|
}));
|
|
174
183
|
});
|
|
175
184
|
};
|
|
@@ -292,17 +301,17 @@ class App extends koa_1.default {
|
|
|
292
301
|
}
|
|
293
302
|
exports.App = App;
|
|
294
303
|
App.configDir = path.join(os.homedir(), '.onebots');
|
|
295
|
-
App.configPath = path.join(App.configDir, 'config.yaml');
|
|
296
|
-
App.logFile = path.join(process_1.default.cwd(), 'onebots.log');
|
|
297
304
|
function createOnebots(config = 'config.yaml', cp) {
|
|
298
305
|
if (typeof config === 'string') {
|
|
299
306
|
config = path.resolve(process_1.default.cwd(), config);
|
|
300
307
|
App.configDir = path.dirname(config);
|
|
301
|
-
App.configPath = config;
|
|
302
308
|
if (!(0, fs_1.existsSync)(App.configDir)) {
|
|
303
309
|
(0, fs_1.mkdirSync)(App.configDir);
|
|
304
310
|
}
|
|
305
|
-
|
|
311
|
+
if (!(0, fs_1.existsSync)(App.dataDir)) {
|
|
312
|
+
(0, fs_1.mkdirSync)(App.dataDir);
|
|
313
|
+
console.log('以为你创建数据存储目录', App.dataDir);
|
|
314
|
+
}
|
|
306
315
|
if (!(0, fs_1.existsSync)(App.configPath)) {
|
|
307
316
|
(0, fs_1.copyFileSync)(path.resolve(__dirname, '../config.sample.yaml'), App.configPath);
|
|
308
317
|
console.log('未找到对应配置文件,已自动生成默认配置文件,请修改配置文件后重新启动');
|
|
@@ -19,12 +19,8 @@ class CommonAction {
|
|
|
19
19
|
async deleteMsg(message_id) {
|
|
20
20
|
if (message_id == 0)
|
|
21
21
|
throw new Error('getMsg: message_id[0] is invalid');
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
});
|
|
25
|
-
if (!msg_entry)
|
|
26
|
-
throw new Error(`getMsg: can not find msg[${message_id}] in db`);
|
|
27
|
-
return this.adapter.call(this.oneBot.uin, 'V11', 'deleteMsg', [msg_entry.base64_id]);
|
|
22
|
+
const msg_id = this.getStrByInt('message_id', message_id);
|
|
23
|
+
return this.adapter.call(this.oneBot.uin, 'V11', 'deleteMessage', [this.oneBot.uin, msg_id]);
|
|
28
24
|
}
|
|
29
25
|
/**
|
|
30
26
|
* 获取消息
|
|
@@ -3,10 +3,10 @@ export declare class FriendAction {
|
|
|
3
3
|
/**
|
|
4
4
|
* 发送私聊消息
|
|
5
5
|
* @param user_id {number} 用户id
|
|
6
|
-
* @param message {
|
|
7
|
-
* @param message_id {
|
|
6
|
+
* @param message {V11.Sendable} 发送的消息
|
|
7
|
+
* @param message_id {number} 引用的消息ID
|
|
8
8
|
*/
|
|
9
|
-
sendPrivateMsg(this: V11, user_id: number, message: V11.Sendable, message_id?:
|
|
9
|
+
sendPrivateMsg(this: V11, user_id: number, message: V11.Sendable, message_id?: number): Promise<V11.MessageRet>;
|
|
10
10
|
/**
|
|
11
11
|
* 获取好友列表
|
|
12
12
|
*/
|
|
@@ -5,11 +5,13 @@ class FriendAction {
|
|
|
5
5
|
/**
|
|
6
6
|
* 发送私聊消息
|
|
7
7
|
* @param user_id {number} 用户id
|
|
8
|
-
* @param message {
|
|
9
|
-
* @param message_id {
|
|
8
|
+
* @param message {V11.Sendable} 发送的消息
|
|
9
|
+
* @param message_id {number} 引用的消息ID
|
|
10
10
|
*/
|
|
11
11
|
async sendPrivateMsg(user_id, message, message_id) {
|
|
12
|
-
|
|
12
|
+
const msg_id = message_id ? this.getStrByInt('message_id', message_id) : undefined;
|
|
13
|
+
const uid = this.getStrByInt('user_id', user_id);
|
|
14
|
+
return this.adapter.call(this.oneBot.uin, 'V11', 'sendPrivateMessage', [uid, message, msg_id]);
|
|
13
15
|
}
|
|
14
16
|
/**
|
|
15
17
|
* 获取好友列表
|
|
@@ -3,10 +3,10 @@ export declare class GroupAction {
|
|
|
3
3
|
/**
|
|
4
4
|
* 发送群聊消息
|
|
5
5
|
* @param group_id {number} 群id
|
|
6
|
-
* @param message {
|
|
7
|
-
* @param message_id {
|
|
6
|
+
* @param message {V11.Sendable[]} 消息
|
|
7
|
+
* @param message_id {number} 引用的消息ID
|
|
8
8
|
*/
|
|
9
|
-
sendGroupMsg(this: V11, group_id: number, message: V11.Sendable, message_id?:
|
|
9
|
+
sendGroupMsg(this: V11, group_id: number, message: V11.Sendable, message_id?: number): Promise<V11.MessageRet>;
|
|
10
10
|
/**
|
|
11
11
|
* 群组踢人
|
|
12
12
|
* @param group_id {number} 群id
|
|
@@ -5,11 +5,13 @@ class GroupAction {
|
|
|
5
5
|
/**
|
|
6
6
|
* 发送群聊消息
|
|
7
7
|
* @param group_id {number} 群id
|
|
8
|
-
* @param message {
|
|
9
|
-
* @param message_id {
|
|
8
|
+
* @param message {V11.Sendable[]} 消息
|
|
9
|
+
* @param message_id {number} 引用的消息ID
|
|
10
10
|
*/
|
|
11
11
|
async sendGroupMsg(group_id, message, message_id) {
|
|
12
|
-
|
|
12
|
+
const msg_id = message_id ? this.getStrByInt('message_id', message_id) : undefined;
|
|
13
|
+
const gid = this.getStrByInt('group_id', group_id);
|
|
14
|
+
return this.adapter.call(this.oneBot.uin, 'V11', 'sendGroupMessage', [gid, message, msg_id]);
|
|
13
15
|
}
|
|
14
16
|
/**
|
|
15
17
|
* 群组踢人
|
|
@@ -26,6 +26,9 @@ export declare class V11 extends Service<"V11"> implements OneBot.Base {
|
|
|
26
26
|
wss?: WebSocketServer;
|
|
27
27
|
wsr: Set<WebSocket>;
|
|
28
28
|
constructor(oneBot: OneBot, config: OneBot.Config<"V11">);
|
|
29
|
+
transformToInt(path: string, value: string): number;
|
|
30
|
+
transformStrToIntForObj<T extends object>(obj: T, keys: (keyof T)[]): void;
|
|
31
|
+
getStrByInt(path: string, value: number): string;
|
|
29
32
|
start(): void;
|
|
30
33
|
private startHttp;
|
|
31
34
|
private startHttpReverse;
|
|
@@ -35,16 +38,6 @@ export declare class V11 extends Service<"V11"> implements OneBot.Base {
|
|
|
35
38
|
format(_: any, data: any): any;
|
|
36
39
|
dispatch(data: any): Promise<void>;
|
|
37
40
|
private _formatEvent;
|
|
38
|
-
private addMsgToDB;
|
|
39
|
-
/**
|
|
40
|
-
* 从 send_msg_xxx() 调用的返回值中提取消息存入数据库(可以让前端在没有收到同步的message数据前就有能力拿到消息对应的base64_id)
|
|
41
|
-
* (也有可能来的比message慢,后来的话会被数据库忽略)
|
|
42
|
-
* @param user_id 发送者
|
|
43
|
-
* @param group_id 群号,私聊为0
|
|
44
|
-
* @param seq 消息序号
|
|
45
|
-
* @param base64_id icqq返回的base64格式的消息id
|
|
46
|
-
*/
|
|
47
|
-
private addMsgToDBFromSendMsgResult;
|
|
48
41
|
private getReplyMsgIdFromDB;
|
|
49
42
|
private _httpRequestHandler;
|
|
50
43
|
/**
|