waengine 1.0.6 → 1.0.7
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/README.md +37 -5
- package/package.json +4 -1
- package/src/client.js +60 -26
- package/src/index.js +1 -0
- package/src/prefix-manager.js +158 -0
package/README.md
CHANGED
|
@@ -496,20 +496,52 @@ const messageTypes = await msg.stats.getMessagesByType()
|
|
|
496
496
|
|
|
497
497
|
### **Prefix Setup**
|
|
498
498
|
```javascript
|
|
499
|
-
//
|
|
499
|
+
// Global Prefix (Fallback)
|
|
500
500
|
const prefix = "!"
|
|
501
501
|
client.setPrefix(prefix)
|
|
502
502
|
|
|
503
|
-
//
|
|
503
|
+
// Chat-spezifische Prefixes (NEU in v1.0.7!)
|
|
504
|
+
client.setChatPrefix(chatId, "#") // Für spezifischen Chat
|
|
505
|
+
client.getChatPrefix(chatId) // Prefix abrufen
|
|
506
|
+
client.removeChatPrefix(chatId) // Prefix entfernen
|
|
507
|
+
|
|
508
|
+
// Commands registrieren
|
|
504
509
|
client.addCommand('help', async (msg, args) => {
|
|
505
510
|
await msg.reply('Help text')
|
|
506
511
|
})
|
|
512
|
+
```
|
|
507
513
|
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
514
|
+
### **Chat-spezifische Prefixes (v1.0.7)**
|
|
515
|
+
Jeder Chat/Gruppe kann einen eigenen Prefix haben:
|
|
516
|
+
|
|
517
|
+
```javascript
|
|
518
|
+
// Setprefix Command (Admin only)
|
|
519
|
+
client.addCommand('setprefix', async (msg, args) => {
|
|
520
|
+
if (msg.isGroup && !(await msg.isAdmin())) {
|
|
521
|
+
return msg.reply('❌ Nur Admins können den Prefix ändern!');
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
const newPrefix = args[0];
|
|
525
|
+
client.setChatPrefix(msg.from, newPrefix);
|
|
526
|
+
await msg.reply(`✅ Prefix geändert zu: "${newPrefix}"`);
|
|
527
|
+
});
|
|
528
|
+
|
|
529
|
+
// Prefix Info Command
|
|
530
|
+
client.addCommand('prefixinfo', async (msg) => {
|
|
531
|
+
const chatPrefix = client.getChatPrefix(msg.from);
|
|
532
|
+
const stats = client.getPrefixStats();
|
|
533
|
+
|
|
534
|
+
await msg.reply(`🎯 Aktueller Prefix: "${chatPrefix}"\n📊 Gesamt Chats: ${stats.totalChats}`);
|
|
535
|
+
});
|
|
511
536
|
```
|
|
512
537
|
|
|
538
|
+
**Features:**
|
|
539
|
+
- ✅ **Persistent Storage** - Prefixes werden automatisch gespeichert
|
|
540
|
+
- ✅ **Admin-only** - Nur Admins können Prefixes in Gruppen ändern
|
|
541
|
+
- ✅ **Validierung** - Max 5 Zeichen, keine Leerzeichen
|
|
542
|
+
- ✅ **Statistics** - Übersicht über alle verwendeten Prefixes
|
|
543
|
+
- ✅ **Fallback** - Global Prefix als Standard
|
|
544
|
+
|
|
513
545
|
### **Command Properties**
|
|
514
546
|
```javascript
|
|
515
547
|
// In message events
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "waengine",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.7",
|
|
4
4
|
"description": "🚀 WAEngine - The most powerful WhatsApp Bot Library with Multi-Device Support & EasyBot API",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -24,6 +24,9 @@
|
|
|
24
24
|
"messaging",
|
|
25
25
|
"multi-account",
|
|
26
26
|
"load-balancing",
|
|
27
|
+
"prefix-system",
|
|
28
|
+
"chat-specific",
|
|
29
|
+
"group-management",
|
|
27
30
|
"typescript",
|
|
28
31
|
"javascript",
|
|
29
32
|
"nodejs"
|
package/src/client.js
CHANGED
|
@@ -3,6 +3,7 @@ import pino from "pino";
|
|
|
3
3
|
import { generateQRCode, closeBrowser } from "./qr.js";
|
|
4
4
|
import { Message } from "./message.js";
|
|
5
5
|
import { SessionManager } from "./session-manager.js";
|
|
6
|
+
import { PrefixManager } from "./prefix-manager.js";
|
|
6
7
|
|
|
7
8
|
export class WhatsAppClient {
|
|
8
9
|
constructor(options = {}) {
|
|
@@ -24,8 +25,9 @@ export class WhatsAppClient {
|
|
|
24
25
|
// Session Manager
|
|
25
26
|
this.sessionManager = new SessionManager(this.options.authDir);
|
|
26
27
|
|
|
27
|
-
// Prefix System
|
|
28
|
-
this.prefix = null;
|
|
28
|
+
// Prefix System (erweitert für gruppen-spezifische Prefixes)
|
|
29
|
+
this.prefix = null; // Global fallback
|
|
30
|
+
this.prefixManager = new PrefixManager('./data');
|
|
29
31
|
this.commands = new Map();
|
|
30
32
|
|
|
31
33
|
// Deine eigenen API-Objekte
|
|
@@ -308,28 +310,32 @@ export class WhatsAppClient {
|
|
|
308
310
|
|
|
309
311
|
const messageObj = new Message(this, messageData);
|
|
310
312
|
|
|
311
|
-
// Prefix System - Command Check
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
console.log(`⚡ Command: ${this.prefix}${command}`);
|
|
317
|
-
|
|
318
|
-
messageObj.isCommand = true;
|
|
319
|
-
messageObj.command = command.toLowerCase();
|
|
320
|
-
messageObj.args = args;
|
|
321
|
-
messageObj.commandText = commandText;
|
|
322
|
-
|
|
323
|
-
// Command Event emittieren
|
|
324
|
-
this.emit('command', messageObj);
|
|
313
|
+
// Prefix System - Command Check (erweitert für Chat-spezifische Prefixes)
|
|
314
|
+
const chatPrefix = this.prefixManager.getPrefix(messageData.from);
|
|
315
|
+
|
|
316
|
+
if (messageData.text && messageData.text.startsWith(chatPrefix)) {
|
|
317
|
+
const commandData = this.prefixManager.parseCommand(messageData.text, messageData.from);
|
|
325
318
|
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
319
|
+
if (commandData) {
|
|
320
|
+
console.log(`⚡ Command in ${messageData.from}: ${commandData.prefix}${commandData.command}`);
|
|
321
|
+
|
|
322
|
+
messageObj.isCommand = true;
|
|
323
|
+
messageObj.command = commandData.command;
|
|
324
|
+
messageObj.args = commandData.args;
|
|
325
|
+
messageObj.commandText = commandData.commandText;
|
|
326
|
+
messageObj.prefix = commandData.prefix;
|
|
327
|
+
|
|
328
|
+
// Command Event emittieren
|
|
329
|
+
this.emit('command', messageObj);
|
|
330
|
+
|
|
331
|
+
// Spezifischen Command Handler aufrufen falls vorhanden
|
|
332
|
+
if (this.commands.has(commandData.command)) {
|
|
333
|
+
const handler = this.commands.get(commandData.command);
|
|
334
|
+
try {
|
|
335
|
+
handler(messageObj, commandData.args);
|
|
336
|
+
} catch (error) {
|
|
337
|
+
console.error(`❌ Fehler in Command '${commandData.command}':`, error);
|
|
338
|
+
}
|
|
333
339
|
}
|
|
334
340
|
}
|
|
335
341
|
} else {
|
|
@@ -424,15 +430,43 @@ export class WhatsAppClient {
|
|
|
424
430
|
};
|
|
425
431
|
}
|
|
426
432
|
|
|
427
|
-
// ===== PREFIX SYSTEM =====
|
|
433
|
+
// ===== PREFIX SYSTEM (ERWEITERT) =====
|
|
428
434
|
|
|
435
|
+
// Global Prefix (Fallback)
|
|
429
436
|
setPrefix(prefix) {
|
|
430
437
|
this.prefix = prefix;
|
|
438
|
+
this.prefixManager.defaultPrefix = prefix;
|
|
439
|
+
console.log(`🌐 Global Prefix gesetzt: "${prefix}"`);
|
|
431
440
|
return this;
|
|
432
441
|
}
|
|
433
442
|
|
|
434
|
-
getPrefix() {
|
|
435
|
-
|
|
443
|
+
getPrefix(chatId = null) {
|
|
444
|
+
if (chatId) {
|
|
445
|
+
return this.prefixManager.getPrefix(chatId);
|
|
446
|
+
}
|
|
447
|
+
return this.prefix || this.prefixManager.defaultPrefix;
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
// Chat-spezifische Prefixes
|
|
451
|
+
setChatPrefix(chatId, prefix) {
|
|
452
|
+
return this.prefixManager.setPrefix(chatId, prefix);
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
getChatPrefix(chatId) {
|
|
456
|
+
return this.prefixManager.getPrefix(chatId);
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
removeChatPrefix(chatId) {
|
|
460
|
+
return this.prefixManager.removePrefix(chatId);
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
// Prefix Statistics
|
|
464
|
+
getPrefixStats() {
|
|
465
|
+
return this.prefixManager.getStats();
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
getAllPrefixes() {
|
|
469
|
+
return this.prefixManager.getAllPrefixes();
|
|
436
470
|
}
|
|
437
471
|
|
|
438
472
|
addCommand(command, handler) {
|
package/src/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export { WhatsAppClient } from "./client.js";
|
|
2
2
|
export { MultiWhatsAppClient } from "./multi-client.js";
|
|
3
3
|
export { DeviceManager } from "./device-manager.js";
|
|
4
|
+
export { PrefixManager } from "./prefix-manager.js";
|
|
4
5
|
export { EasyBot, createBot, createMultiBot, quickBot, bot, multiBot } from "./easy-bot.js";
|
|
5
6
|
export { generateQRCode } from "./qr.js";
|
|
6
7
|
export { Message } from "./message.js";
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
// Prefix Manager für gruppen-spezifische Prefixes
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
|
|
5
|
+
export class PrefixManager {
|
|
6
|
+
constructor(dataDir = './data') {
|
|
7
|
+
this.dataDir = dataDir;
|
|
8
|
+
this.prefixFile = path.join(dataDir, 'prefixes.json');
|
|
9
|
+
this.defaultPrefix = '!';
|
|
10
|
+
this.prefixes = new Map();
|
|
11
|
+
|
|
12
|
+
this.ensureDataDir();
|
|
13
|
+
this.loadPrefixes();
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// ===== SETUP =====
|
|
17
|
+
|
|
18
|
+
ensureDataDir() {
|
|
19
|
+
if (!fs.existsSync(this.dataDir)) {
|
|
20
|
+
fs.mkdirSync(this.dataDir, { recursive: true });
|
|
21
|
+
console.log(`📁 Prefix Data Directory erstellt: ${this.dataDir}`);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// ===== LOAD/SAVE =====
|
|
26
|
+
|
|
27
|
+
loadPrefixes() {
|
|
28
|
+
try {
|
|
29
|
+
if (fs.existsSync(this.prefixFile)) {
|
|
30
|
+
const data = JSON.parse(fs.readFileSync(this.prefixFile, 'utf8'));
|
|
31
|
+
this.prefixes = new Map(Object.entries(data));
|
|
32
|
+
console.log(`📋 ${this.prefixes.size} Prefixes geladen`);
|
|
33
|
+
}
|
|
34
|
+
} catch (error) {
|
|
35
|
+
console.error('❌ Fehler beim Laden der Prefixes:', error);
|
|
36
|
+
this.prefixes = new Map();
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
savePrefixes() {
|
|
41
|
+
try {
|
|
42
|
+
const data = Object.fromEntries(this.prefixes);
|
|
43
|
+
fs.writeFileSync(this.prefixFile, JSON.stringify(data, null, 2));
|
|
44
|
+
console.log(`💾 Prefixes gespeichert (${this.prefixes.size} Einträge)`);
|
|
45
|
+
return true;
|
|
46
|
+
} catch (error) {
|
|
47
|
+
console.error('❌ Fehler beim Speichern der Prefixes:', error);
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// ===== PREFIX MANAGEMENT =====
|
|
53
|
+
|
|
54
|
+
setPrefix(chatId, prefix) {
|
|
55
|
+
if (!chatId) {
|
|
56
|
+
throw new Error('❌ Chat ID ist erforderlich!');
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if (!prefix || prefix.length === 0) {
|
|
60
|
+
throw new Error('❌ Prefix darf nicht leer sein!');
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// Validierung: Prefix sollte nicht zu lang sein
|
|
64
|
+
if (prefix.length > 5) {
|
|
65
|
+
throw new Error('❌ Prefix darf maximal 5 Zeichen lang sein!');
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
this.prefixes.set(chatId, prefix);
|
|
69
|
+
this.savePrefixes();
|
|
70
|
+
|
|
71
|
+
console.log(`🎯 Prefix für ${chatId} gesetzt: "${prefix}"`);
|
|
72
|
+
return true;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
getPrefix(chatId) {
|
|
76
|
+
if (!chatId) return this.defaultPrefix;
|
|
77
|
+
|
|
78
|
+
return this.prefixes.get(chatId) || this.defaultPrefix;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
removePrefix(chatId) {
|
|
82
|
+
if (!chatId) return false;
|
|
83
|
+
|
|
84
|
+
const removed = this.prefixes.delete(chatId);
|
|
85
|
+
if (removed) {
|
|
86
|
+
this.savePrefixes();
|
|
87
|
+
console.log(`🗑️ Prefix für ${chatId} entfernt`);
|
|
88
|
+
}
|
|
89
|
+
return removed;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// ===== UTILITY =====
|
|
93
|
+
|
|
94
|
+
getAllPrefixes() {
|
|
95
|
+
return Object.fromEntries(this.prefixes);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
getPrefixCount() {
|
|
99
|
+
return this.prefixes.size;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// Prüft ob Text mit dem Chat-spezifischen Prefix beginnt
|
|
103
|
+
isCommand(text, chatId) {
|
|
104
|
+
if (!text) return false;
|
|
105
|
+
|
|
106
|
+
const prefix = this.getPrefix(chatId);
|
|
107
|
+
return text.startsWith(prefix);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// Extrahiert Command und Args basierend auf Chat-spezifischem Prefix
|
|
111
|
+
parseCommand(text, chatId) {
|
|
112
|
+
if (!this.isCommand(text, chatId)) {
|
|
113
|
+
return null;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const prefix = this.getPrefix(chatId);
|
|
117
|
+
const commandText = text.slice(prefix.length).trim();
|
|
118
|
+
const [command, ...args] = commandText.split(' ');
|
|
119
|
+
|
|
120
|
+
return {
|
|
121
|
+
prefix,
|
|
122
|
+
command: command.toLowerCase(),
|
|
123
|
+
args,
|
|
124
|
+
commandText,
|
|
125
|
+
fullText: text
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// ===== STATISTICS =====
|
|
130
|
+
|
|
131
|
+
getStats() {
|
|
132
|
+
const prefixCounts = {};
|
|
133
|
+
|
|
134
|
+
for (const prefix of this.prefixes.values()) {
|
|
135
|
+
prefixCounts[prefix] = (prefixCounts[prefix] || 0) + 1;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
return {
|
|
139
|
+
totalChats: this.prefixes.size,
|
|
140
|
+
defaultPrefix: this.defaultPrefix,
|
|
141
|
+
prefixDistribution: prefixCounts,
|
|
142
|
+
mostUsedPrefix: Object.keys(prefixCounts).reduce((a, b) =>
|
|
143
|
+
prefixCounts[a] > prefixCounts[b] ? a : b, this.defaultPrefix)
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// ===== RESET =====
|
|
148
|
+
|
|
149
|
+
resetAllPrefixes() {
|
|
150
|
+
this.prefixes.clear();
|
|
151
|
+
this.savePrefixes();
|
|
152
|
+
console.log('🔄 Alle Prefixes zurückgesetzt');
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
resetToDefault(chatId) {
|
|
156
|
+
return this.removePrefix(chatId);
|
|
157
|
+
}
|
|
158
|
+
}
|