@ryuu-reinzz/haruka-lib 3.5.1 → 3.6.1

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/main/socket.js CHANGED
@@ -262,6 +262,8 @@ export default function addProperty(socket, baileys) {
262
262
  contextInfo = {},
263
263
  bottom_sheet = false,
264
264
  bottom_name = "",
265
+ limited_time_offer_text = "",
266
+ limited_time_offer = false,
265
267
  mentionedJid = []
266
268
  } = content;
267
269
 
@@ -453,17 +455,25 @@ export default function addProperty(socket, baileys) {
453
455
  messageContent.nativeFlowMessage = {
454
456
  buttons: processedButtons,
455
457
  };
458
+ const params = {};
456
459
 
457
460
  if (bottom_sheet) {
458
- messageContent.nativeFlowMessage.messageParamsJson = JSON.stringify({
459
- bottom_sheet: {
460
- in_thread_buttons_limit: 1,
461
- divider_indices: [1, 2],
462
- list_title: bottom_name,
463
- button_title: bottom_name
464
- }
465
- });
461
+ params.bottom_sheet = {
462
+ in_thread_buttons_limit: 1,
463
+ divider_indices: [1, 2],
464
+ list_title: bottom_name,
465
+ button_title: bottom_name
466
+ };
467
+ }
468
+ if (limited_time_offer) {
469
+ params.limited_time_offer = {
470
+ text: limited_time_offer_text || "",
471
+ url: '',
472
+ copy_code: '',
473
+ expiration_time: Date.now() + (1000 * 60 * 60 * 24 * 7)
474
+ };
466
475
  }
476
+ messageContent.nativeFlowMessage.messageParamsJson = JSON.stringify(params);
467
477
 
468
478
  if (contextInfo.externalAdReply && typeof contextInfo.externalAdReply === "object") {
469
479
  messageContent.contextInfo = {
@@ -7,6 +7,7 @@
7
7
  */
8
8
 
9
9
  import Database from "better-sqlite3";
10
+ import fs from "fs";
10
11
  import {
11
12
  Mutex
12
13
  } from "async-mutex";
@@ -101,8 +102,10 @@ class WriteBuffer {
101
102
  }
102
103
 
103
104
  class AuthDatabase {
105
+
104
106
  constructor(dbPath = DEFAULT_DB, options = {}, BufferJSON) {
105
107
  this.dbPath = dbPath;
108
+ this._initWatcher();
106
109
  this.instanceId = `auth-${Date.now()}-${randomUUID()}`;
107
110
  this.disposed = false;
108
111
  this.isInitialized = false;
@@ -116,6 +119,23 @@ class AuthDatabase {
116
119
  this._registerCleanup();
117
120
  this.isInitialized = true;
118
121
  }
122
+ _initWatcher() {
123
+ const dir = path.dirname(this.dbPath);
124
+
125
+ try {
126
+ this.watcher = fs.watch(dir, (eventType, filename) => {
127
+ if (filename === path.basename(this.dbPath) && !fs.existsSync(this.dbPath)) {
128
+ console.log(`[AuthDB] File ${filename} terdeteksi dihapus. Membersihkan instance...`);
129
+ this._cleanup();
130
+ instances.delete(this.dbPath);
131
+ }
132
+ });
133
+
134
+ this.watcher.unref?.();
135
+ } catch (e) {
136
+ // Folder mungkin belum ada
137
+ }
138
+ }
119
139
 
120
140
  _initDatabase() {
121
141
  const db = new Database(this.dbPath);
@@ -357,25 +377,30 @@ class AuthDatabase {
357
377
  this.disposed = true;
358
378
 
359
379
  try {
380
+ if (this.watcher) this.watcher.close();
360
381
  if (this.flushTimer) clearTimeout(this.flushTimer);
361
382
  if (this.vacuumTimer) clearTimeout(this.vacuumTimer);
362
383
 
363
- const {
364
- upserts,
365
- deletes
366
- } = this.writeBuffer.toArrays();
367
- if (upserts.length || deletes.length) {
368
- this.txCommit(upserts, deletes);
384
+ if (fs.existsSync(this.dbPath)) {
385
+ const {
386
+ upserts,
387
+ deletes
388
+ } = this.writeBuffer.toArrays();
389
+ if (upserts.length || deletes.length) {
390
+ this.txCommit(upserts, deletes);
391
+ }
392
+ this.db.pragma("wal_checkpoint(TRUNCATE)");
393
+ this.db.pragma("incremental_vacuum");
394
+ this.db.pragma("optimize");
369
395
  }
370
396
 
371
- this.db.pragma("wal_checkpoint(TRUNCATE)");
372
- this.db.pragma("incremental_vacuum");
373
- this.db.pragma("optimize");
374
-
375
397
  this.db.close();
376
398
  this.cache.clear();
377
- } catch {}
399
+ } catch (e) {
400
+ // Silent fail jika database sudah tidak bisa diakses
401
+ }
378
402
  }
403
+
379
404
  }
380
405
 
381
406
  const instances = new Map();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ryuu-reinzz/haruka-lib",
3
- "version": "3.5.1",
3
+ "version": "3.6.1",
4
4
  "description": "Library extra for bot WhatsApp",
5
5
  "main": "main/index.js",
6
6
  "type": "module",