onebots 0.4.47 → 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-yG7HG4Oa.css → index-2tNhvoZy.css} +1 -1
- 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 +56 -49
- package/lib/adapters/dingtalk/utils.js +5 -20
- package/lib/adapters/icqq/index.d.ts +4 -3
- package/lib/adapters/icqq/index.js +128 -101
- package/lib/adapters/icqq/utils.js +2 -2
- package/lib/adapters/qq/index.d.ts +4 -4
- package/lib/adapters/qq/index.js +63 -52
- package/lib/adapters/qq/utils.js +5 -20
- package/lib/adapters/wechat/index.d.ts +3 -3
- package/lib/adapters/wechat/index.js +63 -52
- 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 +1 -1
- package/dist/assets/index-YN4djyjB.js +0 -19
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,58 +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 => {
|
|
227
237
|
if (typeof item === "string")
|
|
228
238
|
return item;
|
|
229
|
-
if (item.type ===
|
|
239
|
+
if (item.type === "text")
|
|
230
240
|
return item.data?.text || item.text;
|
|
231
241
|
const dataStr = Object.entries(item.data).map(([key, value]) => {
|
|
232
242
|
// is Buffer
|
|
233
243
|
if (value instanceof Buffer)
|
|
234
|
-
return `${key}=${value.toString(
|
|
244
|
+
return `${key}=${value.toString("base64")}`;
|
|
235
245
|
// is Object
|
|
236
246
|
if (value instanceof Object)
|
|
237
247
|
return `${key}=${JSON.stringify(value)}`;
|
|
238
248
|
// is Array
|
|
239
249
|
if (value instanceof Array)
|
|
240
|
-
return `${key}=${value.map(v => JSON.stringify(v)).join(
|
|
250
|
+
return `${key}=${value.map(v => JSON.stringify(v)).join(",")}`;
|
|
241
251
|
// is String
|
|
242
252
|
return `${key}=${item[key]}`;
|
|
243
253
|
});
|
|
244
|
-
return `[CQ:${item.type},${dataStr.join(
|
|
245
|
-
})
|
|
254
|
+
return `[CQ:${item.type},${dataStr.join(",")}]`;
|
|
255
|
+
})
|
|
256
|
+
.join("");
|
|
246
257
|
}
|
|
247
258
|
formatEventPayload(uin, version, event, data) {
|
|
248
259
|
const result = {
|
|
249
260
|
id: data.id,
|
|
250
|
-
[version ===
|
|
261
|
+
[version === "V12" ? "type" : "post_type"]: event,
|
|
251
262
|
version: version,
|
|
252
263
|
self: {
|
|
253
|
-
platform:
|
|
254
|
-
user_id: data.self_id
|
|
264
|
+
platform: "qq",
|
|
265
|
+
user_id: data.self_id,
|
|
255
266
|
},
|
|
256
267
|
detail_type: data.message_type || data.notice_type || data.request_type,
|
|
257
|
-
platform:
|
|
268
|
+
platform: "qq",
|
|
258
269
|
time: data.timestamp,
|
|
259
270
|
...data,
|
|
260
271
|
};
|
|
@@ -265,9 +276,9 @@ class QQAdapter extends adapter_1.Adapter {
|
|
|
265
276
|
const oneBot = this.getOneBot(uin);
|
|
266
277
|
switch (version) {
|
|
267
278
|
case "V11":
|
|
268
|
-
oneBot.V11.transformStrToIntForObj(result, [
|
|
269
|
-
oneBot.V11.transformStrToIntForObj(result.sender, [
|
|
270
|
-
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 "]);
|
|
271
282
|
break;
|
|
272
283
|
}
|
|
273
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,46 +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 => {
|
|
211
217
|
if (typeof item === "string")
|
|
212
218
|
return item;
|
|
213
|
-
if (item.type ===
|
|
219
|
+
if (item.type === "text")
|
|
214
220
|
return item.data?.text || item.text;
|
|
215
221
|
const dataStr = Object.entries(item.data).map(([key, value]) => {
|
|
216
222
|
// is Buffer
|
|
217
223
|
if (value instanceof Buffer)
|
|
218
|
-
return `${key}=${value.toString(
|
|
224
|
+
return `${key}=${value.toString("base64")}`;
|
|
219
225
|
// is Object
|
|
220
226
|
if (value instanceof Object)
|
|
221
227
|
return `${key}=${JSON.stringify(value)}`;
|
|
222
228
|
// is Array
|
|
223
229
|
if (value instanceof Array)
|
|
224
|
-
return `${key}=${value.map(v => JSON.stringify(v)).join(
|
|
230
|
+
return `${key}=${value.map(v => JSON.stringify(v)).join(",")}`;
|
|
225
231
|
// is String
|
|
226
232
|
return `${key}=${item[key]}`;
|
|
227
233
|
});
|
|
228
|
-
return `[CQ:${item.type},${dataStr.join(
|
|
229
|
-
})
|
|
234
|
+
return `[CQ:${item.type},${dataStr.join(",")}]`;
|
|
235
|
+
})
|
|
236
|
+
.join("");
|
|
230
237
|
}
|
|
231
238
|
async getFriendList(uin, version) {
|
|
232
239
|
const bot = this.getOneBot(uin);
|
|
@@ -235,7 +242,9 @@ class WechatAdapter extends adapter_1.Adapter {
|
|
|
235
242
|
return {
|
|
236
243
|
...friend,
|
|
237
244
|
user_name: friend.nickname,
|
|
238
|
-
user_id: version === "V11"
|
|
245
|
+
user_id: version === "V11"
|
|
246
|
+
? bot.V11.transformToInt("friend", friend.user_id)
|
|
247
|
+
: friend.user_id,
|
|
239
248
|
};
|
|
240
249
|
});
|
|
241
250
|
}
|
|
@@ -245,7 +254,9 @@ class WechatAdapter extends adapter_1.Adapter {
|
|
|
245
254
|
return result.map(group => {
|
|
246
255
|
return {
|
|
247
256
|
...group,
|
|
248
|
-
group_id: version === "V11"
|
|
257
|
+
group_id: version === "V11"
|
|
258
|
+
? bot.V11.transformToInt("group", group.group_id)
|
|
259
|
+
: group.group_id,
|
|
249
260
|
};
|
|
250
261
|
});
|
|
251
262
|
}
|
|
@@ -253,14 +264,14 @@ class WechatAdapter extends adapter_1.Adapter {
|
|
|
253
264
|
const bot = this.getOneBot(uin);
|
|
254
265
|
const result = {
|
|
255
266
|
id: data.id,
|
|
256
|
-
[version ===
|
|
267
|
+
[version === "V12" ? "type" : "post_type"]: event,
|
|
257
268
|
version: version,
|
|
258
269
|
self: {
|
|
259
|
-
platform:
|
|
260
|
-
user_id: data.self_id
|
|
270
|
+
platform: "wechat",
|
|
271
|
+
user_id: data.self_id,
|
|
261
272
|
},
|
|
262
273
|
detail_type: data.message_type || data.notice_type || data.request_type,
|
|
263
|
-
platform:
|
|
274
|
+
platform: "wechat",
|
|
264
275
|
group: data.group?.info,
|
|
265
276
|
member: data.member?.info,
|
|
266
277
|
friend: data.friend?.info,
|
|
@@ -270,13 +281,13 @@ class WechatAdapter extends adapter_1.Adapter {
|
|
|
270
281
|
delete result.bot;
|
|
271
282
|
delete result.c;
|
|
272
283
|
delete result.parser;
|
|
273
|
-
if (version ===
|
|
274
|
-
bot.V11.transformStrToIntForObj(result, [
|
|
275
|
-
bot.V11.transformStrToIntForObj(result.self, [
|
|
276
|
-
bot.V11.transformStrToIntForObj(result.sender, [
|
|
277
|
-
bot.V11.transformStrToIntForObj(result.group, [
|
|
278
|
-
bot.V11.transformStrToIntForObj(result.member, [
|
|
279
|
-
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"]);
|
|
280
291
|
}
|
|
281
292
|
return result;
|
|
282
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();
|