levix-bot 4.3.0 → 4.4.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.
Files changed (75) hide show
  1. package/README.md +1 -0
  2. package/package.json +1 -1
  3. package/public/dashboard/assets/index-5P8GnKLg.css +2 -0
  4. package/public/dashboard/assets/index-DXzno3X6.js +515 -0
  5. package/public/dashboard/index.html +2 -2
  6. package/public/dashboard.css +32 -0
  7. package/src/bootstrap/panel.js +16 -4
  8. package/src/commands/autoschedule.cjs +1 -1
  9. package/src/commands/blacklist.cjs +1 -1
  10. package/src/commands/calc.cjs +9 -9
  11. package/src/commands/gemini.cjs +26 -26
  12. package/src/commands/group/add.cjs +2 -2
  13. package/src/commands/group/demote.cjs +2 -2
  14. package/src/commands/group/members.cjs +2 -2
  15. package/src/commands/group/rules.cjs +1 -1
  16. package/src/commands/group/setname.cjs +3 -3
  17. package/src/commands/group/setpp.cjs +3 -3
  18. package/src/commands/group/setrules.cjs +1 -1
  19. package/src/commands/group/tagadmins.cjs +1 -1
  20. package/src/commands/group.cjs +1 -1
  21. package/src/commands/lang.cjs +3 -3
  22. package/src/commands/listschedules.cjs +1 -1
  23. package/src/commands/loop.cjs +3 -3
  24. package/src/commands/memory.cjs +18 -18
  25. package/src/commands/notes.cjs +1 -1
  26. package/src/commands/pack.cjs +159 -0
  27. package/src/commands/packs.cjs +47 -0
  28. package/src/commands/perm.cjs +2 -2
  29. package/src/commands/poll.cjs +3 -3
  30. package/src/commands/rand.cjs +2 -2
  31. package/src/commands/restart.cjs +4 -4
  32. package/src/commands/schedule.cjs +1 -1
  33. package/src/commands/send.cjs +3 -20
  34. package/src/commands/status.cjs +2 -2
  35. package/src/commands/sticker.cjs +77 -232
  36. package/src/commands/stickers.cjs +100 -0
  37. package/src/commands/stopbot.cjs +5 -5
  38. package/src/commands/stt.cjs +1 -1
  39. package/src/commands/toimage.cjs +88 -0
  40. package/src/commands/tts.cjs +2 -2
  41. package/src/config/defaults.cjs +5 -0
  42. package/src/config/settings.cjs +10 -0
  43. package/src/core/events.js +15 -1
  44. package/src/core/session.js +7 -0
  45. package/src/db/db.cjs +381 -0
  46. package/src/db/store.cjs +729 -21
  47. package/src/handlers/command.handler.js +5 -1
  48. package/src/panel/password-reset.cjs +1 -1
  49. package/src/routes/dashboard.api.esm.js +43 -10
  50. package/src/routes/stickers.api.esm.js +570 -0
  51. package/src/services/aiAgent.cjs +2 -2
  52. package/src/services/aiProviders.cjs +1 -1
  53. package/src/services/aiTools.cjs +27 -27
  54. package/src/stickers/errors.cjs +239 -0
  55. package/src/stickers/ffmpeg.cjs +133 -0
  56. package/src/stickers/jobs.cjs +183 -0
  57. package/src/stickers/library.cjs +712 -0
  58. package/src/stickers/limits.cjs +60 -0
  59. package/src/stickers/media.cjs +748 -0
  60. package/src/stickers/options.cjs +128 -0
  61. package/src/stickers/owner.cjs +103 -0
  62. package/src/stickers/studio.cjs +473 -0
  63. package/src/stickers/uploads.cjs +263 -0
  64. package/src/stickers/webp.cjs +231 -0
  65. package/src/stickers/zip.cjs +107 -0
  66. package/src/utils/memory.cjs +7 -7
  67. package/src/utils/messageContent.cjs +30 -4
  68. package/src/utils/recurrence.cjs +189 -30
  69. package/src/utils/stickerBot.cjs +84 -0
  70. package/src/utils/storage.cjs +3 -0
  71. package/src/utils/storage.esm.js +3 -0
  72. package/views/login.ejs +39 -3
  73. package/views/setup.ejs +21 -0
  74. package/public/dashboard/assets/index-BCXZoPGP.js +0 -446
  75. package/public/dashboard/assets/index-LvfJ8ybs.css +0 -2
