@takibeiy/moltbot_cn 2026.1.27-beta.1 → 2026.1.27

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.
@@ -233,6 +233,13 @@ export class OneBotClient {
233
233
  this.state = "disconnected";
234
234
  this.ws = null;
235
235
 
236
+ // Clean up pending requests to prevent memory leak
237
+ for (const [echo, pending] of this.pendingRequests) {
238
+ clearTimeout(pending.timeoutId);
239
+ pending.reject(new Error(`Connection closed (code: ${code})`));
240
+ }
241
+ this.pendingRequests.clear();
242
+
236
243
  this.events.onDisconnect?.(code, reason.toString());
237
244
 
238
245
  // Auto-reconnect if enabled and not manually disconnected
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@takibeiy/moltbot_cn",
3
- "version": "2026.1.27-beta.1",
3
+ "version": "2026.1.27",
4
4
  "description": "Multi-channel AI assistant gateway (QQ, Telegram, WhatsApp, Discord, Slack)",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -1,82 +0,0 @@
1
- /**
2
- * QQ Connection Test Script
3
- *
4
- * Tests connection to NapCat OneBot WebSocket server.
5
- * Run with: npx tsx extensions/qq/test-connection.ts
6
- */
7
-
8
- import WebSocket from "ws";
9
-
10
- const WS_URL = "ws://127.0.0.1:3001";
11
-
12
- console.log(`\n🔌 Connecting to NapCat at ${WS_URL}...\n`);
13
-
14
- const ws = new WebSocket(WS_URL);
15
-
16
- ws.on("open", () => {
17
- console.log("✅ Connected to NapCat!\n");
18
-
19
- // Request login info
20
- const request = {
21
- action: "get_login_info",
22
- params: {},
23
- echo: "test_login_info"
24
- };
25
-
26
- console.log("📤 Sending get_login_info request...");
27
- ws.send(JSON.stringify(request));
28
- });
29
-
30
- ws.on("message", (data) => {
31
- try {
32
- const message = JSON.parse(data.toString());
33
-
34
- // Check if it's our API response
35
- if (message.echo === "test_login_info") {
36
- if (message.status === "ok") {
37
- console.log("\n✅ Login info received:");
38
- console.log(` QQ号: ${message.data.user_id}`);
39
- console.log(` 昵称: ${message.data.nickname}`);
40
- } else {
41
- console.log("\n❌ API call failed:", message.message || message.wording);
42
- }
43
-
44
- // Close connection after getting info
45
- setTimeout(() => {
46
- console.log("\n👋 Closing connection...");
47
- ws.close();
48
- }, 500);
49
- return;
50
- }
51
-
52
- // It's an event
53
- if (message.post_type === "message") {
54
- const chatType = message.message_type === "group" ? "群聊" : "私聊";
55
- const sender = message.sender?.nickname || message.user_id;
56
- console.log(`\n📨 收到${chatType}消息 [${sender}]: ${message.raw_message?.slice(0, 50)}...`);
57
- } else if (message.post_type === "meta_event" && message.meta_event_type === "heartbeat") {
58
- console.log("💓 Heartbeat");
59
- } else if (message.post_type === "meta_event" && message.meta_event_type === "lifecycle") {
60
- console.log(`🔄 Lifecycle event: ${message.sub_type}`);
61
- }
62
- } catch (err) {
63
- console.log("⚠️ Failed to parse message:", data.toString().slice(0, 100));
64
- }
65
- });
66
-
67
- ws.on("error", (error) => {
68
- console.error("\n❌ Connection error:", error.message);
69
- console.log("\n提示: 请确保 NapCat 已启动且 WebSocket 服务器已配置在端口 3001");
70
- process.exit(1);
71
- });
72
-
73
- ws.on("close", (code, reason) => {
74
- console.log(`\n🔌 Connection closed (code: ${code})`);
75
- process.exit(0);
76
- });
77
-
78
- // Timeout after 10 seconds
79
- setTimeout(() => {
80
- console.log("\n⏱️ Timeout - closing connection");
81
- ws.close();
82
- }, 10000);
@@ -1,98 +0,0 @@
1
- /**
2
- * QQ Send Message Test
3
- *
4
- * Tests sending a message via OneBot API.
5
- * Usage: npx tsx extensions/qq/test-send.ts <target> <message>
6
- *
7
- * Examples:
8
- * npx tsx extensions/qq/test-send.ts 123456789 "Hello!"
9
- * npx tsx extensions/qq/test-send.ts group:740112783 "Hello group!"
10
- */
11
-
12
- import WebSocket from "ws";
13
-
14
- const WS_URL = "ws://127.0.0.1:3001";
15
-
16
- // Parse arguments
17
- const args = process.argv.slice(2);
18
- if (args.length < 2) {
19
- console.log("Usage: npx tsx extensions/qq/test-send.ts <target> <message>");
20
- console.log("");
21
- console.log("Examples:");
22
- console.log(' npx tsx extensions/qq/test-send.ts 123456789 "Hello!"');
23
- console.log(' npx tsx extensions/qq/test-send.ts group:740112783 "Hello group!"');
24
- process.exit(1);
25
- }
26
-
27
- const [target, ...messageParts] = args;
28
- const message = messageParts.join(" ");
29
-
30
- // Parse target
31
- const isGroup = target.startsWith("group:");
32
- const targetId = isGroup ? Number(target.slice(6)) : Number(target);
33
-
34
- if (Number.isNaN(targetId)) {
35
- console.error("❌ Invalid target ID:", target);
36
- process.exit(1);
37
- }
38
-
39
- console.log(`\n🔌 Connecting to NapCat at ${WS_URL}...`);
40
-
41
- const ws = new WebSocket(WS_URL);
42
-
43
- ws.on("open", () => {
44
- console.log("✅ Connected!\n");
45
-
46
- const action = isGroup ? "send_group_msg" : "send_private_msg";
47
- const params = isGroup
48
- ? { group_id: targetId, message: [{ type: "text", data: { text: message } }] }
49
- : { user_id: targetId, message: [{ type: "text", data: { text: message } }] };
50
-
51
- const request = {
52
- action,
53
- params,
54
- echo: "test_send"
55
- };
56
-
57
- console.log(`📤 Sending ${isGroup ? "group" : "private"} message to ${targetId}...`);
58
- console.log(` Content: "${message}"`);
59
- ws.send(JSON.stringify(request));
60
- });
61
-
62
- ws.on("message", (data) => {
63
- try {
64
- const response = JSON.parse(data.toString());
65
-
66
- if (response.echo === "test_send") {
67
- if (response.status === "ok") {
68
- console.log(`\n✅ Message sent successfully!`);
69
- console.log(` Message ID: ${response.data?.message_id}`);
70
- } else {
71
- console.log(`\n❌ Failed to send message:`);
72
- console.log(` Error: ${response.message || response.wording || "Unknown error"}`);
73
- console.log(` Retcode: ${response.retcode}`);
74
- }
75
-
76
- setTimeout(() => {
77
- ws.close();
78
- }, 500);
79
- }
80
- } catch {
81
- // Ignore parse errors
82
- }
83
- });
84
-
85
- ws.on("error", (error) => {
86
- console.error("\n❌ Connection error:", error.message);
87
- process.exit(1);
88
- });
89
-
90
- ws.on("close", () => {
91
- console.log("\n👋 Done!");
92
- process.exit(0);
93
- });
94
-
95
- setTimeout(() => {
96
- console.log("\n⏱️ Timeout");
97
- ws.close();
98
- }, 10000);