onebots 0.4.46 → 0.4.48
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-2tNhvoZy.css +1 -0
- package/dist/assets/index-_Kz1yWe8.js +19 -0
- package/dist/index.html +2 -2
- package/lib/adapter.js +6 -8
- package/lib/adapters/dingtalk/index.d.ts +4 -4
- package/lib/adapters/dingtalk/index.js +59 -48
- package/lib/adapters/dingtalk/utils.js +5 -20
- package/lib/adapters/icqq/index.d.ts +4 -3
- package/lib/adapters/icqq/index.js +130 -101
- package/lib/adapters/icqq/utils.js +2 -2
- package/lib/adapters/qq/index.d.ts +4 -4
- package/lib/adapters/qq/index.js +66 -51
- package/lib/adapters/qq/utils.js +5 -20
- package/lib/adapters/wechat/index.d.ts +3 -3
- package/lib/adapters/wechat/index.js +66 -51
- package/lib/adapters/wechat/utils.js +5 -20
- package/lib/bin.js +6 -6
- package/lib/db.js +10 -10
- package/lib/onebot.d.ts +12 -12
- package/lib/onebot.js +25 -16
- package/lib/server/app.d.ts +2 -2
- package/lib/server/app.js +71 -70
- package/lib/server/router.d.ts +1 -1
- package/lib/server/router.js +5 -5
- package/lib/service/V11/action/common.d.ts +1 -0
- package/lib/service/V11/action/common.js +24 -24
- package/lib/service/V11/action/friend.js +16 -8
- package/lib/service/V11/action/group.js +52 -22
- package/lib/service/V11/index.js +86 -50
- package/lib/service/V12/action/common.d.ts +3 -3
- package/lib/service/V12/action/common.js +33 -31
- package/lib/service/V12/action/friend.js +8 -4
- package/lib/service/V12/action/group.js +50 -20
- package/lib/service/V12/action/guild.js +110 -35
- package/lib/service/V12/index.d.ts +18 -18
- package/lib/service/V12/index.js +189 -147
- package/lib/service/shareMusicCustom.js +14 -9
- package/lib/service.js +29 -27
- package/lib/utils.d.ts +1 -1
- package/lib/utils.js +44 -32
- package/package.json +3 -3
- package/dist/assets/index-VSQZ6fYD.js +0 -3
- package/dist/assets/index-m-TylXnm.css +0 -1
package/lib/adapters/qq/index.js
CHANGED
|
@@ -35,7 +35,7 @@ const qq_group_bot_1 = require("qq-group-bot");
|
|
|
35
35
|
const path = __importStar(require("path"));
|
|
36
36
|
class QQAdapter extends adapter_1.Adapter {
|
|
37
37
|
constructor(app, config) {
|
|
38
|
-
super(app,
|
|
38
|
+
super(app, "qq", config);
|
|
39
39
|
_QQAdapter_disposes.set(this, new Map());
|
|
40
40
|
this.icon = `https://qzonestyle.gtimg.cn/qzone/qzact/act/external/tiqq/logo.png`;
|
|
41
41
|
}
|
|
@@ -44,7 +44,7 @@ class QQAdapter extends adapter_1.Adapter {
|
|
|
44
44
|
const selfInfo = await oneBot.internal.getSelfInfo();
|
|
45
45
|
oneBot.avatar = selfInfo.avatar;
|
|
46
46
|
oneBot.nickname = selfInfo.username;
|
|
47
|
-
const pkg = require(path.resolve(path.dirname(require.resolve(
|
|
47
|
+
const pkg = require(path.resolve(path.dirname(require.resolve("qq-group-bot")), "../package.json"));
|
|
48
48
|
oneBot.dependency = `qq-group-bot v${pkg.version}`;
|
|
49
49
|
const disposeArr = [];
|
|
50
50
|
const clean = () => {
|
|
@@ -53,12 +53,12 @@ class QQAdapter extends adapter_1.Adapter {
|
|
|
53
53
|
}
|
|
54
54
|
oneBot.internal.stop();
|
|
55
55
|
};
|
|
56
|
-
const messageHandler =
|
|
57
|
-
this.emit(
|
|
56
|
+
const messageHandler = event => {
|
|
57
|
+
this.emit("message.receive", oneBot.uin, event);
|
|
58
58
|
};
|
|
59
|
-
oneBot.internal.on(
|
|
59
|
+
oneBot.internal.on("message", messageHandler);
|
|
60
60
|
disposeArr.push(() => {
|
|
61
|
-
oneBot.internal.off(
|
|
61
|
+
oneBot.internal.off("message", messageHandler);
|
|
62
62
|
});
|
|
63
63
|
return clean;
|
|
64
64
|
}
|
|
@@ -77,7 +77,7 @@ class QQAdapter extends adapter_1.Adapter {
|
|
|
77
77
|
oneBot.internal = new qq_group_bot_1.Bot({
|
|
78
78
|
appid: oneBot.uin,
|
|
79
79
|
logLevel: this.app.config.log_level,
|
|
80
|
-
...protocol
|
|
80
|
+
...protocol,
|
|
81
81
|
});
|
|
82
82
|
oneBot.status = onebot_1.OneBotStatus.Online;
|
|
83
83
|
return oneBot;
|
|
@@ -89,9 +89,11 @@ class QQAdapter extends adapter_1.Adapter {
|
|
|
89
89
|
if (source)
|
|
90
90
|
quote = { id: source };
|
|
91
91
|
const result = await bot.internal.sendGroupMessage(group_id, message.map(({ type, data }) => ({ type, ...data })), quote);
|
|
92
|
-
if (result.msg ===
|
|
92
|
+
if (result.msg === "success") {
|
|
93
93
|
return {
|
|
94
|
-
message_id: version ===
|
|
94
|
+
message_id: version === "V11"
|
|
95
|
+
? bot.V11.transformToInt("message_id", `group:${group_id}${result.msg_id}`)
|
|
96
|
+
: `group:${group_id}${result.msg_id}`,
|
|
95
97
|
};
|
|
96
98
|
}
|
|
97
99
|
throw new Error(result.msg);
|
|
@@ -103,9 +105,11 @@ class QQAdapter extends adapter_1.Adapter {
|
|
|
103
105
|
if (source)
|
|
104
106
|
quote = { id: source };
|
|
105
107
|
const result = await bot.internal.sendPrivateMessage(user_id, message.map(({ type, data }) => ({ type, ...data })), quote);
|
|
106
|
-
if (result.msg ===
|
|
108
|
+
if (result.msg === "success") {
|
|
107
109
|
return {
|
|
108
|
-
message_id: version ===
|
|
110
|
+
message_id: version === "V11"
|
|
111
|
+
? bot.V11.transformToInt("message_id", `private:${user_id}${result.msg_id}`)
|
|
112
|
+
: `private:${user_id}${result.msg_id}`,
|
|
109
113
|
};
|
|
110
114
|
}
|
|
111
115
|
throw new Error(result.msg);
|
|
@@ -117,9 +121,11 @@ class QQAdapter extends adapter_1.Adapter {
|
|
|
117
121
|
if (source)
|
|
118
122
|
quote = { id: source };
|
|
119
123
|
const result = await bot.internal.sendGuildMessage(channel_id, message.map(({ type, data }) => ({ type, ...data })), quote);
|
|
120
|
-
if (result.msg ===
|
|
124
|
+
if (result.msg === "success") {
|
|
121
125
|
return {
|
|
122
|
-
message_id: version ===
|
|
126
|
+
message_id: version === "V11"
|
|
127
|
+
? bot.V11.transformToInt("message_id", `guild:${channel_id}${result.msg_id}`)
|
|
128
|
+
: `guild:${channel_id}${result.msg_id}`,
|
|
123
129
|
};
|
|
124
130
|
}
|
|
125
131
|
throw new Error(result.msg);
|
|
@@ -131,24 +137,26 @@ class QQAdapter extends adapter_1.Adapter {
|
|
|
131
137
|
if (source)
|
|
132
138
|
quote = { id: source };
|
|
133
139
|
const result = await bot.internal.sendDirectMessage(guild_id, message.map(({ type, data }) => ({ type, ...data })), quote);
|
|
134
|
-
if (result.msg ===
|
|
140
|
+
if (result.msg === "success") {
|
|
135
141
|
return {
|
|
136
|
-
message_id: version ===
|
|
142
|
+
message_id: version === "V11"
|
|
143
|
+
? bot.V11.transformToInt("message_id", `direct:${guild_id}${result.msg_id}`)
|
|
144
|
+
: `direct:${guild_id}${result.msg_id}`,
|
|
137
145
|
};
|
|
138
146
|
}
|
|
139
147
|
throw new Error(result.msg);
|
|
140
148
|
}
|
|
141
149
|
deleteMessage(uin, message_id) {
|
|
142
|
-
const [from_type, from_id, ...msg_idArr] = message_id.split(
|
|
150
|
+
const [from_type, from_id, ...msg_idArr] = message_id.split(":");
|
|
143
151
|
const bot = this.getOneBot(uin).internal;
|
|
144
152
|
switch (from_type) {
|
|
145
|
-
case
|
|
146
|
-
case
|
|
153
|
+
case "private":
|
|
154
|
+
case "group":
|
|
147
155
|
throw new Error(`暂不支持撤回${from_type}类型的消息`);
|
|
148
|
-
case
|
|
149
|
-
return bot.recallDirectMessage(from_id, msg_idArr.join(
|
|
150
|
-
case
|
|
151
|
-
return bot.recallGuildMessage(from_id, msg_idArr.join(
|
|
156
|
+
case "direct":
|
|
157
|
+
return bot.recallDirectMessage(from_id, msg_idArr.join(":"));
|
|
158
|
+
case "guild":
|
|
159
|
+
return bot.recallGuildMessage(from_id, msg_idArr.join(":"));
|
|
152
160
|
}
|
|
153
161
|
}
|
|
154
162
|
call(uin, version, method, args) {
|
|
@@ -156,9 +164,9 @@ class QQAdapter extends adapter_1.Adapter {
|
|
|
156
164
|
if (!oneBot) {
|
|
157
165
|
throw new Error(`未找到账号${uin}`);
|
|
158
166
|
}
|
|
159
|
-
if (typeof this[method] ===
|
|
167
|
+
if (typeof this[method] === "function")
|
|
160
168
|
return this[method](uin, version, args);
|
|
161
|
-
if (typeof oneBot.internal[method] !==
|
|
169
|
+
if (typeof oneBot.internal[method] !== "function")
|
|
162
170
|
throw onebot_1.OneBot.UnsupportedMethodError;
|
|
163
171
|
try {
|
|
164
172
|
return oneBot.internal[method](...(args || []));
|
|
@@ -171,10 +179,10 @@ class QQAdapter extends adapter_1.Adapter {
|
|
|
171
179
|
return [].concat(segment).map(item => {
|
|
172
180
|
if (typeof item === "string")
|
|
173
181
|
return {
|
|
174
|
-
type:
|
|
182
|
+
type: "text",
|
|
175
183
|
data: {
|
|
176
|
-
text: item
|
|
177
|
-
}
|
|
184
|
+
text: item,
|
|
185
|
+
},
|
|
178
186
|
};
|
|
179
187
|
return item;
|
|
180
188
|
});
|
|
@@ -183,18 +191,18 @@ class QQAdapter extends adapter_1.Adapter {
|
|
|
183
191
|
return [].concat(message).map(item => {
|
|
184
192
|
if (!item || typeof item !== "object")
|
|
185
193
|
return {
|
|
186
|
-
type:
|
|
194
|
+
type: "text",
|
|
187
195
|
data: {
|
|
188
|
-
text: item
|
|
189
|
-
}
|
|
196
|
+
text: item,
|
|
197
|
+
},
|
|
190
198
|
};
|
|
191
199
|
const { type, data, ...other } = item;
|
|
192
200
|
return {
|
|
193
201
|
type,
|
|
194
202
|
data: {
|
|
195
203
|
...data,
|
|
196
|
-
...other
|
|
197
|
-
}
|
|
204
|
+
...other,
|
|
205
|
+
},
|
|
198
206
|
};
|
|
199
207
|
});
|
|
200
208
|
}
|
|
@@ -203,54 +211,61 @@ class QQAdapter extends adapter_1.Adapter {
|
|
|
203
211
|
if (!regExpMatchArray)
|
|
204
212
|
return [
|
|
205
213
|
{
|
|
206
|
-
type:
|
|
214
|
+
type: "text",
|
|
207
215
|
data: {
|
|
208
|
-
text: message
|
|
209
|
-
}
|
|
210
|
-
}
|
|
216
|
+
text: message,
|
|
217
|
+
},
|
|
218
|
+
},
|
|
211
219
|
];
|
|
212
220
|
const result = [];
|
|
213
221
|
for (const match of regExpMatchArray) {
|
|
214
|
-
const [type, ...valueArr] = match.substring(1, match.length - 1).split(
|
|
222
|
+
const [type, ...valueArr] = match.substring(1, match.length - 1).split(",");
|
|
215
223
|
result.push({
|
|
216
224
|
type: type,
|
|
217
225
|
data: Object.fromEntries(valueArr.map(item => {
|
|
218
|
-
const [key, value] = item.split(
|
|
226
|
+
const [key, value] = item.split("=");
|
|
219
227
|
return [key, value];
|
|
220
|
-
}))
|
|
228
|
+
})),
|
|
221
229
|
});
|
|
222
230
|
}
|
|
223
231
|
return result;
|
|
224
232
|
}
|
|
225
233
|
toCqcode(version, messageArr) {
|
|
226
|
-
return []
|
|
234
|
+
return []
|
|
235
|
+
.concat(messageArr)
|
|
236
|
+
.map(item => {
|
|
237
|
+
if (typeof item === "string")
|
|
238
|
+
return item;
|
|
239
|
+
if (item.type === "text")
|
|
240
|
+
return item.data?.text || item.text;
|
|
227
241
|
const dataStr = Object.entries(item.data).map(([key, value]) => {
|
|
228
242
|
// is Buffer
|
|
229
243
|
if (value instanceof Buffer)
|
|
230
|
-
return `${key}=${value.toString(
|
|
244
|
+
return `${key}=${value.toString("base64")}`;
|
|
231
245
|
// is Object
|
|
232
246
|
if (value instanceof Object)
|
|
233
247
|
return `${key}=${JSON.stringify(value)}`;
|
|
234
248
|
// is Array
|
|
235
249
|
if (value instanceof Array)
|
|
236
|
-
return `${key}=${value.map(v => JSON.stringify(v)).join(
|
|
250
|
+
return `${key}=${value.map(v => JSON.stringify(v)).join(",")}`;
|
|
237
251
|
// is String
|
|
238
252
|
return `${key}=${item[key]}`;
|
|
239
253
|
});
|
|
240
|
-
return `[CQ:${item.type},${dataStr.join(
|
|
241
|
-
})
|
|
254
|
+
return `[CQ:${item.type},${dataStr.join(",")}]`;
|
|
255
|
+
})
|
|
256
|
+
.join("");
|
|
242
257
|
}
|
|
243
258
|
formatEventPayload(uin, version, event, data) {
|
|
244
259
|
const result = {
|
|
245
260
|
id: data.id,
|
|
246
|
-
[version ===
|
|
261
|
+
[version === "V12" ? "type" : "post_type"]: event,
|
|
247
262
|
version: version,
|
|
248
263
|
self: {
|
|
249
|
-
platform:
|
|
250
|
-
user_id: data.self_id
|
|
264
|
+
platform: "qq",
|
|
265
|
+
user_id: data.self_id,
|
|
251
266
|
},
|
|
252
267
|
detail_type: data.message_type || data.notice_type || data.request_type,
|
|
253
|
-
platform:
|
|
268
|
+
platform: "qq",
|
|
254
269
|
time: data.timestamp,
|
|
255
270
|
...data,
|
|
256
271
|
};
|
|
@@ -261,9 +276,9 @@ class QQAdapter extends adapter_1.Adapter {
|
|
|
261
276
|
const oneBot = this.getOneBot(uin);
|
|
262
277
|
switch (version) {
|
|
263
278
|
case "V11":
|
|
264
|
-
oneBot.V11.transformStrToIntForObj(result, [
|
|
265
|
-
oneBot.V11.transformStrToIntForObj(result.sender, [
|
|
266
|
-
oneBot.V11.transformStrToIntForObj(result.self, [
|
|
279
|
+
oneBot.V11.transformStrToIntForObj(result, ["message_id", "user_id", "group_id"]);
|
|
280
|
+
oneBot.V11.transformStrToIntForObj(result.sender, ["user_id "]);
|
|
281
|
+
oneBot.V11.transformStrToIntForObj(result.self, ["user_id "]);
|
|
267
282
|
break;
|
|
268
283
|
}
|
|
269
284
|
return result;
|
package/lib/adapters/qq/utils.js
CHANGED
|
@@ -36,26 +36,11 @@ function findLastIndex(list, predicate) {
|
|
|
36
36
|
exports.findLastIndex = findLastIndex;
|
|
37
37
|
function trimQuote(str) {
|
|
38
38
|
const quotes = [
|
|
39
|
-
[
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
],
|
|
43
|
-
[
|
|
44
|
-
"'",
|
|
45
|
-
"'",
|
|
46
|
-
],
|
|
47
|
-
[
|
|
48
|
-
'`',
|
|
49
|
-
'`',
|
|
50
|
-
],
|
|
51
|
-
[
|
|
52
|
-
'“',
|
|
53
|
-
'”',
|
|
54
|
-
],
|
|
55
|
-
[
|
|
56
|
-
'‘',
|
|
57
|
-
'’',
|
|
58
|
-
]
|
|
39
|
+
['"', '"'],
|
|
40
|
+
["'", "'"],
|
|
41
|
+
["`", "`"],
|
|
42
|
+
["“", "”"],
|
|
43
|
+
["‘", "’"],
|
|
59
44
|
];
|
|
60
45
|
for (let i = 0; i < quotes.length; i++) {
|
|
61
46
|
const [start, end] = quotes[i];
|
|
@@ -3,7 +3,7 @@ import { App } from "../../server/app";
|
|
|
3
3
|
import { OneBot } from "../../onebot";
|
|
4
4
|
import { Client, Sendable, BaseClient } from "lib-wechat";
|
|
5
5
|
type WechatConfig = BaseClient.Config;
|
|
6
|
-
export default class WechatAdapter extends Adapter<
|
|
6
|
+
export default class WechatAdapter extends Adapter<"wechat"> {
|
|
7
7
|
#private;
|
|
8
8
|
constructor(app: App, config: WechatAdapter.Config);
|
|
9
9
|
startOneBot(oneBot: OneBot<Client>): Promise<() => void>;
|
|
@@ -25,7 +25,7 @@ export default class WechatAdapter extends Adapter<'wechat'> {
|
|
|
25
25
|
stop(uin?: string): Promise<void>;
|
|
26
26
|
getSelfInfo<V extends OneBot.Version>(uin: string, version: V): OneBot.SelfInfo<V>;
|
|
27
27
|
}
|
|
28
|
-
declare module
|
|
28
|
+
declare module "../../adapter" {
|
|
29
29
|
namespace Adapter {
|
|
30
30
|
interface Configs {
|
|
31
31
|
wechat: WechatAdapter.Config;
|
|
@@ -33,7 +33,7 @@ declare module '../../adapter' {
|
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
35
|
export declare namespace WechatAdapter {
|
|
36
|
-
interface Config extends Adapter.Config<
|
|
36
|
+
interface Config extends Adapter.Config<"wechat"> {
|
|
37
37
|
protocol: WechatConfig;
|
|
38
38
|
}
|
|
39
39
|
}
|
|
@@ -35,13 +35,13 @@ const lib_wechat_1 = require("lib-wechat");
|
|
|
35
35
|
const path = __importStar(require("path"));
|
|
36
36
|
class WechatAdapter extends adapter_1.Adapter {
|
|
37
37
|
constructor(app, config) {
|
|
38
|
-
super(app,
|
|
38
|
+
super(app, "wechat", config);
|
|
39
39
|
_WechatAdapter_disposes.set(this, new Map());
|
|
40
40
|
this.icon = `https://res.wx.qq.com/a/wx_fed/assets/res/NTI4MWU5.ico`;
|
|
41
41
|
}
|
|
42
42
|
async startOneBot(oneBot) {
|
|
43
43
|
await this.setOnline(oneBot.uin);
|
|
44
|
-
const pkg = require(path.resolve(path.dirname(require.resolve(
|
|
44
|
+
const pkg = require(path.resolve(path.dirname(require.resolve("lib-wechat")), "../package.json"));
|
|
45
45
|
oneBot.dependency = `lib-wechat v${pkg.version}`;
|
|
46
46
|
const disposeArr = [];
|
|
47
47
|
const clean = () => {
|
|
@@ -50,12 +50,12 @@ class WechatAdapter extends adapter_1.Adapter {
|
|
|
50
50
|
}
|
|
51
51
|
oneBot.internal.stop();
|
|
52
52
|
};
|
|
53
|
-
const messageHandler =
|
|
54
|
-
this.emit(
|
|
53
|
+
const messageHandler = event => {
|
|
54
|
+
this.emit("message.receive", oneBot.uin, event);
|
|
55
55
|
};
|
|
56
|
-
oneBot.internal.on(
|
|
56
|
+
oneBot.internal.on("message", messageHandler);
|
|
57
57
|
disposeArr.push(() => {
|
|
58
|
-
oneBot.internal.off(
|
|
58
|
+
oneBot.internal.off("message", messageHandler);
|
|
59
59
|
});
|
|
60
60
|
return clean;
|
|
61
61
|
}
|
|
@@ -63,7 +63,7 @@ class WechatAdapter extends adapter_1.Adapter {
|
|
|
63
63
|
const oneBot = this.getOneBot(uin);
|
|
64
64
|
await oneBot?.internal.start();
|
|
65
65
|
const { data } = await oneBot?.internal.getAvatar(oneBot.internal.info.nickname);
|
|
66
|
-
oneBot.avatar = `data:image/png;base64,${data.toString(
|
|
66
|
+
oneBot.avatar = `data:image/png;base64,${data.toString("base64")}`;
|
|
67
67
|
oneBot.nickname = oneBot.internal.info.nickname;
|
|
68
68
|
oneBot.status = onebot_1.OneBotStatus.Good;
|
|
69
69
|
}
|
|
@@ -76,7 +76,7 @@ class WechatAdapter extends adapter_1.Adapter {
|
|
|
76
76
|
const oneBot = super.createOneBot(uin, protocol, versions);
|
|
77
77
|
oneBot.internal = new lib_wechat_1.Client({
|
|
78
78
|
log_level: this.app.config.log_level,
|
|
79
|
-
...protocol
|
|
79
|
+
...protocol,
|
|
80
80
|
});
|
|
81
81
|
oneBot.status = onebot_1.OneBotStatus.Online;
|
|
82
82
|
return oneBot;
|
|
@@ -86,9 +86,9 @@ class WechatAdapter extends adapter_1.Adapter {
|
|
|
86
86
|
if (!oneBot) {
|
|
87
87
|
throw new Error(`未找到账号${uin}`);
|
|
88
88
|
}
|
|
89
|
-
if (typeof this[method] ===
|
|
89
|
+
if (typeof this[method] === "function")
|
|
90
90
|
return this[method](uin, version, args);
|
|
91
|
-
if (typeof oneBot.internal[method] !==
|
|
91
|
+
if (typeof oneBot.internal[method] !== "function")
|
|
92
92
|
throw onebot_1.OneBot.UnsupportedMethodError;
|
|
93
93
|
try {
|
|
94
94
|
return oneBot.internal[method](...(args || []));
|
|
@@ -104,13 +104,15 @@ class WechatAdapter extends adapter_1.Adapter {
|
|
|
104
104
|
const { type, data } = item;
|
|
105
105
|
return {
|
|
106
106
|
type,
|
|
107
|
-
...data
|
|
107
|
+
...data,
|
|
108
108
|
};
|
|
109
109
|
}));
|
|
110
110
|
if (Array.isArray(result))
|
|
111
111
|
result = JSON.stringify(result);
|
|
112
112
|
return {
|
|
113
|
-
message_id: version ===
|
|
113
|
+
message_id: version === "V11"
|
|
114
|
+
? bot.V11.transformToInt("message_id", `${user_id}:${result}`)
|
|
115
|
+
: `${user_id}:${result}`,
|
|
114
116
|
};
|
|
115
117
|
}
|
|
116
118
|
async sendGroupMessage(uin, version, args) {
|
|
@@ -120,20 +122,22 @@ class WechatAdapter extends adapter_1.Adapter {
|
|
|
120
122
|
const { type, data } = item;
|
|
121
123
|
return {
|
|
122
124
|
type,
|
|
123
|
-
...data
|
|
125
|
+
...data,
|
|
124
126
|
};
|
|
125
127
|
}));
|
|
126
128
|
if (Array.isArray(result))
|
|
127
129
|
result = JSON.stringify(result);
|
|
128
130
|
return {
|
|
129
|
-
message_id: version ===
|
|
131
|
+
message_id: version === "V11"
|
|
132
|
+
? bot.V11.transformToInt("message_id", `${group_id}:${result}`)
|
|
133
|
+
: `${group_id}:${result}`,
|
|
130
134
|
};
|
|
131
135
|
}
|
|
132
136
|
async deleteMessage(uin, version, [str]) {
|
|
133
|
-
const [username, ...message_idArr] = str.split(
|
|
137
|
+
const [username, ...message_idArr] = str.split(":");
|
|
134
138
|
const bot = this.getOneBot(uin);
|
|
135
139
|
try {
|
|
136
|
-
const message_ids = JSON.parse(message_idArr.join(
|
|
140
|
+
const message_ids = JSON.parse(message_idArr.join(":"));
|
|
137
141
|
if (Array.isArray(message_ids)) {
|
|
138
142
|
let success = false;
|
|
139
143
|
for (const message_id in message_ids) {
|
|
@@ -143,22 +147,22 @@ class WechatAdapter extends adapter_1.Adapter {
|
|
|
143
147
|
}
|
|
144
148
|
return success;
|
|
145
149
|
}
|
|
146
|
-
else if (message_ids && typeof message_ids ===
|
|
150
|
+
else if (message_ids && typeof message_ids === "string") {
|
|
147
151
|
return await bot.internal.recallMsg(username, message_ids);
|
|
148
152
|
}
|
|
149
153
|
}
|
|
150
154
|
catch {
|
|
151
|
-
return bot.internal.recallMsg(username, message_idArr.join(
|
|
155
|
+
return bot.internal.recallMsg(username, message_idArr.join(":"));
|
|
152
156
|
}
|
|
153
157
|
}
|
|
154
158
|
fromSegment(version, segment) {
|
|
155
159
|
return [].concat(segment).map(item => {
|
|
156
160
|
if (typeof item === "string")
|
|
157
161
|
return {
|
|
158
|
-
type:
|
|
162
|
+
type: "text",
|
|
159
163
|
data: {
|
|
160
|
-
text: item
|
|
161
|
-
}
|
|
164
|
+
text: item,
|
|
165
|
+
},
|
|
162
166
|
};
|
|
163
167
|
return item;
|
|
164
168
|
});
|
|
@@ -167,18 +171,18 @@ class WechatAdapter extends adapter_1.Adapter {
|
|
|
167
171
|
return [].concat(message).map(item => {
|
|
168
172
|
if (!item || typeof item !== "object")
|
|
169
173
|
return {
|
|
170
|
-
type:
|
|
174
|
+
type: "text",
|
|
171
175
|
data: {
|
|
172
|
-
text: item
|
|
173
|
-
}
|
|
176
|
+
text: item,
|
|
177
|
+
},
|
|
174
178
|
};
|
|
175
179
|
const { type, data, ...other } = item;
|
|
176
180
|
return {
|
|
177
181
|
type,
|
|
178
182
|
data: {
|
|
179
183
|
...data,
|
|
180
|
-
...other
|
|
181
|
-
}
|
|
184
|
+
...other,
|
|
185
|
+
},
|
|
182
186
|
};
|
|
183
187
|
});
|
|
184
188
|
}
|
|
@@ -187,42 +191,49 @@ class WechatAdapter extends adapter_1.Adapter {
|
|
|
187
191
|
if (!regExpMatchArray)
|
|
188
192
|
return [
|
|
189
193
|
{
|
|
190
|
-
type:
|
|
194
|
+
type: "text",
|
|
191
195
|
data: {
|
|
192
|
-
text: message
|
|
193
|
-
}
|
|
194
|
-
}
|
|
196
|
+
text: message,
|
|
197
|
+
},
|
|
198
|
+
},
|
|
195
199
|
];
|
|
196
200
|
const result = [];
|
|
197
201
|
for (const match of regExpMatchArray) {
|
|
198
|
-
const [type, ...valueArr] = match.substring(1, match.length - 1).split(
|
|
202
|
+
const [type, ...valueArr] = match.substring(1, match.length - 1).split(",");
|
|
199
203
|
result.push({
|
|
200
204
|
type: type,
|
|
201
205
|
data: Object.fromEntries(valueArr.map(item => {
|
|
202
|
-
const [key, value] = item.split(
|
|
206
|
+
const [key, value] = item.split("=");
|
|
203
207
|
return [key, value];
|
|
204
|
-
}))
|
|
208
|
+
})),
|
|
205
209
|
});
|
|
206
210
|
}
|
|
207
211
|
return result;
|
|
208
212
|
}
|
|
209
213
|
toCqcode(version, messageArr) {
|
|
210
|
-
return []
|
|
214
|
+
return []
|
|
215
|
+
.concat(messageArr)
|
|
216
|
+
.map(item => {
|
|
217
|
+
if (typeof item === "string")
|
|
218
|
+
return item;
|
|
219
|
+
if (item.type === "text")
|
|
220
|
+
return item.data?.text || item.text;
|
|
211
221
|
const dataStr = Object.entries(item.data).map(([key, value]) => {
|
|
212
222
|
// is Buffer
|
|
213
223
|
if (value instanceof Buffer)
|
|
214
|
-
return `${key}=${value.toString(
|
|
224
|
+
return `${key}=${value.toString("base64")}`;
|
|
215
225
|
// is Object
|
|
216
226
|
if (value instanceof Object)
|
|
217
227
|
return `${key}=${JSON.stringify(value)}`;
|
|
218
228
|
// is Array
|
|
219
229
|
if (value instanceof Array)
|
|
220
|
-
return `${key}=${value.map(v => JSON.stringify(v)).join(
|
|
230
|
+
return `${key}=${value.map(v => JSON.stringify(v)).join(",")}`;
|
|
221
231
|
// is String
|
|
222
232
|
return `${key}=${item[key]}`;
|
|
223
233
|
});
|
|
224
|
-
return `[CQ:${item.type},${dataStr.join(
|
|
225
|
-
})
|
|
234
|
+
return `[CQ:${item.type},${dataStr.join(",")}]`;
|
|
235
|
+
})
|
|
236
|
+
.join("");
|
|
226
237
|
}
|
|
227
238
|
async getFriendList(uin, version) {
|
|
228
239
|
const bot = this.getOneBot(uin);
|
|
@@ -231,7 +242,9 @@ class WechatAdapter extends adapter_1.Adapter {
|
|
|
231
242
|
return {
|
|
232
243
|
...friend,
|
|
233
244
|
user_name: friend.nickname,
|
|
234
|
-
user_id: version === "V11"
|
|
245
|
+
user_id: version === "V11"
|
|
246
|
+
? bot.V11.transformToInt("friend", friend.user_id)
|
|
247
|
+
: friend.user_id,
|
|
235
248
|
};
|
|
236
249
|
});
|
|
237
250
|
}
|
|
@@ -241,7 +254,9 @@ class WechatAdapter extends adapter_1.Adapter {
|
|
|
241
254
|
return result.map(group => {
|
|
242
255
|
return {
|
|
243
256
|
...group,
|
|
244
|
-
group_id: version === "V11"
|
|
257
|
+
group_id: version === "V11"
|
|
258
|
+
? bot.V11.transformToInt("group", group.group_id)
|
|
259
|
+
: group.group_id,
|
|
245
260
|
};
|
|
246
261
|
});
|
|
247
262
|
}
|
|
@@ -249,14 +264,14 @@ class WechatAdapter extends adapter_1.Adapter {
|
|
|
249
264
|
const bot = this.getOneBot(uin);
|
|
250
265
|
const result = {
|
|
251
266
|
id: data.id,
|
|
252
|
-
[version ===
|
|
267
|
+
[version === "V12" ? "type" : "post_type"]: event,
|
|
253
268
|
version: version,
|
|
254
269
|
self: {
|
|
255
|
-
platform:
|
|
256
|
-
user_id: data.self_id
|
|
270
|
+
platform: "wechat",
|
|
271
|
+
user_id: data.self_id,
|
|
257
272
|
},
|
|
258
273
|
detail_type: data.message_type || data.notice_type || data.request_type,
|
|
259
|
-
platform:
|
|
274
|
+
platform: "wechat",
|
|
260
275
|
group: data.group?.info,
|
|
261
276
|
member: data.member?.info,
|
|
262
277
|
friend: data.friend?.info,
|
|
@@ -266,13 +281,13 @@ class WechatAdapter extends adapter_1.Adapter {
|
|
|
266
281
|
delete result.bot;
|
|
267
282
|
delete result.c;
|
|
268
283
|
delete result.parser;
|
|
269
|
-
if (version ===
|
|
270
|
-
bot.V11.transformStrToIntForObj(result, [
|
|
271
|
-
bot.V11.transformStrToIntForObj(result.self, [
|
|
272
|
-
bot.V11.transformStrToIntForObj(result.sender, [
|
|
273
|
-
bot.V11.transformStrToIntForObj(result.group, [
|
|
274
|
-
bot.V11.transformStrToIntForObj(result.member, [
|
|
275
|
-
bot.V11.transformStrToIntForObj(result.friend, [
|
|
284
|
+
if (version === "V11") {
|
|
285
|
+
bot.V11.transformStrToIntForObj(result, ["user_id", "group_id", "message_id"]);
|
|
286
|
+
bot.V11.transformStrToIntForObj(result.self, ["user_id"]);
|
|
287
|
+
bot.V11.transformStrToIntForObj(result.sender, ["user_id"]);
|
|
288
|
+
bot.V11.transformStrToIntForObj(result.group, ["user_id", "group_id"]);
|
|
289
|
+
bot.V11.transformStrToIntForObj(result.member, ["user_id", "member_id"]);
|
|
290
|
+
bot.V11.transformStrToIntForObj(result.friend, ["user_id"]);
|
|
276
291
|
}
|
|
277
292
|
return result;
|
|
278
293
|
}
|
|
@@ -36,26 +36,11 @@ function findLastIndex(list, predicate) {
|
|
|
36
36
|
exports.findLastIndex = findLastIndex;
|
|
37
37
|
function trimQuote(str) {
|
|
38
38
|
const quotes = [
|
|
39
|
-
[
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
],
|
|
43
|
-
[
|
|
44
|
-
"'",
|
|
45
|
-
"'",
|
|
46
|
-
],
|
|
47
|
-
[
|
|
48
|
-
'`',
|
|
49
|
-
'`',
|
|
50
|
-
],
|
|
51
|
-
[
|
|
52
|
-
'“',
|
|
53
|
-
'”',
|
|
54
|
-
],
|
|
55
|
-
[
|
|
56
|
-
'‘',
|
|
57
|
-
'’',
|
|
58
|
-
]
|
|
39
|
+
['"', '"'],
|
|
40
|
+
["'", "'"],
|
|
41
|
+
["`", "`"],
|
|
42
|
+
["“", "”"],
|
|
43
|
+
["‘", "’"],
|
|
59
44
|
];
|
|
60
45
|
for (let i = 0; i < quotes.length; i++) {
|
|
61
46
|
const [start, end] = quotes[i];
|
package/lib/bin.js
CHANGED
|
@@ -10,11 +10,11 @@ const child_process_1 = require("child_process");
|
|
|
10
10
|
const execArgv = process_1.default.argv.splice(2);
|
|
11
11
|
let cp;
|
|
12
12
|
if (process_1.default.env.TS_NODE_DEV) {
|
|
13
|
-
cp = (0, child_process_1.exec)(
|
|
14
|
-
cp.stdout.on(
|
|
13
|
+
cp = (0, child_process_1.exec)("vite");
|
|
14
|
+
cp.stdout.on("data", data => {
|
|
15
15
|
console.log(data);
|
|
16
16
|
});
|
|
17
|
-
cp.stderr.on(
|
|
17
|
+
cp.stderr.on("data", e => {
|
|
18
18
|
console.error(e);
|
|
19
19
|
});
|
|
20
20
|
}
|
|
@@ -31,10 +31,10 @@ for (let i = 0; i < execArgv.length; i += 2) {
|
|
|
31
31
|
obj[key] = [obj[key], value];
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
|
-
if (obj[
|
|
35
|
-
const adapters = [].concat(obj[
|
|
34
|
+
if (obj["-r"]) {
|
|
35
|
+
const adapters = [].concat(obj["-r"]);
|
|
36
36
|
for (const adapter of adapters) {
|
|
37
37
|
app_1.App.registerAdapter(adapter);
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
|
-
(0, app_1.createOnebots)(obj[
|
|
40
|
+
(0, app_1.createOnebots)(obj["-c"], cp).start();
|