@@ -0,0 +1,183 @@
1
+ // Bounded conversions protect the WhatsApp socket from too many FFmpeg jobs.
2
+ // A timed-out worker keeps its slot briefly while abort cleanup finishes.
3
+ const { randomUUID } = require("node:crypto");
4
+ const { StickerError } = require("./errors.cjs");
5
+ const {
6
+ JOB_CONCURRENCY,
7
+ JOB_MAX_QUEUED,
8
+ JOB_TIMEOUT_MS,
9
+ JOB_RETENTION_MS,
10
+ } = require("./limits.cjs");
11
+
12
+ function createQueue({
13
+ concurrency = JOB_CONCURRENCY,
14
+ maxQueued = JOB_MAX_QUEUED,
15
+ timeoutMs = JOB_TIMEOUT_MS,
16
+ retentionMs = JOB_RETENTION_MS,
17
+ timeoutGraceMs = 5000,
18
+ } = {}) {
19
+ const records = new Map();
20
+ const waiting = [];
21
+ const running = new Set();
22
+ let active = 0;
23
+
24
+ function failRecord(record, error) {
25
+ record.state = "failed";
26
+ record.result = null;
27
+ record.error =
28
+ error instanceof StickerError
29
+ ? { code: error.code, details: error.details }
30
+ : { code: "CONVERSION_FAILED" };
31
+ }
32
+
33
+ function retainBriefly(record) {
34
+ const retention = setTimeout(() => records.delete(record.id), retentionMs);
35
+ retention.unref?.();
36
+ }
37
+
38
+ function drain() {
39
+ while (active < concurrency && waiting.length) {
40
+ const entry = waiting.shift();
41
+ const { record, resolve, reject } = entry;
42
+ active++;
43
+ record.state = "running";
44
+ const controller = new AbortController();
45
+ entry.controller = controller;
46
+ running.add(entry);
47
+ let timeout;
48
+ let timedOut = false;
49
+ const cancelled = new Promise((_, fail) => {
50
+ entry.cancel = (code) => {
51
+ controller.abort();
52
+ fail(new StickerError(code));
53
+ };
54
+ });
55
+ const timeoutPromise = new Promise((_, fail) => {
56
+ timeout = setTimeout(() => {
57
+ timedOut = true;
58
+ controller.abort();
59
+ fail(new StickerError("TIMEOUT"));
60
+ }, timeoutMs);
61
+ });
62
+ const work = Promise.resolve().then(() => {
63
+ const run = entry.run;
64
+ entry.run = null;
65
+ if (controller.signal.aborted) throw new StickerError("CANCELLED");
66
+ return run({
67
+ signal: controller.signal,
68
+ progress(stage, fraction) {
69
+ if (record.state !== "running") return;
70
+ record.stage = stage;
71
+ record.progress = Math.max(0, Math.min(1, Number(fraction) || 0));
72
+ },
73
+ });
74
+ });
75
+ Promise.race([work, timeoutPromise, cancelled])
76
+ .then(
77
+ (result) => {
78
+ if (entry.cancelledCode) {
79
+ const error = new StickerError(entry.cancelledCode);
80
+ failRecord(record, error);
81
+ reject(error);
82
+ return;
83
+ }
84
+ record.state = "done";
85
+ record.result =
86
+ record.kind === "create" && result?.sticker
87
+ ? {
88
+ sticker: result.sticker,
89
+ created: result.created,
90
+ qualityReduced: !!result.qualityReduced,
91
+ }
92
+ : null;
93
+ record.progress = 1;
94
+ resolve(result);
95
+ },
96
+ (error) => {
97
+ const failure = entry.cancelledCode ? new StickerError(entry.cancelledCode) : error;
98
+ failRecord(record, failure);
99
+ reject(failure);
100
+ },
101
+ )
102
+ .finally(() => {
103
+ clearTimeout(timeout);
104
+ entry.run = null;
105
+ entry.cancel = null;
106
+ running.delete(entry);
107
+ retainBriefly(record);
108
+ let released = false;
109
+ const releaseSlot = () => {
110
+ if (released) return;
111
+ released = true;
112
+ active--;
113
+ drain();
114
+ };
115
+ if (timedOut || controller.signal.aborted) {
116
+ // Abort is cooperative; wait for cleanup but never hold the slot forever.
117
+ const grace = setTimeout(releaseSlot, timeoutGraceMs);
118
+ work.then(
119
+ () => {
120
+ clearTimeout(grace);
121
+ releaseSlot();
122
+ },
123
+ () => {
124
+ clearTimeout(grace);
125
+ releaseSlot();
126
+ },
127
+ );
128
+ } else {
129
+ releaseSlot();
130
+ }
131
+ });
132
+ }
133
+ }
134
+
135
+ function submit(run, { kind } = {}) {
136
+ if (typeof run !== "function") throw new TypeError("run must be a function");
137
+ if (active >= concurrency && waiting.length >= maxQueued) throw new StickerError("BUSY");
138
+ const id = randomUUID();
139
+ const record = {
140
+ id,
141
+ kind,
142
+ state: "queued",
143
+ stage: null,
144
+ progress: 0,
145
+ error: null,
146
+ result: null,
147
+ };
148
+ records.set(id, record);
149
+ const promise = new Promise((resolve, reject) => {
150
+ waiting.push({ record, run, resolve, reject });
151
+ drain();
152
+ });
153
+ return { id, promise };
154
+ }
155
+
156
+ function cancelAll(code = "CANCELLED") {
157
+ for (const entry of waiting.splice(0)) {
158
+ const { record, reject } = entry;
159
+ entry.run = null;
160
+ const error = new StickerError(code);
161
+ failRecord(record, error);
162
+ retainBriefly(record);
163
+ reject(error);
164
+ }
165
+ for (const entry of running) {
166
+ entry.cancelledCode = code;
167
+ failRecord(entry.record, new StickerError(code));
168
+ entry.cancel?.(code);
169
+ }
170
+ }
171
+
172
+ return {
173
+ submit,
174
+ cancelAll,
175
+ get(id) {
176
+ const record = records.get(id);
177
+ return record ? { ...record } : null;
178
+ },
179
+ };
180
+ }
181
+
182
+ const queue = createQueue();
183
+ module.exports = { createQueue, submit: queue.submit, cancelAll: queue.cancelAll, get: queue.get };