waengine 2.3.2 β†’ 2.3.5

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "waengine",
3
- "version": "2.3.2",
3
+ "version": "2.3.5",
4
4
  "description": "πŸš€ WAEngine - The most powerful WhatsApp Bot Library with 860+ Working Features, Complete Baileys Integration & Production-Ready Stability",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -285,7 +285,8 @@ let sessionMenuShown = false;
285
285
 
286
286
  export async function showSessionMenuIfNeeded() {
287
287
  // PrΓΌfe ob wir vom Session Menu selbst aufgerufen werden
288
- if (global.__WAENGINE_SKIP_SESSION_MENU__) {
288
+ // WICHTIG: PrΓΌfe sowohl global als auch Environment-Variable!
289
+ if (global.__WAENGINE_SKIP_SESSION_MENU__ || process.env.__WAENGINE_SKIP_SESSION_MENU__ === 'true') {
289
290
  return null;
290
291
  }
291
292
 
@@ -18,13 +18,16 @@ const c = {
18
18
  };
19
19
 
20
20
  export class SessionMenu {
21
- constructor(baseAuthDir = './auth') { // GeΓ€ndert von './sessions' zu './auth'
21
+ constructor(baseAuthDir = './auth') {
22
22
  this.baseAuthDir = baseAuthDir;
23
- this.sessionsConfigPath = path.join(baseAuthDir, '..', 'sessions.json'); // Eine Ebene hΓΆher
24
- this.sessionStatusPath = path.join(baseAuthDir, '..', 'session-status.json'); // Status-Tracking
23
+ this.sessionsConfigPath = path.join(baseAuthDir, '..', 'sessions.json');
24
+ this.sessionStatusPath = path.join(baseAuthDir, '..', 'session-status.json');
25
25
  this.activeSessions = new Map();
26
26
  this.rl = null;
27
27
 
28
+ // Erkenne das Start-Script aus process.argv
29
+ this.userStartCommand = this.detectStartCommand();
30
+
28
31
  if (!fs.existsSync(baseAuthDir)) {
29
32
  fs.mkdirSync(baseAuthDir, { recursive: true });
30
33
  }
@@ -32,6 +35,22 @@ export class SessionMenu {
32
35
  this.loadSessionsConfig();
33
36
  this.loadSessionStatus();
34
37
  }
38
+
39
+ // Erkenne wie der User seinen Bot gestartet hat
40
+ detectStartCommand() {
41
+ // process.argv[0] = node
42
+ // process.argv[1] = script.js
43
+ const scriptPath = process.argv[1];
44
+
45
+ if (scriptPath) {
46
+ const scriptName = path.basename(scriptPath);
47
+ console.log(c.green(`βœ… Start-Command erkannt: node ${scriptName}`));
48
+ return scriptName;
49
+ }
50
+
51
+ // Fallback
52
+ return 'index.js';
53
+ }
35
54
 
36
55
  loadSessionsConfig() {
37
56
  if (fs.existsSync(this.sessionsConfigPath)) {
@@ -101,20 +120,17 @@ export class SessionMenu {
101
120
 
102
121
  console.log(c.cyan(`\nπŸš€ Γ–ffne neues Terminal fΓΌr Session: ${sessionName}...`));
103
122
 
104
- // Erstelle ein temporΓ€res Start-Script fΓΌr diese Session
105
- const scriptPath = path.join(process.cwd(), `.session-${sessionName}.js`);
123
+ // Setze Status auf "connecting"
124
+ this.updateSessionStatus(sessionName, 'connecting');
125
+
126
+ // Erstelle Wrapper-Script fΓΌr Status-Tracking
127
+ const wrapperPath = path.join(process.cwd(), `.session-${sessionName}-wrapper.js`);
106
128
  const statusPath = path.join(process.cwd(), 'session-status.json');
107
129
 
108
- const scriptContent = `
109
- // Auto-generiertes Session-Start-Script fΓΌr: ${sessionName}
110
- import { WhatsAppClient } from 'waengine';
130
+ const wrapperContent = `// Session Wrapper fΓΌr: ${sessionName}
111
131
  import fs from 'fs';
132
+ import { spawn } from 'child_process';
112
133
 
113
- console.log('╔════════════════════════════════════════╗');
114
- console.log('β•‘ WAEngine Session: ${sessionName.padEnd(20)}β•‘');
115
- console.log('β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•\\n');
116
-
117
- // Status-Update Funktion
118
134
  function updateStatus(status) {
119
135
  try {
120
136
  let statusData = {};
@@ -131,73 +147,56 @@ function updateStatus(status) {
131
147
 
132
148
  fs.writeFileSync('${statusPath.replace(/\\/g, '/')}', JSON.stringify(statusData, null, 2));
133
149
  } catch (error) {
134
- console.error('Status-Update Fehler:', error.message);
150
+ console.error('❌ Status-Update Fehler:', error.message);
135
151
  }
136
152
  }
137
153
 
138
- // Status: Verbindet
139
- updateStatus('connecting');
154
+ console.log('╔════════════════════════════════════════╗');
155
+ console.log('β•‘ WAEngine Session: ${sessionName.padEnd(20)}β•‘');
156
+ console.log('β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•\\n');
140
157
 
141
- // Deaktiviere Session Menu fΓΌr diese Session
142
- global.__WAENGINE_SKIP_SESSION_MENU__ = true;
158
+ updateStatus('connecting');
143
159
 
144
- const client = new WhatsAppClient({
145
- authDir: '${session.authDir.replace(/\\/g, '/')}',
146
- printQR: false,
147
- silent: false
160
+ // Starte User's Bot-Script mit Environment-Variablen
161
+ const botProcess = spawn('node', ['${this.userStartCommand}'], {
162
+ env: {
163
+ ...process.env,
164
+ WAENGINE_AUTH_DIR: '${session.authDir.replace(/\\/g, '/')}',
165
+ WAENGINE_SESSION_NAME: '${sessionName}',
166
+ __WAENGINE_SKIP_SESSION_MENU__: 'true'
167
+ },
168
+ stdio: 'inherit'
148
169
  });
149
170
 
150
- console.log('πŸ”„ Starte Session ${sessionName}...\\n');
151
-
152
- try {
153
- await client.connect();
154
-
155
- // Status: Online
171
+ // Warte kurz und setze Status auf online
172
+ setTimeout(() => {
156
173
  updateStatus('online');
157
174
 
158
- console.log('\\nβœ… Session ${sessionName} lΓ€uft!');
159
- console.log('πŸ’¬ Bot wartet auf Nachrichten...\\n');
160
-
161
- // Heartbeat: Status alle 10 Sekunden aktualisieren
175
+ // Heartbeat alle 10 Sekunden
162
176
  setInterval(() => {
163
177
  updateStatus('online');
164
178
  }, 10000);
165
-
166
- // Beispiel: Message Handler
167
- client.on('message', async (msg) => {
168
- console.log(\`πŸ“¨ Nachricht von \${msg.from}: \${msg.body}\`);
169
-
170
- // Hier kann der User seinen Bot-Code einfΓΌgen
171
- if (msg.body === '!ping') {
172
- await msg.reply('πŸ“ Pong!');
173
- }
174
- });
175
-
176
- } catch (error) {
177
- console.error('❌ Fehler beim Starten:', error.message);
179
+ }, 3000);
180
+
181
+ botProcess.on('exit', (code) => {
182
+ console.log(\`\\nπŸ‘‹ Bot beendet (Code: \${code})\`);
178
183
  updateStatus('offline');
179
- }
184
+ process.exit(code);
185
+ });
180
186
 
181
- // Verhindere dass das Script beendet wird
182
187
  process.on('SIGINT', () => {
183
188
  console.log('\\nπŸ‘‹ Session ${sessionName} wird beendet...');
184
189
  updateStatus('offline');
190
+ botProcess.kill();
185
191
  process.exit(0);
186
192
  });
187
-
188
- process.on('exit', () => {
189
- updateStatus('offline');
190
- });
191
193
  `;
192
194
 
193
- // Schreibe das Script
194
- fs.writeFileSync(scriptPath, scriptContent);
195
-
196
- // Setze Status auf "connecting"
197
- this.updateSessionStatus(sessionName, 'connecting');
195
+ // Schreibe Wrapper-Script
196
+ fs.writeFileSync(wrapperPath, wrapperContent);
198
197
 
199
- // Γ–ffne neues Terminal (Windows CMD)
200
- const command = `start "WAEngine - ${sessionName}" cmd /k "node ${scriptPath}"`;
198
+ // Γ–ffne neues Terminal mit Wrapper-Script
199
+ const command = `start "WAEngine - ${sessionName}" cmd /k "node ${wrapperPath}"`;
201
200
 
202
201
  try {
203
202
  spawn(command, [], {
@@ -207,7 +206,8 @@ process.on('exit', () => {
207
206
  });
208
207
 
209
208
  console.log(c.green(`βœ… Neues Terminal geΓΆffnet fΓΌr: ${sessionName}`));
210
- console.log(c.gray(` Script: ${scriptPath}`));
209
+ console.log(c.gray(` Command: node ${this.userStartCommand}`));
210
+ console.log(c.gray(` Auth: ${session.authDir}`));
211
211
  console.log(c.gray(` Status wird automatisch aktualisiert...`));
212
212
 
213
213
  return true;
@@ -215,8 +215,8 @@ process.on('exit', () => {
215
215
  console.log(c.red(`❌ Fehler beim Γ–ffnen des Terminals: ${error.message}`));
216
216
 
217
217
  // Cleanup
218
- if (fs.existsSync(scriptPath)) {
219
- fs.unlinkSync(scriptPath);
218
+ if (fs.existsSync(wrapperPath)) {
219
+ fs.unlinkSync(wrapperPath);
220
220
  }
221
221
 
222
222
  this.updateSessionStatus(sessionName, 'offline');