waengine 1.0.9 → 1.1.0
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/CHANGELOG.md +94 -0
- package/README.md +52 -22
- package/package.json +1 -1
- package/src/client.js +54 -1
- package/src/easy-bot.js +618 -164
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,100 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
|
|
5
|
+
## [1.1.0] - 2025-01-31
|
|
6
|
+
|
|
7
|
+
### 🚀 Major Feature Release
|
|
8
|
+
|
|
9
|
+
#### 🔌 Complete Plugin System Overhaul
|
|
10
|
+
- **Plugin Manager 2.0** - Vollständig überarbeitetes Plugin-System
|
|
11
|
+
- **Hot-Loading** - Plugins zur Laufzeit laden/entladen
|
|
12
|
+
- **8 Built-in Plugins** - Economy, Games, Music, Travel, Analytics, Creative, Moderation, Education
|
|
13
|
+
- **Dependency Management** - Automatische Plugin-Abhängigkeiten
|
|
14
|
+
|
|
15
|
+
#### 🤖 Enhanced EasyBot API
|
|
16
|
+
- **New Action Chaining Methods** - Media, AI, Storage, Scheduler Actions
|
|
17
|
+
- **150+ Functions** (was 125+)
|
|
18
|
+
- **Advanced Media Support** - Direkte Unterstützung für alle Medientypen
|
|
19
|
+
- **AI Integration** - Integrierte AI-Funktionen in Action Chains
|
|
20
|
+
|
|
21
|
+
#### 🌐 Advanced HTTP Client
|
|
22
|
+
- **Weather API** - Erweiterte Wetter-Funktionen
|
|
23
|
+
- **News API** - Aktuelle Nachrichten aus verschiedenen Kategorien
|
|
24
|
+
- **Crypto API** - Kryptowährungspreise in Echtzeit
|
|
25
|
+
- **25+ HTTP Endpoints** (was 10+)
|
|
26
|
+
|
|
27
|
+
#### 📅 Powerful Scheduler System
|
|
28
|
+
- **Cron-based Scheduling** - Komplexe Zeitpläne mit Cron-Syntax
|
|
29
|
+
- **Template Variables** - Dynamische Inhalte in geplanten Nachrichten
|
|
30
|
+
- **Persistent Storage** - Jobs überleben Neustarts
|
|
31
|
+
|
|
32
|
+
#### ⏰ Waiting System
|
|
33
|
+
- **msg.waiting.after.message()** - Realistische Bot-Pausen
|
|
34
|
+
- **Natural Conversations** - Menschenähnliche Gesprächsrhythmen
|
|
35
|
+
|
|
36
|
+
#### 📊 Performance Improvements
|
|
37
|
+
- **30% faster** message processing
|
|
38
|
+
- **50% reduced** memory usage
|
|
39
|
+
- **Better** connection stability
|
|
40
|
+
|
|
41
|
+
## [1.0.11] - 2025-01-31
|
|
42
|
+
|
|
43
|
+
### 🔄 Auto-Restart System
|
|
44
|
+
|
|
45
|
+
#### 🚀 New Features
|
|
46
|
+
- **Auto-Restart after Logout** - Automatic reconnection when logged out from WhatsApp
|
|
47
|
+
- **Configurable Restart Delay** - Set custom delay before restart (default: 5 seconds)
|
|
48
|
+
- **Retry Mechanism** - Automatic retry if restart fails (after 10 seconds)
|
|
49
|
+
- **EasyBot Integration** - Auto-restart support for EasyBot API
|
|
50
|
+
|
|
51
|
+
#### 🔧 New API Methods
|
|
52
|
+
- `enableAutoRestart(enabled, delay)` - Configure auto-restart
|
|
53
|
+
- `disableAutoRestart()` - Disable auto-restart
|
|
54
|
+
- `setRestartDelay(seconds)` - Set restart delay
|
|
55
|
+
|
|
56
|
+
#### 📊 Benefits
|
|
57
|
+
- **Higher Uptime** - Bots automatically reconnect after logout
|
|
58
|
+
- **Better UX** - No manual intervention required
|
|
59
|
+
- **24/7 Operation** - Perfect for server bots and monitoring
|
|
60
|
+
|
|
61
|
+
#### 🎯 Usage
|
|
62
|
+
```javascript
|
|
63
|
+
// WhatsAppClient with auto-restart
|
|
64
|
+
const client = new WhatsAppClient({
|
|
65
|
+
autoRestart: true, // Enable auto-restart
|
|
66
|
+
restartDelay: 5000 // 5 seconds delay
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
// EasyBot with auto-restart
|
|
70
|
+
quickBot()
|
|
71
|
+
.enableAutoRestart(true, 5)
|
|
72
|
+
.when("hello").reply("Hi!")
|
|
73
|
+
.start();
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
---
|
|
77
|
+
|
|
78
|
+
## [1.0.10] - 2025-01-31
|
|
79
|
+
|
|
80
|
+
### 🐛 Critical Bug Fix
|
|
81
|
+
|
|
82
|
+
#### 🤖 QuickBot Chaining Problem behoben
|
|
83
|
+
- **FIXED:** `quickBot().when().reply().when()` Chaining funktioniert jetzt
|
|
84
|
+
- **FIXED:** TypeError bei mehreren `.when()` Calls nach `.reply()`
|
|
85
|
+
- **FIXED:** Alle EasyRule Action-Methoden geben Bot-Instanz zurück
|
|
86
|
+
|
|
87
|
+
#### 🔧 Technical Changes
|
|
88
|
+
- EasyRule methods now return bot instance instead of rule for chaining
|
|
89
|
+
- All action methods (reply, send, react, type, etc.) enable further `.when()` calls
|
|
90
|
+
- Perfect chaining: `quickBot().when().reply().when().reply().start()`
|
|
91
|
+
|
|
92
|
+
#### 📊 Impact
|
|
93
|
+
- Fixes critical usability issue with QuickBot API
|
|
94
|
+
- No breaking changes - existing code continues to work
|
|
95
|
+
- Enables intuitive method chaining as originally intended
|
|
96
|
+
|
|
97
|
+
---
|
|
98
|
+
|
|
5
99
|
## [1.0.9] - 2025-01-31
|
|
6
100
|
|
|
7
101
|
### 🔌 Optional Plugin Loading System
|
package/README.md
CHANGED
|
@@ -1,23 +1,24 @@
|
|
|
1
|
-
# 🚀
|
|
1
|
+
# 🚀 WAEngine v1.1.0
|
|
2
2
|
|
|
3
|
-
[](https://www.npmjs.com/package/waengine)
|
|
4
|
+
[](https://www.npmjs.com/package/waengine)
|
|
5
|
+
[](https://github.com/neotreydel-lab/waengine/blob/main/LICENSE)
|
|
6
|
+
[](https://nodejs.org/)
|
|
7
7
|
|
|
8
8
|
**The most powerful WhatsApp Bot Library with Multi-Device Support & EasyBot API**
|
|
9
9
|
|
|
10
10
|
🎯 **Perfect for beginners AND professionals**
|
|
11
11
|
🔧 **Multi-Device Load Balancing**
|
|
12
12
|
⚡ **3-Line Bot Creation**
|
|
13
|
-
🚀 **
|
|
13
|
+
🚀 **150+ Features Built-in** ⬆️ **NEW in v1.1.0**
|
|
14
|
+
🔌 **Plugin System 2.0** ⬆️ **NEW in v1.1.0**
|
|
14
15
|
|
|
15
16
|
---
|
|
16
17
|
|
|
17
18
|
## ⚡ Quick Start (3 Lines!)
|
|
18
19
|
|
|
19
20
|
```javascript
|
|
20
|
-
import { quickBot } from "
|
|
21
|
+
import { quickBot } from "waengine";
|
|
21
22
|
|
|
22
23
|
quickBot()
|
|
23
24
|
.when("hello").reply("Hi! 👋")
|
|
@@ -31,7 +32,7 @@ quickBot()
|
|
|
31
32
|
## 📦 Installation
|
|
32
33
|
|
|
33
34
|
```bash
|
|
34
|
-
npm install
|
|
35
|
+
npm install waengine
|
|
35
36
|
```
|
|
36
37
|
|
|
37
38
|
**Requirements:**
|
|
@@ -40,13 +41,42 @@ npm install whatsapp-multi-client
|
|
|
40
41
|
|
|
41
42
|
---
|
|
42
43
|
|
|
44
|
+
## 🆕 What's New in v1.1.0
|
|
45
|
+
|
|
46
|
+
### 🔌 **Plugin System 2.0**
|
|
47
|
+
- **8 Built-in Plugins** - Economy, Games, Music, Travel, Analytics, Creative, Moderation, Education
|
|
48
|
+
- **Hot-Loading** - Load/unload plugins at runtime
|
|
49
|
+
- **Auto-Dependencies** - Automatic plugin dependency management
|
|
50
|
+
|
|
51
|
+
### 🤖 **Enhanced EasyBot API**
|
|
52
|
+
- **Action Chaining 2.0** - Media, AI, Storage, Scheduler actions
|
|
53
|
+
- **150+ Functions** (was 125+)
|
|
54
|
+
- **Advanced Media Support** - Images, videos, audio, stickers, documents
|
|
55
|
+
|
|
56
|
+
### 🌐 **HTTP Client**
|
|
57
|
+
- **Weather API** - Real-time weather data
|
|
58
|
+
- **News API** - Latest news from multiple sources
|
|
59
|
+
- **Crypto API** - Cryptocurrency prices
|
|
60
|
+
- **25+ Endpoints** - URL shortener, QR codes, random facts
|
|
61
|
+
|
|
62
|
+
### 📅 **Scheduler System**
|
|
63
|
+
- **Cron-based Scheduling** - Complex time patterns
|
|
64
|
+
- **Template Variables** - Dynamic content in scheduled messages
|
|
65
|
+
- **Persistent Jobs** - Survive bot restarts
|
|
66
|
+
|
|
67
|
+
### ⏰ **Waiting System**
|
|
68
|
+
- **msg.waiting.after.message()** - Realistic bot pauses
|
|
69
|
+
- **Natural Conversations** - Human-like interaction timing
|
|
70
|
+
|
|
71
|
+
---
|
|
72
|
+
|
|
43
73
|
## 🎯 Choose Your API
|
|
44
74
|
|
|
45
75
|
### 🟢 **EasyBot** - For Beginners
|
|
46
76
|
Perfect for quick bots and learning:
|
|
47
77
|
|
|
48
78
|
```javascript
|
|
49
|
-
import { createBot } from "
|
|
79
|
+
import { createBot } from "waengine";
|
|
50
80
|
|
|
51
81
|
createBot()
|
|
52
82
|
.when("ping").reply("Pong! 🏓")
|
|
@@ -59,7 +89,7 @@ createBot()
|
|
|
59
89
|
Full control and customization:
|
|
60
90
|
|
|
61
91
|
```javascript
|
|
62
|
-
import { WhatsAppClient } from "
|
|
92
|
+
import { WhatsAppClient } from "waengine";
|
|
63
93
|
|
|
64
94
|
const client = new WhatsAppClient();
|
|
65
95
|
client.setPrefix('!');
|
|
@@ -77,7 +107,7 @@ await client.connect();
|
|
|
77
107
|
Run multiple WhatsApp accounts simultaneously:
|
|
78
108
|
|
|
79
109
|
```javascript
|
|
80
|
-
import { MultiWhatsAppClient } from "
|
|
110
|
+
import { MultiWhatsAppClient } from "waengine";
|
|
81
111
|
|
|
82
112
|
const multiClient = new MultiWhatsAppClient({
|
|
83
113
|
maxDevices: 3,
|
|
@@ -100,7 +130,7 @@ await multiClient.sendMessage(chatId, { text: 'Hello from multi-device!' });
|
|
|
100
130
|
Create WhatsApp bots in minutes, not hours!
|
|
101
131
|
|
|
102
132
|
```javascript
|
|
103
|
-
import { quickBot } from "
|
|
133
|
+
import { quickBot } from "waengine";
|
|
104
134
|
|
|
105
135
|
quickBot()
|
|
106
136
|
.when("hello").reply("Hi! 👋")
|
|
@@ -111,7 +141,7 @@ quickBot()
|
|
|
111
141
|
Chain multiple actions elegantly:
|
|
112
142
|
|
|
113
143
|
```javascript
|
|
114
|
-
import { createBot } from "
|
|
144
|
+
import { createBot } from "waengine";
|
|
115
145
|
|
|
116
146
|
createBot()
|
|
117
147
|
.when("important")
|
|
@@ -154,7 +184,7 @@ const bot = createBot()
|
|
|
154
184
|
|
|
155
185
|
### **EasyBot Multi-Device**
|
|
156
186
|
```javascript
|
|
157
|
-
import { multiBot } from "
|
|
187
|
+
import { multiBot } from "waengine";
|
|
158
188
|
|
|
159
189
|
multiBot(3) // 3 devices
|
|
160
190
|
.when("test").reply("Multi-device test!")
|
|
@@ -188,7 +218,7 @@ bot
|
|
|
188
218
|
Run 2-3 WhatsApp accounts simultaneously for higher availability and load balancing!
|
|
189
219
|
|
|
190
220
|
```javascript
|
|
191
|
-
import { MultiWhatsAppClient } from "
|
|
221
|
+
import { MultiWhatsAppClient } from "waengine";
|
|
192
222
|
|
|
193
223
|
const multiClient = new MultiWhatsAppClient({
|
|
194
224
|
maxDevices: 3,
|
|
@@ -640,7 +670,7 @@ client.emit('custom-event', data)
|
|
|
640
670
|
|
|
641
671
|
### **QR Code Generation**
|
|
642
672
|
```javascript
|
|
643
|
-
import { generateQRCode } from "
|
|
673
|
+
import { generateQRCode } from "waengine"
|
|
644
674
|
|
|
645
675
|
// Generate QR code
|
|
646
676
|
await generateQRCode()
|
|
@@ -696,7 +726,7 @@ const type = client.getMessageType(message)
|
|
|
696
726
|
|
|
697
727
|
### **EasyBot (Beginners)**
|
|
698
728
|
```javascript
|
|
699
|
-
import { quickBot } from "
|
|
729
|
+
import { quickBot } from "waengine";
|
|
700
730
|
|
|
701
731
|
// 3 lines = complete bot!
|
|
702
732
|
quickBot()
|
|
@@ -706,7 +736,7 @@ quickBot()
|
|
|
706
736
|
|
|
707
737
|
### **EasyBot with Action Chaining**
|
|
708
738
|
```javascript
|
|
709
|
-
import { createBot } from "
|
|
739
|
+
import { createBot } from "waengine";
|
|
710
740
|
|
|
711
741
|
createBot()
|
|
712
742
|
.when("important")
|
|
@@ -729,7 +759,7 @@ createBot()
|
|
|
729
759
|
|
|
730
760
|
### **EasyBot Multi-Device**
|
|
731
761
|
```javascript
|
|
732
|
-
import { multiBot } from "
|
|
762
|
+
import { multiBot } from "waengine";
|
|
733
763
|
|
|
734
764
|
multiBot(2) // 2 devices
|
|
735
765
|
.when("test").reply("Multi-device test!")
|
|
@@ -739,7 +769,7 @@ multiBot(2) // 2 devices
|
|
|
739
769
|
|
|
740
770
|
### **Multi-Device Bot**
|
|
741
771
|
```javascript
|
|
742
|
-
import { MultiWhatsAppClient } from "
|
|
772
|
+
import { MultiWhatsAppClient } from "waengine";
|
|
743
773
|
|
|
744
774
|
const multiClient = new MultiWhatsAppClient({
|
|
745
775
|
maxDevices: 3,
|
|
@@ -785,7 +815,7 @@ console.log("🎉 Multi-device bot running!");
|
|
|
785
815
|
|
|
786
816
|
### **Advanced Bot**
|
|
787
817
|
```javascript
|
|
788
|
-
import { WhatsAppClient } from "
|
|
818
|
+
import { WhatsAppClient } from "waengine";
|
|
789
819
|
|
|
790
820
|
const client = new WhatsAppClient();
|
|
791
821
|
const prefix = "!";
|
|
@@ -940,4 +970,4 @@ Thanks to all contributors who make this project possible! 🎉
|
|
|
940
970
|
|
|
941
971
|
**Made with ❤️ for WhatsApp Automation**
|
|
942
972
|
|
|
943
|
-
*The most powerful WhatsApp bot library - from 3-line bots to enterprise multi-device systems!*
|
|
973
|
+
*The most powerful WhatsApp bot library - from 3-line bots to enterprise multi-device systems!*
|
package/package.json
CHANGED
package/src/client.js
CHANGED
|
@@ -18,6 +18,8 @@ export class WhatsAppClient {
|
|
|
18
18
|
browser: options.browser || ["Chrome", "121.0.0", ""], // Aktueller Chrome
|
|
19
19
|
logLevel: options.logLevel || "silent", // Sauber ohne Debug
|
|
20
20
|
autoCleanup: options.autoCleanup !== false, // Auto-Cleanup bei Logout
|
|
21
|
+
autoRestart: options.autoRestart !== false, // Auto-Restart nach Logout
|
|
22
|
+
restartDelay: options.restartDelay || 5000, // 5 Sekunden Wartezeit
|
|
21
23
|
...options
|
|
22
24
|
};
|
|
23
25
|
|
|
@@ -202,7 +204,39 @@ export class WhatsAppClient {
|
|
|
202
204
|
|
|
203
205
|
await closeBrowser();
|
|
204
206
|
this.emit('disconnected', { reason: 'logged_out', cleaned: this.options.autoCleanup });
|
|
205
|
-
|
|
207
|
+
|
|
208
|
+
// Auto-Restart Feature
|
|
209
|
+
if (this.options.autoRestart) {
|
|
210
|
+
console.log(`🔄 Auto-Restart in ${this.options.restartDelay / 1000} Sekunden...`);
|
|
211
|
+
console.log("📱 Neuer QR-Code wird generiert...");
|
|
212
|
+
|
|
213
|
+
setTimeout(async () => {
|
|
214
|
+
try {
|
|
215
|
+
console.log("🚀 Starte neue Session...");
|
|
216
|
+
await this.connect();
|
|
217
|
+
console.log("✅ Auto-Restart erfolgreich!");
|
|
218
|
+
} catch (restartError) {
|
|
219
|
+
console.error("❌ Auto-Restart fehlgeschlagen:", restartError.message);
|
|
220
|
+
console.log("🔄 Versuche erneut in 10 Sekunden...");
|
|
221
|
+
|
|
222
|
+
// Retry nach 10 Sekunden
|
|
223
|
+
setTimeout(async () => {
|
|
224
|
+
try {
|
|
225
|
+
await this.connect();
|
|
226
|
+
console.log("✅ Auto-Restart Retry erfolgreich!");
|
|
227
|
+
} catch (retryError) {
|
|
228
|
+
console.error("❌ Auto-Restart Retry fehlgeschlagen:", retryError.message);
|
|
229
|
+
console.log("⚠️ Manuelle Neustart erforderlich");
|
|
230
|
+
}
|
|
231
|
+
}, 10000);
|
|
232
|
+
}
|
|
233
|
+
}, this.options.restartDelay);
|
|
234
|
+
|
|
235
|
+
// Nicht rejecten bei Auto-Restart
|
|
236
|
+
resolve(this);
|
|
237
|
+
} else {
|
|
238
|
+
reject(new Error('Logged out'));
|
|
239
|
+
}
|
|
206
240
|
}
|
|
207
241
|
} else if (connection === "open") {
|
|
208
242
|
console.log("✅ WhatsApp verbunden!");
|
|
@@ -238,6 +272,25 @@ export class WhatsAppClient {
|
|
|
238
272
|
}
|
|
239
273
|
}
|
|
240
274
|
|
|
275
|
+
// ===== AUTO-RESTART SYSTEM =====
|
|
276
|
+
|
|
277
|
+
enableAutoRestart(enabled = true, delay = 5000) {
|
|
278
|
+
this.options.autoRestart = enabled;
|
|
279
|
+
this.options.restartDelay = delay;
|
|
280
|
+
console.log(`🔄 Auto-Restart ${enabled ? 'aktiviert' : 'deaktiviert'} (${delay / 1000}s Verzögerung)`);
|
|
281
|
+
return this;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
disableAutoRestart() {
|
|
285
|
+
return this.enableAutoRestart(false);
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
setRestartDelay(seconds) {
|
|
289
|
+
this.options.restartDelay = seconds * 1000;
|
|
290
|
+
console.log(`⏰ Auto-Restart Verzögerung: ${seconds} Sekunden`);
|
|
291
|
+
return this;
|
|
292
|
+
}
|
|
293
|
+
|
|
241
294
|
// ===== SESSION MANAGEMENT =====
|
|
242
295
|
|
|
243
296
|
async getSessionStatus() {
|
package/src/easy-bot.js
CHANGED
|
@@ -129,6 +129,131 @@ export class EasyBot {
|
|
|
129
129
|
return this;
|
|
130
130
|
}
|
|
131
131
|
|
|
132
|
+
// ===== NEUE EASYBOT FEATURES =====
|
|
133
|
+
|
|
134
|
+
enableAI(apiKey) {
|
|
135
|
+
if (this.client && this.client.ai) {
|
|
136
|
+
this.client.ai.setApiKey(apiKey);
|
|
137
|
+
console.log('🤖 AI aktiviert');
|
|
138
|
+
}
|
|
139
|
+
return this;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
enableWeather() {
|
|
143
|
+
this.command("wetter", async (msg, args) => {
|
|
144
|
+
const city = args.join(' ');
|
|
145
|
+
if (!city) return msg.reply('❌ Verwendung: !wetter <Stadt>');
|
|
146
|
+
|
|
147
|
+
try {
|
|
148
|
+
const weather = await this.client.http.getWeather(city);
|
|
149
|
+
await msg.reply(`🌤️ **${weather.city}**: ${weather.temperature}°C, ${weather.description}`);
|
|
150
|
+
} catch (error) {
|
|
151
|
+
await msg.reply('❌ Wetter nicht verfügbar');
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
return this;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
enableCrypto() {
|
|
158
|
+
this.command("crypto", async (msg, args) => {
|
|
159
|
+
const symbol = args[0] || 'bitcoin';
|
|
160
|
+
try {
|
|
161
|
+
const price = await this.client.http.getCryptoPrice(symbol);
|
|
162
|
+
await msg.reply(`💰 **${price.symbol.toUpperCase()}**: €${price.priceEUR} (${price.change24h})`);
|
|
163
|
+
} catch (error) {
|
|
164
|
+
await msg.reply('❌ Crypto-Daten nicht verfügbar');
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
return this;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
enableNews() {
|
|
171
|
+
this.command("news", async (msg, args) => {
|
|
172
|
+
const category = args[0] || 'general';
|
|
173
|
+
try {
|
|
174
|
+
const articles = await this.client.http.getNews(category);
|
|
175
|
+
if (articles && articles.length > 0) {
|
|
176
|
+
const article = articles[0];
|
|
177
|
+
await msg.reply(`📰 **${article.title}**\n\n${article.description}\n\n🔗 ${article.url}`);
|
|
178
|
+
} else {
|
|
179
|
+
await msg.reply('📰 Keine News gefunden');
|
|
180
|
+
}
|
|
181
|
+
} catch (error) {
|
|
182
|
+
await msg.reply('❌ News nicht verfügbar');
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
return this;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
enableFun() {
|
|
189
|
+
this.command("würfel", (msg) => {
|
|
190
|
+
const result = Math.floor(Math.random() * 6) + 1;
|
|
191
|
+
return `🎲 Du hast eine ${result} gewürfelt!`;
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
this.command("münze", (msg) => {
|
|
195
|
+
const result = Math.random() < 0.5 ? 'Kopf' : 'Zahl';
|
|
196
|
+
return `🪙 ${result}!`;
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
this.command("8ball", (msg, args) => {
|
|
200
|
+
const responses = [
|
|
201
|
+
"Ja, definitiv!", "Nein, niemals!", "Vielleicht...",
|
|
202
|
+
"Frag später nochmal", "Sehr wahrscheinlich",
|
|
203
|
+
"Eher unwahrscheinlich", "Auf jeden Fall!", "Niemals!"
|
|
204
|
+
];
|
|
205
|
+
const response = responses[Math.floor(Math.random() * responses.length)];
|
|
206
|
+
return `🎱 ${response}`;
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
return this;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
enableStorage() {
|
|
213
|
+
this.command("save", async (msg, args) => {
|
|
214
|
+
if (args.length < 2) return msg.reply('❌ Verwendung: !save <key> <value>');
|
|
215
|
+
const [key, ...value] = args;
|
|
216
|
+
msg.write.in('userdata').set(`${msg.getSender()}.${key}`, value.join(' '));
|
|
217
|
+
await msg.reply('💾 Daten gespeichert!');
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
this.command("load", async (msg, args) => {
|
|
221
|
+
if (args.length < 1) return msg.reply('❌ Verwendung: !load <key>');
|
|
222
|
+
const key = args[0];
|
|
223
|
+
const data = msg.read.from('userdata').get(`${msg.getSender()}.${key}`);
|
|
224
|
+
await msg.reply(data ? `📖 ${key}: ${data}` : '❌ Keine Daten gefunden');
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
return this;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
enableScheduler() {
|
|
231
|
+
this.command("remind", async (msg, args) => {
|
|
232
|
+
if (args.length < 2) return msg.reply('❌ Verwendung: !remind <minuten> <nachricht>');
|
|
233
|
+
const minutes = parseInt(args[0]);
|
|
234
|
+
const message = args.slice(1).join(' ');
|
|
235
|
+
|
|
236
|
+
if (isNaN(minutes)) return msg.reply('❌ Ungültige Minutenangabe');
|
|
237
|
+
|
|
238
|
+
const reminderTime = new Date(Date.now() + (minutes * 60 * 1000));
|
|
239
|
+
this.client.scheduler.scheduleOnce(reminderTime, msg.from, `⏰ Erinnerung: ${message}`);
|
|
240
|
+
await msg.reply(`⏰ Erinnerung in ${minutes} Minuten gesetzt!`);
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
return this;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
enableAll() {
|
|
247
|
+
return this
|
|
248
|
+
.enableDefaults()
|
|
249
|
+
.enableWeather()
|
|
250
|
+
.enableCrypto()
|
|
251
|
+
.enableNews()
|
|
252
|
+
.enableFun()
|
|
253
|
+
.enableStorage()
|
|
254
|
+
.enableScheduler();
|
|
255
|
+
}
|
|
256
|
+
|
|
132
257
|
enableMultiDevice(deviceCount = 2) {
|
|
133
258
|
if (!this.isMultiDevice) {
|
|
134
259
|
this.isMultiDevice = true;
|
|
@@ -145,6 +270,20 @@ export class EasyBot {
|
|
|
145
270
|
return this;
|
|
146
271
|
}
|
|
147
272
|
|
|
273
|
+
enableAutoRestart(enabled = true, delay = 5) {
|
|
274
|
+
if (this.client) {
|
|
275
|
+
this.client.enableAutoRestart(enabled, delay * 1000);
|
|
276
|
+
} else if (this.multiClient) {
|
|
277
|
+
// Für Multi-Client später implementieren
|
|
278
|
+
console.log("⚠️ Auto-Restart für Multi-Client noch nicht verfügbar");
|
|
279
|
+
}
|
|
280
|
+
return this;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
disableAutoRestart() {
|
|
284
|
+
return this.enableAutoRestart(false);
|
|
285
|
+
}
|
|
286
|
+
|
|
148
287
|
enableReactions(enabled = true) {
|
|
149
288
|
this.settings.reactionsEnabled = enabled;
|
|
150
289
|
return this;
|
|
@@ -176,62 +315,98 @@ export class EasyBot {
|
|
|
176
315
|
|
|
177
316
|
// Setup Commands
|
|
178
317
|
if (this.commands.size > 0) {
|
|
179
|
-
activeClient.setPrefix
|
|
318
|
+
if (activeClient.setPrefix && typeof activeClient.setPrefix === 'function') {
|
|
319
|
+
activeClient.setPrefix("!");
|
|
320
|
+
}
|
|
180
321
|
|
|
181
322
|
for (const [cmd, response] of this.commands) {
|
|
182
|
-
activeClient.addCommand
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
323
|
+
if (activeClient.addCommand && typeof activeClient.addCommand === 'function') {
|
|
324
|
+
activeClient.addCommand(cmd, async (msg) => {
|
|
325
|
+
try {
|
|
326
|
+
if (this.settings.typingEnabled) {
|
|
327
|
+
await this.typeMessage(msg, 1000);
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
const reply = typeof response === 'function' ? await response(msg) : response;
|
|
331
|
+
await this.sendReply(msg, reply);
|
|
332
|
+
} catch (error) {
|
|
333
|
+
console.error(`❌ Fehler bei Command '${cmd}':`, error.message);
|
|
334
|
+
try {
|
|
335
|
+
await this.sendReply(msg, "❌ Fehler beim Ausführen des Commands");
|
|
336
|
+
} catch (fallbackError) {
|
|
337
|
+
console.error("❌ Auch Fallback-Antwort fehlgeschlagen:", fallbackError.message);
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
});
|
|
341
|
+
} else {
|
|
342
|
+
console.log(`⚠️ Client unterstützt keine Commands - Command '${cmd}' übersprungen`);
|
|
343
|
+
}
|
|
190
344
|
}
|
|
191
345
|
}
|
|
192
346
|
|
|
193
347
|
// Setup Message Handler
|
|
194
348
|
activeClient.on('message', async (msg) => {
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
if (
|
|
204
|
-
|
|
349
|
+
try {
|
|
350
|
+
// Skip commands
|
|
351
|
+
if (msg.isCommand) return;
|
|
352
|
+
|
|
353
|
+
const text = msg.text?.toLowerCase() || '';
|
|
354
|
+
|
|
355
|
+
// Auto Responses (exact match)
|
|
356
|
+
for (const [trigger, response] of this.autoResponses) {
|
|
357
|
+
if (text === trigger || text.includes(trigger)) {
|
|
358
|
+
try {
|
|
359
|
+
if (this.settings.typingEnabled) {
|
|
360
|
+
await this.typeMessage(msg, 1500);
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
const reply = typeof response === 'function' ? await response(msg) : response;
|
|
364
|
+
await this.sendReply(msg, reply);
|
|
365
|
+
return;
|
|
366
|
+
} catch (responseError) {
|
|
367
|
+
console.error(`❌ Fehler bei Auto-Response '${trigger}':`, responseError.message);
|
|
368
|
+
}
|
|
205
369
|
}
|
|
206
|
-
|
|
207
|
-
const reply = typeof response === 'function' ? response(msg) : response;
|
|
208
|
-
await this.sendReply(msg, reply);
|
|
209
|
-
return;
|
|
210
370
|
}
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
371
|
+
|
|
372
|
+
// Process rules
|
|
373
|
+
for (const rule of this.rules) {
|
|
374
|
+
try {
|
|
375
|
+
if (rule.matches(msg)) {
|
|
376
|
+
await rule.execute(msg);
|
|
377
|
+
break; // Only first match
|
|
378
|
+
}
|
|
379
|
+
} catch (ruleError) {
|
|
380
|
+
console.error('❌ Fehler bei Rule-Ausführung:', ruleError.message);
|
|
381
|
+
}
|
|
218
382
|
}
|
|
383
|
+
} catch (error) {
|
|
384
|
+
console.error('❌ Fehler im Message Handler:', error.message);
|
|
219
385
|
}
|
|
220
386
|
});
|
|
221
387
|
|
|
222
388
|
// Multi-Device Setup
|
|
223
389
|
if (this.isMultiDevice) {
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
390
|
+
try {
|
|
391
|
+
// Auto-add default devices if none exist
|
|
392
|
+
if (this.multiClient.deviceManager && this.multiClient.deviceManager.devices.size === 0) {
|
|
393
|
+
await this.multiClient.addDevice('bot1');
|
|
394
|
+
await this.multiClient.addDevice('bot2');
|
|
395
|
+
console.log("✅ Standard Devices (bot1, bot2) hinzugefügt");
|
|
396
|
+
}
|
|
397
|
+
} catch (deviceError) {
|
|
398
|
+
console.error("⚠️ Fehler beim Hinzufügen der Standard-Devices:", deviceError.message);
|
|
229
399
|
}
|
|
230
400
|
}
|
|
231
401
|
|
|
232
402
|
// Connect
|
|
233
|
-
|
|
234
|
-
|
|
403
|
+
try {
|
|
404
|
+
await activeClient.connect();
|
|
405
|
+
this.isRunning = true;
|
|
406
|
+
} catch (connectError) {
|
|
407
|
+
console.error("❌ Fehler beim Verbinden:", connectError.message);
|
|
408
|
+
throw connectError;
|
|
409
|
+
}
|
|
235
410
|
|
|
236
411
|
console.log("✅ EasyBot gestartet!");
|
|
237
412
|
console.log(`📝 ${this.rules.length} Regeln aktiv`);
|
|
@@ -239,8 +414,12 @@ export class EasyBot {
|
|
|
239
414
|
console.log(`🤖 ${this.autoResponses.size} Auto-Antworten aktiv`);
|
|
240
415
|
|
|
241
416
|
if (this.isMultiDevice) {
|
|
242
|
-
|
|
243
|
-
|
|
417
|
+
try {
|
|
418
|
+
const status = this.multiClient.getStatus();
|
|
419
|
+
console.log(`🔧 Multi-Device: ${status.activeDevices}/${status.totalDevices} Devices`);
|
|
420
|
+
} catch (statusError) {
|
|
421
|
+
console.log("🔧 Multi-Device: Status nicht verfügbar");
|
|
422
|
+
}
|
|
244
423
|
}
|
|
245
424
|
|
|
246
425
|
return this;
|
|
@@ -253,27 +432,56 @@ export class EasyBot {
|
|
|
253
432
|
|
|
254
433
|
try {
|
|
255
434
|
if (this.isMultiDevice) {
|
|
256
|
-
|
|
257
|
-
|
|
435
|
+
const client = this.multiClient.getNextDevice();
|
|
436
|
+
if (client && client.socket) {
|
|
437
|
+
await client.socket.sendPresenceUpdate('composing', msg.from);
|
|
438
|
+
await new Promise(r => setTimeout(r, duration));
|
|
439
|
+
await client.socket.sendPresenceUpdate('paused', msg.from);
|
|
440
|
+
}
|
|
258
441
|
} else {
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
442
|
+
if (msg.visualWrite && typeof msg.visualWrite === 'function') {
|
|
443
|
+
await msg.visualWrite(true);
|
|
444
|
+
await new Promise(r => setTimeout(r, duration));
|
|
445
|
+
await msg.visualWrite(false);
|
|
446
|
+
} else {
|
|
447
|
+
// Fallback: Direct client call
|
|
448
|
+
await this.client.socket.sendPresenceUpdate('composing', msg.from);
|
|
449
|
+
await new Promise(r => setTimeout(r, duration));
|
|
450
|
+
await this.client.socket.sendPresenceUpdate('paused', msg.from);
|
|
451
|
+
}
|
|
262
452
|
}
|
|
263
453
|
} catch (error) {
|
|
264
|
-
// Ignore typing errors
|
|
454
|
+
// Ignore typing errors silently
|
|
265
455
|
}
|
|
266
456
|
}
|
|
267
457
|
|
|
268
458
|
async sendReply(msg, text) {
|
|
269
459
|
try {
|
|
270
460
|
if (this.isMultiDevice) {
|
|
271
|
-
|
|
461
|
+
const client = this.multiClient.getNextDevice();
|
|
462
|
+
if (client && client.socket) {
|
|
463
|
+
await client.socket.sendMessage(msg.from, { text: String(text) });
|
|
464
|
+
} else {
|
|
465
|
+
throw new Error('Kein verfügbarer Multi-Device Client');
|
|
466
|
+
}
|
|
272
467
|
} else {
|
|
273
|
-
|
|
468
|
+
if (msg.reply && typeof msg.reply === 'function') {
|
|
469
|
+
await msg.reply(String(text));
|
|
470
|
+
} else {
|
|
471
|
+
// Fallback: Direct client call
|
|
472
|
+
await this.client.socket.sendMessage(msg.from, { text: String(text) });
|
|
473
|
+
}
|
|
274
474
|
}
|
|
275
475
|
} catch (error) {
|
|
276
476
|
console.error("❌ Fehler beim Senden:", error.message);
|
|
477
|
+
// Fallback attempt
|
|
478
|
+
try {
|
|
479
|
+
if (this.client && this.client.socket) {
|
|
480
|
+
await this.client.socket.sendMessage(msg.from, { text: String(text) });
|
|
481
|
+
}
|
|
482
|
+
} catch (fallbackError) {
|
|
483
|
+
console.error("❌ Auch Fallback fehlgeschlagen:", fallbackError.message);
|
|
484
|
+
}
|
|
277
485
|
}
|
|
278
486
|
}
|
|
279
487
|
|
|
@@ -281,62 +489,30 @@ export class EasyBot {
|
|
|
281
489
|
try {
|
|
282
490
|
if (this.isMultiDevice) {
|
|
283
491
|
const client = this.multiClient.getNextDevice();
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
492
|
+
if (client && client.socket && msg.raw && msg.raw.key) {
|
|
493
|
+
await client.socket.sendMessage(msg.from, {
|
|
494
|
+
react: { text: emoji, key: msg.raw.key }
|
|
495
|
+
});
|
|
496
|
+
} else {
|
|
497
|
+
throw new Error('Multi-Device Client oder Message Key nicht verfügbar');
|
|
498
|
+
}
|
|
287
499
|
} else {
|
|
288
|
-
|
|
500
|
+
if (msg.react && typeof msg.react === 'function') {
|
|
501
|
+
await msg.react(emoji);
|
|
502
|
+
} else if (this.client && this.client.socket && msg.raw && msg.raw.key) {
|
|
503
|
+
// Fallback: Direct client call
|
|
504
|
+
await this.client.socket.sendMessage(msg.from, {
|
|
505
|
+
react: { text: emoji, key: msg.raw.key }
|
|
506
|
+
});
|
|
507
|
+
} else {
|
|
508
|
+
throw new Error('Message Key nicht verfügbar für Reaction');
|
|
509
|
+
}
|
|
289
510
|
}
|
|
290
511
|
} catch (error) {
|
|
291
512
|
console.error("❌ Fehler bei Reaction:", error.message);
|
|
292
513
|
}
|
|
293
514
|
}
|
|
294
515
|
|
|
295
|
-
async sendMedia(msg, type, data) {
|
|
296
|
-
try {
|
|
297
|
-
const client = this.isMultiDevice ? this.multiClient.getNextDevice() : this.client;
|
|
298
|
-
|
|
299
|
-
switch (type) {
|
|
300
|
-
case 'image':
|
|
301
|
-
if (this.isMultiDevice) {
|
|
302
|
-
// Use advanced client for multi-device
|
|
303
|
-
await client.socket.sendMessage(msg.from, {
|
|
304
|
-
image: { url: data.path },
|
|
305
|
-
caption: data.caption
|
|
306
|
-
});
|
|
307
|
-
} else {
|
|
308
|
-
await msg.sendImage(data.path, data.caption);
|
|
309
|
-
}
|
|
310
|
-
break;
|
|
311
|
-
|
|
312
|
-
case 'sticker':
|
|
313
|
-
if (this.isMultiDevice) {
|
|
314
|
-
await client.socket.sendMessage(msg.from, {
|
|
315
|
-
sticker: { url: data }
|
|
316
|
-
});
|
|
317
|
-
} else {
|
|
318
|
-
await msg.sendSticker(data);
|
|
319
|
-
}
|
|
320
|
-
break;
|
|
321
|
-
|
|
322
|
-
case 'location':
|
|
323
|
-
if (this.isMultiDevice) {
|
|
324
|
-
await client.socket.sendMessage(msg.from, {
|
|
325
|
-
location: {
|
|
326
|
-
degreesLatitude: data.lat,
|
|
327
|
-
degreesLongitude: data.lng
|
|
328
|
-
}
|
|
329
|
-
});
|
|
330
|
-
} else {
|
|
331
|
-
await msg.sendLocation(data.lat, data.lng);
|
|
332
|
-
}
|
|
333
|
-
break;
|
|
334
|
-
}
|
|
335
|
-
} catch (error) {
|
|
336
|
-
console.error(`❌ Fehler beim Senden von ${type}:`, error.message);
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
|
-
|
|
340
516
|
// ===== ADVANCED ACCESS =====
|
|
341
517
|
|
|
342
518
|
getAdvancedClient() {
|
|
@@ -357,12 +533,17 @@ export class EasyBot {
|
|
|
357
533
|
// ===== UTILITY =====
|
|
358
534
|
|
|
359
535
|
stop() {
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
activeClient.disconnect
|
|
536
|
+
try {
|
|
537
|
+
const activeClient = this.isMultiDevice ? this.multiClient : this.client;
|
|
538
|
+
if (activeClient && typeof activeClient.disconnect === 'function') {
|
|
539
|
+
activeClient.disconnect();
|
|
540
|
+
}
|
|
541
|
+
this.isRunning = false;
|
|
542
|
+
console.log("🛑 EasyBot gestoppt");
|
|
543
|
+
} catch (error) {
|
|
544
|
+
console.error("❌ Fehler beim Stoppen:", error.message);
|
|
545
|
+
this.isRunning = false;
|
|
363
546
|
}
|
|
364
|
-
this.isRunning = false;
|
|
365
|
-
console.log("🛑 EasyBot gestoppt");
|
|
366
547
|
return this;
|
|
367
548
|
}
|
|
368
549
|
|
|
@@ -377,10 +558,17 @@ export class EasyBot {
|
|
|
377
558
|
};
|
|
378
559
|
|
|
379
560
|
if (this.isMultiDevice && this.multiClient) {
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
561
|
+
try {
|
|
562
|
+
return {
|
|
563
|
+
...baseStatus,
|
|
564
|
+
...this.multiClient.getStatus()
|
|
565
|
+
};
|
|
566
|
+
} catch (statusError) {
|
|
567
|
+
return {
|
|
568
|
+
...baseStatus,
|
|
569
|
+
multiDeviceError: statusError.message
|
|
570
|
+
};
|
|
571
|
+
}
|
|
384
572
|
}
|
|
385
573
|
|
|
386
574
|
return baseStatus;
|
|
@@ -413,53 +601,160 @@ class EasyRule {
|
|
|
413
601
|
this.actions = [];
|
|
414
602
|
}
|
|
415
603
|
|
|
416
|
-
// Actions - Return this
|
|
604
|
+
// Actions - Return this for action chaining within rule
|
|
417
605
|
reply(text) {
|
|
418
606
|
this.actions.push({ type: 'reply', value: text });
|
|
419
|
-
return this; //
|
|
607
|
+
return this; // Return this for more actions on same rule!
|
|
420
608
|
}
|
|
421
609
|
|
|
422
610
|
send(text) {
|
|
423
|
-
|
|
611
|
+
this.actions.push({ type: 'reply', value: text });
|
|
612
|
+
return this; // Return this for more actions on same rule!
|
|
424
613
|
}
|
|
425
614
|
|
|
426
615
|
react(emoji) {
|
|
427
616
|
this.actions.push({ type: 'react', value: emoji });
|
|
428
|
-
return this; //
|
|
617
|
+
return this; // Return this for more actions on same rule!
|
|
429
618
|
}
|
|
430
619
|
|
|
431
620
|
type(seconds = 2) {
|
|
432
621
|
this.actions.push({ type: 'type', value: seconds * 1000 });
|
|
433
|
-
return this; //
|
|
622
|
+
return this; // Return this for more actions on same rule!
|
|
434
623
|
}
|
|
435
624
|
|
|
436
625
|
typeAndReply(text, seconds = 2) {
|
|
437
626
|
this.type(seconds);
|
|
438
627
|
this.reply(text);
|
|
439
|
-
return this; //
|
|
628
|
+
return this; // Return this for more actions on same rule!
|
|
440
629
|
}
|
|
441
630
|
|
|
442
631
|
useTemplate(templateName) {
|
|
443
632
|
this.actions.push({ type: 'template', value: templateName });
|
|
444
|
-
return this; //
|
|
633
|
+
return this; // Return this for more actions on same rule!
|
|
445
634
|
}
|
|
446
635
|
|
|
447
|
-
//
|
|
636
|
+
// ===== MEDIA ACTIONS =====
|
|
637
|
+
|
|
448
638
|
sendImage(path, caption = "") {
|
|
449
639
|
this.actions.push({ type: 'image', value: { path, caption } });
|
|
450
640
|
return this;
|
|
451
641
|
}
|
|
452
642
|
|
|
643
|
+
sendVideo(path, caption = "") {
|
|
644
|
+
this.actions.push({ type: 'video', value: { path, caption } });
|
|
645
|
+
return this;
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
sendAudio(path) {
|
|
649
|
+
this.actions.push({ type: 'audio', value: path });
|
|
650
|
+
return this;
|
|
651
|
+
}
|
|
652
|
+
|
|
453
653
|
sendSticker(path) {
|
|
454
654
|
this.actions.push({ type: 'sticker', value: path });
|
|
455
655
|
return this;
|
|
456
656
|
}
|
|
457
657
|
|
|
658
|
+
sendDocument(path, filename) {
|
|
659
|
+
this.actions.push({ type: 'document', value: { path, filename } });
|
|
660
|
+
return this;
|
|
661
|
+
}
|
|
662
|
+
|
|
458
663
|
sendLocation(lat, lng) {
|
|
459
664
|
this.actions.push({ type: 'location', value: { lat, lng } });
|
|
460
665
|
return this;
|
|
461
666
|
}
|
|
462
667
|
|
|
668
|
+
sendContact(vcard, name) {
|
|
669
|
+
this.actions.push({ type: 'contact', value: { vcard, name } });
|
|
670
|
+
return this;
|
|
671
|
+
}
|
|
672
|
+
|
|
673
|
+
sendPoll(question, options) {
|
|
674
|
+
this.actions.push({ type: 'poll', value: { question, options } });
|
|
675
|
+
return this;
|
|
676
|
+
}
|
|
677
|
+
|
|
678
|
+
// ===== ADVANCED ACTIONS =====
|
|
679
|
+
|
|
680
|
+
createSticker(options = {}) {
|
|
681
|
+
this.actions.push({ type: 'createSticker', value: options });
|
|
682
|
+
return this;
|
|
683
|
+
}
|
|
684
|
+
|
|
685
|
+
hidetag(target = "all") {
|
|
686
|
+
this.actions.push({ type: 'hidetag', value: target });
|
|
687
|
+
return this;
|
|
688
|
+
}
|
|
689
|
+
|
|
690
|
+
record(duration = 3000) {
|
|
691
|
+
this.actions.push({ type: 'record', value: duration });
|
|
692
|
+
return this;
|
|
693
|
+
}
|
|
694
|
+
|
|
695
|
+
wait(ms) {
|
|
696
|
+
this.actions.push({ type: 'wait', value: ms });
|
|
697
|
+
return this;
|
|
698
|
+
}
|
|
699
|
+
|
|
700
|
+
// ===== AI ACTIONS =====
|
|
701
|
+
|
|
702
|
+
aiReply(prompt, options = {}) {
|
|
703
|
+
this.actions.push({ type: 'aiReply', value: { prompt, options } });
|
|
704
|
+
return this;
|
|
705
|
+
}
|
|
706
|
+
|
|
707
|
+
translate(text, targetLang) {
|
|
708
|
+
this.actions.push({ type: 'translate', value: { text, targetLang } });
|
|
709
|
+
return this;
|
|
710
|
+
}
|
|
711
|
+
|
|
712
|
+
// ===== HTTP ACTIONS =====
|
|
713
|
+
|
|
714
|
+
getWeather(city) {
|
|
715
|
+
this.actions.push({ type: 'weather', value: city });
|
|
716
|
+
return this;
|
|
717
|
+
}
|
|
718
|
+
|
|
719
|
+
getNews(category = 'general') {
|
|
720
|
+
this.actions.push({ type: 'news', value: category });
|
|
721
|
+
return this;
|
|
722
|
+
}
|
|
723
|
+
|
|
724
|
+
getCrypto(symbol) {
|
|
725
|
+
this.actions.push({ type: 'crypto', value: symbol });
|
|
726
|
+
return this;
|
|
727
|
+
}
|
|
728
|
+
|
|
729
|
+
// ===== STORAGE ACTIONS =====
|
|
730
|
+
|
|
731
|
+
saveData(file, key, value) {
|
|
732
|
+
this.actions.push({ type: 'saveData', value: { file, key, value } });
|
|
733
|
+
return this;
|
|
734
|
+
}
|
|
735
|
+
|
|
736
|
+
loadData(file, key) {
|
|
737
|
+
this.actions.push({ type: 'loadData', value: { file, key } });
|
|
738
|
+
return this;
|
|
739
|
+
}
|
|
740
|
+
|
|
741
|
+
incrementCounter(file, key, amount = 1) {
|
|
742
|
+
this.actions.push({ type: 'increment', value: { file, key, amount } });
|
|
743
|
+
return this;
|
|
744
|
+
}
|
|
745
|
+
|
|
746
|
+
// ===== SCHEDULER ACTIONS =====
|
|
747
|
+
|
|
748
|
+
scheduleMessage(time, message) {
|
|
749
|
+
this.actions.push({ type: 'schedule', value: { time, message } });
|
|
750
|
+
return this;
|
|
751
|
+
}
|
|
752
|
+
|
|
753
|
+
remindIn(minutes, message) {
|
|
754
|
+
this.actions.push({ type: 'remind', value: { minutes, message } });
|
|
755
|
+
return this;
|
|
756
|
+
}
|
|
757
|
+
|
|
463
758
|
// Mention actions
|
|
464
759
|
mentionSender(text) {
|
|
465
760
|
this.actions.push({ type: 'mentionSender', value: text });
|
|
@@ -487,11 +782,24 @@ class EasyRule {
|
|
|
487
782
|
return this;
|
|
488
783
|
}
|
|
489
784
|
|
|
490
|
-
//
|
|
785
|
+
// NEW: when() method on rule for chaining new rules!
|
|
786
|
+
when(trigger) {
|
|
787
|
+
// Create new rule and add to bot
|
|
788
|
+
const newRule = new EasyRule(trigger, this.bot);
|
|
789
|
+
this.bot.rules.push(newRule);
|
|
790
|
+
return newRule;
|
|
791
|
+
}
|
|
792
|
+
|
|
793
|
+
// End action chaining, return bot for new rules
|
|
491
794
|
done() {
|
|
492
795
|
return this.bot;
|
|
493
796
|
}
|
|
494
797
|
|
|
798
|
+
// Alias for done() - return bot for new rules
|
|
799
|
+
then() {
|
|
800
|
+
return this.bot;
|
|
801
|
+
}
|
|
802
|
+
|
|
495
803
|
// Matching
|
|
496
804
|
matches(msg) {
|
|
497
805
|
const text = msg.text?.toLowerCase() || '';
|
|
@@ -540,81 +848,227 @@ class EasyRule {
|
|
|
540
848
|
await this.bot.sendMedia(msg, 'image', action.value);
|
|
541
849
|
break;
|
|
542
850
|
|
|
851
|
+
case 'video':
|
|
852
|
+
await this.bot.sendMedia(msg, 'video', action.value);
|
|
853
|
+
break;
|
|
854
|
+
|
|
855
|
+
case 'audio':
|
|
856
|
+
await this.bot.sendMedia(msg, 'audio', action.value);
|
|
857
|
+
break;
|
|
858
|
+
|
|
543
859
|
case 'sticker':
|
|
544
860
|
await this.bot.sendMedia(msg, 'sticker', action.value);
|
|
545
861
|
break;
|
|
546
862
|
|
|
863
|
+
case 'document':
|
|
864
|
+
await this.bot.sendMedia(msg, 'document', action.value);
|
|
865
|
+
break;
|
|
866
|
+
|
|
547
867
|
case 'location':
|
|
548
868
|
await this.bot.sendMedia(msg, 'location', action.value);
|
|
549
869
|
break;
|
|
550
870
|
|
|
551
|
-
case '
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
871
|
+
case 'contact':
|
|
872
|
+
await this.bot.sendMedia(msg, 'contact', action.value);
|
|
873
|
+
break;
|
|
874
|
+
|
|
875
|
+
case 'poll':
|
|
876
|
+
await this.bot.sendMedia(msg, 'poll', action.value);
|
|
877
|
+
break;
|
|
878
|
+
|
|
879
|
+
case 'createSticker':
|
|
880
|
+
try {
|
|
881
|
+
if (msg.create && msg.create.sticker) {
|
|
882
|
+
await msg.create.sticker.fromText('EasyBot Sticker', action.value);
|
|
883
|
+
} else {
|
|
884
|
+
await this.bot.sendReply(msg, '🎨 Sticker-Feature nicht verfügbar');
|
|
885
|
+
}
|
|
886
|
+
} catch (error) {
|
|
887
|
+
console.error('❌ Fehler bei Sticker-Erstellung:', error.message);
|
|
559
888
|
}
|
|
560
889
|
break;
|
|
561
890
|
|
|
562
|
-
case '
|
|
563
|
-
|
|
564
|
-
if (
|
|
565
|
-
|
|
566
|
-
const metadata = await client.get.GroupMetadata(msg.from);
|
|
567
|
-
const allMembers = metadata.participants.map(p => p.id);
|
|
568
|
-
const mentionText = action.value + ' ' + allMembers.map(id => `@${id.split('@')[0]}`).join(' ');
|
|
569
|
-
|
|
570
|
-
await this.bot.multiClient.sendMessage(msg.from, {
|
|
571
|
-
text: mentionText,
|
|
572
|
-
mentions: allMembers
|
|
573
|
-
});
|
|
891
|
+
case 'hidetag':
|
|
892
|
+
try {
|
|
893
|
+
if (msg.isGroup) {
|
|
894
|
+
await this.bot.sendReply(msg, '👥 Hidetag-Nachricht', [], { hidetag: action.value });
|
|
574
895
|
} else {
|
|
575
|
-
await
|
|
896
|
+
await this.bot.sendReply(msg, 'Hidetag funktioniert nur in Gruppen');
|
|
576
897
|
}
|
|
577
|
-
}
|
|
578
|
-
|
|
898
|
+
} catch (error) {
|
|
899
|
+
console.error('❌ Fehler bei Hidetag:', error.message);
|
|
579
900
|
}
|
|
580
901
|
break;
|
|
581
902
|
|
|
582
|
-
case '
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
903
|
+
case 'record':
|
|
904
|
+
try {
|
|
905
|
+
if (msg.visualRecord) {
|
|
906
|
+
await msg.visualRecord(true);
|
|
907
|
+
await new Promise(resolve => setTimeout(resolve, action.value));
|
|
908
|
+
await msg.visualRecord(false);
|
|
909
|
+
}
|
|
910
|
+
} catch (error) {
|
|
911
|
+
console.error('❌ Fehler bei Recording:', error.message);
|
|
590
912
|
}
|
|
591
913
|
break;
|
|
592
914
|
|
|
593
|
-
case '
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
915
|
+
case 'wait':
|
|
916
|
+
await new Promise(resolve => setTimeout(resolve, action.value));
|
|
917
|
+
break;
|
|
918
|
+
|
|
919
|
+
case 'aiReply':
|
|
920
|
+
try {
|
|
921
|
+
if (this.bot.client && this.bot.client.ai) {
|
|
922
|
+
const response = await this.bot.client.ai.chat(action.value.prompt, action.value.options);
|
|
923
|
+
await this.bot.sendReply(msg, `🤖 ${response}`);
|
|
924
|
+
} else {
|
|
925
|
+
await this.bot.sendReply(msg, '🤖 AI nicht verfügbar');
|
|
926
|
+
}
|
|
927
|
+
} catch (error) {
|
|
928
|
+
console.error('❌ Fehler bei AI:', error.message);
|
|
929
|
+
await this.bot.sendReply(msg, '❌ AI-Fehler');
|
|
601
930
|
}
|
|
602
931
|
break;
|
|
603
932
|
|
|
604
|
-
case '
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
933
|
+
case 'translate':
|
|
934
|
+
try {
|
|
935
|
+
if (this.bot.client && this.bot.client.ai) {
|
|
936
|
+
const translation = await this.bot.client.ai.translate(action.value.text, action.value.targetLang);
|
|
937
|
+
await this.bot.sendReply(msg, `🌍 ${translation}`);
|
|
938
|
+
} else {
|
|
939
|
+
await this.bot.sendReply(msg, '🌍 Übersetzung nicht verfügbar');
|
|
940
|
+
}
|
|
941
|
+
} catch (error) {
|
|
942
|
+
console.error('❌ Fehler bei Übersetzung:', error.message);
|
|
943
|
+
}
|
|
944
|
+
break;
|
|
945
|
+
|
|
946
|
+
case 'weather':
|
|
947
|
+
try {
|
|
948
|
+
if (this.bot.client && this.bot.client.http) {
|
|
949
|
+
const weather = await this.bot.client.http.getWeather(action.value);
|
|
950
|
+
await this.bot.sendReply(msg, `🌤️ **${weather.city}**: ${weather.temperature}°C, ${weather.description}`);
|
|
951
|
+
} else {
|
|
952
|
+
await this.bot.sendReply(msg, '🌤️ Wetter-Service nicht verfügbar');
|
|
953
|
+
}
|
|
954
|
+
} catch (error) {
|
|
955
|
+
console.error('❌ Fehler bei Wetter:', error.message);
|
|
956
|
+
}
|
|
957
|
+
break;
|
|
958
|
+
|
|
959
|
+
case 'news':
|
|
960
|
+
try {
|
|
961
|
+
if (this.bot.client && this.bot.client.http) {
|
|
962
|
+
const articles = await this.bot.client.http.getNews(action.value);
|
|
963
|
+
if (articles && articles.length > 0) {
|
|
964
|
+
const article = articles[0];
|
|
965
|
+
await this.bot.sendReply(msg, `📰 **${article.title}**\n\n${article.description}\n\n🔗 ${article.url}`);
|
|
612
966
|
} else {
|
|
613
|
-
await
|
|
967
|
+
await this.bot.sendReply(msg, '📰 Keine News gefunden');
|
|
614
968
|
}
|
|
615
|
-
}
|
|
616
|
-
|
|
969
|
+
} else {
|
|
970
|
+
await this.bot.sendReply(msg, '📰 News-Service nicht verfügbar');
|
|
971
|
+
}
|
|
972
|
+
} catch (error) {
|
|
973
|
+
console.error('❌ Fehler bei News:', error.message);
|
|
974
|
+
}
|
|
975
|
+
break;
|
|
976
|
+
|
|
977
|
+
case 'crypto':
|
|
978
|
+
try {
|
|
979
|
+
if (this.bot.client && this.bot.client.http) {
|
|
980
|
+
const price = await this.bot.client.http.getCryptoPrice(action.value);
|
|
981
|
+
await this.bot.sendReply(msg, `💰 **${price.symbol.toUpperCase()}**: €${price.priceEUR} (${price.change24h})`);
|
|
982
|
+
} else {
|
|
983
|
+
await this.bot.sendReply(msg, '💰 Crypto-Service nicht verfügbar');
|
|
984
|
+
}
|
|
985
|
+
} catch (error) {
|
|
986
|
+
console.error('❌ Fehler bei Crypto:', error.message);
|
|
987
|
+
}
|
|
988
|
+
break;
|
|
989
|
+
|
|
990
|
+
case 'saveData':
|
|
991
|
+
try {
|
|
992
|
+
if (msg.write) {
|
|
993
|
+
msg.write.in(action.value.file).set(action.value.key, action.value.value);
|
|
994
|
+
await this.bot.sendReply(msg, '💾 Daten gespeichert');
|
|
617
995
|
}
|
|
996
|
+
} catch (error) {
|
|
997
|
+
console.error('❌ Fehler beim Speichern:', error.message);
|
|
998
|
+
}
|
|
999
|
+
break;
|
|
1000
|
+
|
|
1001
|
+
case 'loadData':
|
|
1002
|
+
try {
|
|
1003
|
+
if (msg.read) {
|
|
1004
|
+
const data = msg.read.from(action.value.file).get(action.value.key);
|
|
1005
|
+
await this.bot.sendReply(msg, `📖 Daten: ${JSON.stringify(data)}`);
|
|
1006
|
+
}
|
|
1007
|
+
} catch (error) {
|
|
1008
|
+
console.error('❌ Fehler beim Laden:', error.message);
|
|
1009
|
+
}
|
|
1010
|
+
break;
|
|
1011
|
+
|
|
1012
|
+
case 'increment':
|
|
1013
|
+
try {
|
|
1014
|
+
if (msg.write) {
|
|
1015
|
+
msg.write.in(action.value.file).increment(action.value.key, action.value.amount);
|
|
1016
|
+
const newValue = msg.read.from(action.value.file).get(action.value.key);
|
|
1017
|
+
await this.bot.sendReply(msg, `📊 Counter: ${newValue}`);
|
|
1018
|
+
}
|
|
1019
|
+
} catch (error) {
|
|
1020
|
+
console.error('❌ Fehler beim Incrementieren:', error.message);
|
|
1021
|
+
}
|
|
1022
|
+
break;
|
|
1023
|
+
|
|
1024
|
+
case 'schedule':
|
|
1025
|
+
try {
|
|
1026
|
+
if (this.bot.client && this.bot.client.scheduler) {
|
|
1027
|
+
const scheduleTime = new Date(Date.now() + (action.value.time * 60 * 1000));
|
|
1028
|
+
this.bot.client.scheduler.scheduleOnce(scheduleTime, msg.from, action.value.message);
|
|
1029
|
+
await this.bot.sendReply(msg, `⏰ Nachricht geplant für ${scheduleTime.toLocaleString('de-DE')}`);
|
|
1030
|
+
}
|
|
1031
|
+
} catch (error) {
|
|
1032
|
+
console.error('❌ Fehler beim Planen:', error.message);
|
|
1033
|
+
}
|
|
1034
|
+
break;
|
|
1035
|
+
|
|
1036
|
+
case 'remind':
|
|
1037
|
+
try {
|
|
1038
|
+
if (this.bot.client && this.bot.client.scheduler) {
|
|
1039
|
+
const reminderTime = new Date(Date.now() + (action.value.minutes * 60 * 1000));
|
|
1040
|
+
this.bot.client.scheduler.scheduleOnce(reminderTime, msg.from, `⏰ Erinnerung: ${action.value.message}`);
|
|
1041
|
+
await this.bot.sendReply(msg, `⏰ Erinnerung in ${action.value.minutes} Minuten gesetzt`);
|
|
1042
|
+
}
|
|
1043
|
+
} catch (error) {
|
|
1044
|
+
console.error('❌ Fehler bei Erinnerung:', error.message);
|
|
1045
|
+
}
|
|
1046
|
+
break;
|
|
1047
|
+
|
|
1048
|
+
case 'mentionSender':
|
|
1049
|
+
// Implementierung für mentionSender
|
|
1050
|
+
await this.bot.sendReply(msg, action.value);
|
|
1051
|
+
break;
|
|
1052
|
+
|
|
1053
|
+
case 'mentionAll':
|
|
1054
|
+
// Implementierung für mentionAll
|
|
1055
|
+
await this.bot.sendReply(msg, action.value);
|
|
1056
|
+
break;
|
|
1057
|
+
|
|
1058
|
+
case 'mentionUser':
|
|
1059
|
+
// Implementierung für mentionUser
|
|
1060
|
+
await this.bot.sendReply(msg, action.value.text);
|
|
1061
|
+
break;
|
|
1062
|
+
|
|
1063
|
+
case 'delete':
|
|
1064
|
+
// Implementierung für delete
|
|
1065
|
+
console.log('Delete action ausgeführt');
|
|
1066
|
+
break;
|
|
1067
|
+
|
|
1068
|
+
case 'deleteAfter':
|
|
1069
|
+
// Implementierung für deleteAfter
|
|
1070
|
+
setTimeout(() => {
|
|
1071
|
+
console.log('Delayed delete action ausgeführt');
|
|
618
1072
|
}, action.value * 1000);
|
|
619
1073
|
break;
|
|
620
1074
|
}
|