levix-bot 4.3.1 → 4.5.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/README.md +4 -2
- package/package.json +1 -1
- package/public/dashboard/assets/index-COI8zgqa.css +2 -0
- package/public/dashboard/assets/index-IZMBuNAZ.js +505 -0
- package/public/dashboard/index.html +2 -2
- package/public/dashboard.css +32 -0
- package/scheduler.cjs +66 -7
- package/src/bootstrap/panel.js +16 -4
- package/src/commands/pack.cjs +159 -0
- package/src/commands/packs.cjs +47 -0
- package/src/commands/send.cjs +1 -18
- package/src/commands/sticker.cjs +77 -232
- package/src/commands/stickers.cjs +100 -0
- package/src/commands/toimage.cjs +88 -0
- package/src/config/defaults.cjs +5 -0
- package/src/config/settings.cjs +10 -0
- package/src/core/events.js +15 -1
- package/src/core/session.js +7 -0
- package/src/db/db.cjs +387 -0
- package/src/db/store.cjs +746 -24
- package/src/handlers/command.handler.js +4 -0
- package/src/panel/feedback.cjs +43 -14
- package/src/routes/dashboard.api.esm.js +172 -20
- package/src/routes/stickers.api.esm.js +570 -0
- package/src/services/llmDiscovery.cjs +32 -10
- package/src/stickers/errors.cjs +239 -0
- package/src/stickers/ffmpeg.cjs +133 -0
- package/src/stickers/jobs.cjs +183 -0
- package/src/stickers/library.cjs +712 -0
- package/src/stickers/limits.cjs +60 -0
- package/src/stickers/media.cjs +748 -0
- package/src/stickers/options.cjs +128 -0
- package/src/stickers/owner.cjs +103 -0
- package/src/stickers/studio.cjs +473 -0
- package/src/stickers/uploads.cjs +263 -0
- package/src/stickers/webp.cjs +231 -0
- package/src/stickers/zip.cjs +107 -0
- package/src/utils/messageContent.cjs +30 -4
- package/src/utils/multipart.esm.js +81 -0
- package/src/utils/recurrence.cjs +189 -30
- package/src/utils/stickerBot.cjs +84 -0
- package/src/utils/storage.cjs +3 -0
- package/src/utils/storage.esm.js +3 -0
- package/views/login.ejs +39 -3
- package/views/setup.ejs +21 -0
- package/public/dashboard/assets/index-B6RhYFIy.js +0 -446
- package/public/dashboard/assets/index-vEwOcxiH.css +0 -2
|
@@ -10,8 +10,8 @@
|
|
|
10
10
|
<link rel="preconnect" href="https://fonts.googleapis.com" />
|
|
11
11
|
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
|
|
12
12
|
<link href="https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@300;400;500;600;700;800&family=Tajawal:wght@400;500;700;800&family=JetBrains+Mono:wght@400;500&display=swap" rel="stylesheet" />
|
|
13
|
-
<script type="module" crossorigin src="/dashboard/assets/index-
|
|
14
|
-
<link rel="stylesheet" crossorigin href="/dashboard/assets/index-
|
|
13
|
+
<script type="module" crossorigin src="/dashboard/assets/index-IZMBuNAZ.js"></script>
|
|
14
|
+
<link rel="stylesheet" crossorigin href="/dashboard/assets/index-COI8zgqa.css">
|
|
15
15
|
</head>
|
|
16
16
|
<body>
|
|
17
17
|
<div id="root"></div>
|
package/public/dashboard.css
CHANGED
|
@@ -2973,3 +2973,35 @@ html.screen-guard .gateway-panel {
|
|
|
2973
2973
|
display: none;
|
|
2974
2974
|
}
|
|
2975
2975
|
}
|
|
2976
|
+
|
|
2977
|
+
.gateway-back-btn {
|
|
2978
|
+
display: inline-flex;
|
|
2979
|
+
align-items: center;
|
|
2980
|
+
gap: 0.375rem;
|
|
2981
|
+
padding: 0.375rem 0.625rem;
|
|
2982
|
+
margin-bottom: 0.75rem;
|
|
2983
|
+
border-radius: 0.625rem;
|
|
2984
|
+
border: 1px solid var(--line);
|
|
2985
|
+
background: var(--panel-raised);
|
|
2986
|
+
color: var(--text-main);
|
|
2987
|
+
font-size: 0.8125rem;
|
|
2988
|
+
font-weight: 500;
|
|
2989
|
+
cursor: pointer;
|
|
2990
|
+
transition: background 0.15s, color 0.15s;
|
|
2991
|
+
line-height: 1;
|
|
2992
|
+
}
|
|
2993
|
+
.gateway-back-btn[hidden] {
|
|
2994
|
+
display: none;
|
|
2995
|
+
}
|
|
2996
|
+
.gateway-back-btn:hover {
|
|
2997
|
+
background: var(--panel-hover);
|
|
2998
|
+
color: var(--brand-cyan);
|
|
2999
|
+
}
|
|
3000
|
+
.gateway-back-btn svg {
|
|
3001
|
+
width: 1rem;
|
|
3002
|
+
height: 1rem;
|
|
3003
|
+
flex-shrink: 0;
|
|
3004
|
+
}
|
|
3005
|
+
.gateway-back-btn[dir="rtl"] svg {
|
|
3006
|
+
transform: scaleX(-1);
|
|
3007
|
+
}
|
package/scheduler.cjs
CHANGED
|
@@ -17,6 +17,24 @@ const { detectLang, withLang, tr } = require("./src/utils/i18n.cjs");
|
|
|
17
17
|
const RETENTION_MS = 1000 * 60 * 60 * 24 * 3;
|
|
18
18
|
const cacheCleanupCron = "0 */6 * * *"; // every 6 hours
|
|
19
19
|
|
|
20
|
+
// A scheduled message can carry one media file. The bytes live under
|
|
21
|
+
// <data>/media/schedules/<job id> — a subfolder, which the retention sweep
|
|
22
|
+
// skips (it only unlinks files) — and are deleted with the job, not by age.
|
|
23
|
+
const SCHEDULE_MEDIA_MAX_BYTES = 20 * 1024 * 1024;
|
|
24
|
+
|
|
25
|
+
function scheduleMediaPath(jobId) {
|
|
26
|
+
// basename so a hand-crafted job id can never climb out of the folder
|
|
27
|
+
return path.join(ensureDataDir("media"), "schedules", path.basename(String(jobId)));
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function removeScheduleMedia(jobId) {
|
|
31
|
+
try {
|
|
32
|
+
fs.rmSync(scheduleMediaPath(jobId), { force: true });
|
|
33
|
+
} catch (err) {
|
|
34
|
+
logger.warn({ err, jobId }, "[Scheduler] failed to remove scheduled media");
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
20
38
|
function getScheduledJobs() {
|
|
21
39
|
try {
|
|
22
40
|
return storage.getSchedules();
|
|
@@ -151,6 +169,42 @@ function recordDelivery(jobId, status, runAt, error = null) {
|
|
|
151
169
|
}
|
|
152
170
|
}
|
|
153
171
|
|
|
172
|
+
/**
|
|
173
|
+
* What sendMessage receives for one job, in order: the text, or the stored
|
|
174
|
+
* media with the text as its caption. Audio and stickers take no caption, so
|
|
175
|
+
* their text follows as a message of its own instead of being dropped. Runs
|
|
176
|
+
* inside withLang() so tr() picks the right header.
|
|
177
|
+
*/
|
|
178
|
+
function buildScheduledPayloads(job) {
|
|
179
|
+
const header = tr("*Scheduled message 🗓️*", "*رسالة مجدولة 🗓️*");
|
|
180
|
+
const text = job.message ? `${header}\n\n${job.message}` : header;
|
|
181
|
+
if (!job.media) return [{ text }];
|
|
182
|
+
|
|
183
|
+
const buffer = fs.readFileSync(scheduleMediaPath(job.id));
|
|
184
|
+
const mimetype = job.media.mimeType || "application/octet-stream";
|
|
185
|
+
const caption = job.message ? text : undefined;
|
|
186
|
+
const followUp = job.message ? [{ text }] : [];
|
|
187
|
+
switch (job.media.kind) {
|
|
188
|
+
case "image":
|
|
189
|
+
return [{ image: buffer, mimetype, caption }];
|
|
190
|
+
case "video":
|
|
191
|
+
return [{ video: buffer, mimetype, caption }];
|
|
192
|
+
case "audio":
|
|
193
|
+
return [{ audio: buffer, mimetype, ptt: false }, ...followUp];
|
|
194
|
+
case "sticker":
|
|
195
|
+
return [{ sticker: buffer }, ...followUp];
|
|
196
|
+
default:
|
|
197
|
+
return [
|
|
198
|
+
{
|
|
199
|
+
document: buffer,
|
|
200
|
+
mimetype,
|
|
201
|
+
fileName: job.media.fileName || undefined,
|
|
202
|
+
caption,
|
|
203
|
+
},
|
|
204
|
+
];
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
154
208
|
async function deliverScheduledJob(sock, job) {
|
|
155
209
|
if (deliveriesInFlight.has(job.id)) {
|
|
156
210
|
logger.warn(`[Scheduler] Job ${job.id} is already being delivered — skipping overlap`);
|
|
@@ -161,13 +215,12 @@ async function deliverScheduledJob(sock, job) {
|
|
|
161
215
|
const runAt = Date.now();
|
|
162
216
|
|
|
163
217
|
try {
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
});
|
|
218
|
+
// No message is being answered here, so the header follows the scheduled
|
|
219
|
+
// text itself (in "auto"), or the bot's language.
|
|
220
|
+
const payloads = withLang(detectLang(job.message || " "), () => buildScheduledPayloads(job));
|
|
221
|
+
for (const payload of payloads) {
|
|
222
|
+
await sock.sendMessage(job.targetJid, payload);
|
|
223
|
+
}
|
|
171
224
|
recordDelivery(job.id, "sent", runAt);
|
|
172
225
|
logger.info(`[Scheduler] Executed job ${job.id} -> ${job.targetJid}`);
|
|
173
226
|
return { ok: true, reason: "sent" };
|
|
@@ -193,6 +246,9 @@ async function executeScheduledJob(sock, job) {
|
|
|
193
246
|
"[Scheduler] failed to record one-off schedule status",
|
|
194
247
|
);
|
|
195
248
|
}
|
|
249
|
+
// A sent one-off never fires again, so its media copy is dead weight —
|
|
250
|
+
// but a failed one stays retryable and keeps its file.
|
|
251
|
+
if (result.ok) removeScheduleMedia(job.id);
|
|
196
252
|
}
|
|
197
253
|
|
|
198
254
|
return result;
|
|
@@ -264,6 +320,7 @@ async function retryScheduledJob(sock, jobId) {
|
|
|
264
320
|
function deleteScheduledJob(jobId) {
|
|
265
321
|
stopTask(jobId);
|
|
266
322
|
storage.deleteSchedule(jobId);
|
|
323
|
+
removeScheduleMedia(jobId);
|
|
267
324
|
logger.info(`[Scheduler] Deleted job ${jobId}.`);
|
|
268
325
|
return true;
|
|
269
326
|
}
|
|
@@ -286,6 +343,7 @@ function scheduleJobNow(job) {
|
|
|
286
343
|
}
|
|
287
344
|
|
|
288
345
|
module.exports = {
|
|
346
|
+
SCHEDULE_MEDIA_MAX_BYTES,
|
|
289
347
|
initializeScheduledJobs,
|
|
290
348
|
stopAllScheduledJobs,
|
|
291
349
|
scheduleNewJob,
|
|
@@ -294,5 +352,6 @@ module.exports = {
|
|
|
294
352
|
getScheduledJobs,
|
|
295
353
|
saveScheduledJob,
|
|
296
354
|
deleteScheduledJob,
|
|
355
|
+
scheduleMediaPath,
|
|
297
356
|
updateJobStatus,
|
|
298
357
|
};
|
package/src/bootstrap/panel.js
CHANGED
|
@@ -46,10 +46,19 @@ export async function bootstrapPanel({ core } = {}) {
|
|
|
46
46
|
const { default: dashboardApiRoutes, setSession } = await import(
|
|
47
47
|
"../routes/dashboard.api.esm.js"
|
|
48
48
|
);
|
|
49
|
+
const stickerApi = await import("../routes/stickers.api.esm.js");
|
|
49
50
|
|
|
50
|
-
// Same session as the control panel
|
|
51
|
-
//
|
|
52
|
-
|
|
51
|
+
// Same session as the control panel. One chain and one JSON parser: the
|
|
52
|
+
// sticker upload is raw bytes (any Content-Type, up to the upload cap) and
|
|
53
|
+
// express.json would consume it before the route can enforce that cap.
|
|
54
|
+
app.use(
|
|
55
|
+
"/dashboard/api",
|
|
56
|
+
requireLoginApi,
|
|
57
|
+
noStore,
|
|
58
|
+
stickerApi.jsonUnlessStickerUpload(dashboardJson),
|
|
59
|
+
stickerApi.default,
|
|
60
|
+
dashboardApiRoutes,
|
|
61
|
+
);
|
|
53
62
|
logger.info("Dashboard API routes registered");
|
|
54
63
|
|
|
55
64
|
// Everything the bot reports goes out to the browsers watching the panel.
|
|
@@ -65,7 +74,10 @@ export async function bootstrapPanel({ core } = {}) {
|
|
|
65
74
|
|
|
66
75
|
// The routes read the live socket off the session manager, so a reconnect
|
|
67
76
|
// needs no re-wiring here.
|
|
68
|
-
if (core?.session)
|
|
77
|
+
if (core?.session) {
|
|
78
|
+
setSession(core.session);
|
|
79
|
+
stickerApi.setSession(core.session);
|
|
80
|
+
}
|
|
69
81
|
// The WhatsApp-code password reset talks to the same session manager.
|
|
70
82
|
if (core?.session) require("../panel/password-reset.cjs").setSession(core.session);
|
|
71
83
|
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
const { tr } = require("../utils/i18n.cjs");
|
|
2
|
+
const { createStatus } = require("../utils/statusMessage.cjs");
|
|
3
|
+
const {
|
|
4
|
+
targetOf,
|
|
5
|
+
downloadTarget,
|
|
6
|
+
commandHint,
|
|
7
|
+
countLabel,
|
|
8
|
+
errorText,
|
|
9
|
+
} = require("../utils/stickerBot.cjs");
|
|
10
|
+
const { StickerError } = require("../stickers/errors.cjs");
|
|
11
|
+
const { BOT_VIDEO_MAX_SECONDS, PACK_SUBCOMMANDS } = require("../stickers/limits.cjs");
|
|
12
|
+
const ownerModule = require("../stickers/owner.cjs");
|
|
13
|
+
const library = require("../stickers/library.cjs");
|
|
14
|
+
const studio = require("../stickers/studio.cjs");
|
|
15
|
+
|
|
16
|
+
const keywords = Object.values(PACK_SUBCOMMANDS).flat();
|
|
17
|
+
|
|
18
|
+
function parse(args) {
|
|
19
|
+
const [first, ...rest] = args;
|
|
20
|
+
const word = /^[a-z]+$/i.test(first || "") ? first.toLowerCase() : first;
|
|
21
|
+
const action =
|
|
22
|
+
Object.entries(PACK_SUBCOMMANDS).find(([, words]) => words.includes(word))?.[0] || "auto";
|
|
23
|
+
if (action === "rename") {
|
|
24
|
+
const text = rest.join(" ").trim();
|
|
25
|
+
const names = text.includes("|")
|
|
26
|
+
? text.split("|").map((s) => s.trim())
|
|
27
|
+
: rest.length === 2
|
|
28
|
+
? rest
|
|
29
|
+
: [];
|
|
30
|
+
return {
|
|
31
|
+
action,
|
|
32
|
+
oldName: names[0] || "",
|
|
33
|
+
newName: names[1] || "",
|
|
34
|
+
valid: names.length === 2 && names.every(Boolean),
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
return { action, name: (action === "auto" ? args : rest).join(" ").trim() };
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function requirePack(who, name) {
|
|
41
|
+
const pack = library.findPackByName(who, name);
|
|
42
|
+
if (!pack) throw new StickerError("PACK_NOT_FOUND", { name });
|
|
43
|
+
return pack;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
module.exports = {
|
|
47
|
+
name: "pack",
|
|
48
|
+
aliases: ["حزمة"],
|
|
49
|
+
description: {
|
|
50
|
+
en: "Create, fill and manage your sticker packs.",
|
|
51
|
+
ar: "ينشئ حزم الملصقات ويديرها ويضيف إليها.",
|
|
52
|
+
},
|
|
53
|
+
usage: {
|
|
54
|
+
en: "pack <name> (reply to media to add)\npack <name> (show without a reply)\npack create <name>\npack add <name>\npack remove <name>\npack rename <old> | <new>\npack delete <name>\npack show <name>",
|
|
55
|
+
ar: "pack <الاسم> (رد على وسائط للإضافة)\npack <الاسم> (عرض بلا رد)\npack إنشاء <الاسم>\npack إضافة <الاسم>\npack إزالة <الاسم>\npack تسمية <القديم> | <الجديد>\npack حذف <الاسم>\npack عرض <الاسم>",
|
|
56
|
+
},
|
|
57
|
+
keywords,
|
|
58
|
+
chat: "all",
|
|
59
|
+
async execute(sock, msg, args = []) {
|
|
60
|
+
const jid = msg.key.remoteJid;
|
|
61
|
+
const who = await ownerModule.forMessage(msg, sock);
|
|
62
|
+
if (!who.key)
|
|
63
|
+
return sock.sendMessage(jid, {
|
|
64
|
+
text: tr("I couldn't identify the sender.", "تعذّر تحديد هوية المرسل."),
|
|
65
|
+
});
|
|
66
|
+
const parsed = parse(args);
|
|
67
|
+
let status;
|
|
68
|
+
try {
|
|
69
|
+
let line;
|
|
70
|
+
if (parsed.action === "rename") {
|
|
71
|
+
if (!parsed.valid) throw new StickerError("INVALID_NAME");
|
|
72
|
+
const pack = requirePack(who, parsed.oldName);
|
|
73
|
+
const renamed = library.updatePack(who, pack.id, parsed.newName);
|
|
74
|
+
line = tr(`Renamed pack to ${renamed.name}.`, `أُعيدت تسمية الحزمة إلى ${renamed.name}.`);
|
|
75
|
+
} else if (!parsed.name) {
|
|
76
|
+
line = tr(
|
|
77
|
+
`Use ${commandHint("pack", "<name>")} while replying to media, or ${commandHint("pack", "create <name>")}.`,
|
|
78
|
+
`استخدم ${commandHint("pack", "<الاسم>")} عند الرد على وسائط، أو ${commandHint("pack", "إنشاء <الاسم>")}.`,
|
|
79
|
+
);
|
|
80
|
+
} else if (parsed.action === "create") {
|
|
81
|
+
const pack = library.createPack(who, parsed.name);
|
|
82
|
+
line = tr(`Created pack ${pack.name}.`, `أُنشئت الحزمة ${pack.name}.`);
|
|
83
|
+
} else if (parsed.action === "delete") {
|
|
84
|
+
const pack = requirePack(who, parsed.name);
|
|
85
|
+
library.deletePack(who, pack.id);
|
|
86
|
+
line = tr(
|
|
87
|
+
`Deleted pack ${pack.name}. Its stickers remain in your library.`,
|
|
88
|
+
`حُذفت الحزمة ${pack.name}. بقيت ملصقاتها في مكتبتك.`,
|
|
89
|
+
);
|
|
90
|
+
} else if (parsed.action === "remove") {
|
|
91
|
+
const pack = requirePack(who, parsed.name);
|
|
92
|
+
const target = targetOf(msg, { quotedOnly: true });
|
|
93
|
+
if (target?.type !== "sticker") throw new StickerError("NO_MEDIA");
|
|
94
|
+
const buffer = await downloadTarget(target);
|
|
95
|
+
const sticker = library.findStickerByContent(who, buffer);
|
|
96
|
+
const removed = library.removeFromPack(who, pack.id, [sticker.id]);
|
|
97
|
+
if (!removed.affected) throw new StickerError("NOT_FOUND");
|
|
98
|
+
line = tr(
|
|
99
|
+
`Removed the sticker from ${pack.name}. It remains in your library.`,
|
|
100
|
+
`أُزيل الملصق من ${pack.name}. بقي في مكتبتك.`,
|
|
101
|
+
);
|
|
102
|
+
} else {
|
|
103
|
+
const target = targetOf(msg, { quotedOnly: true });
|
|
104
|
+
if (parsed.action === "show" || (parsed.action === "auto" && !target)) {
|
|
105
|
+
const pack = requirePack(who, parsed.name);
|
|
106
|
+
line = tr(
|
|
107
|
+
`${pack.name} — ${countLabel(pack.count)}. Use ${commandHint("stickers", `pack ${pack.name}`)} to see them.`,
|
|
108
|
+
`${pack.name} — ${countLabel(pack.count)}. استخدم ${commandHint("stickers", `حزمة ${pack.name}`)} لعرضها.`,
|
|
109
|
+
);
|
|
110
|
+
} else {
|
|
111
|
+
if (!target) throw new StickerError("NO_MEDIA");
|
|
112
|
+
let pack = library.findPackByName(who, parsed.name);
|
|
113
|
+
const createdPack = !pack;
|
|
114
|
+
if (createdPack) pack = library.createPack(who, parsed.name);
|
|
115
|
+
try {
|
|
116
|
+
const buffer = await downloadTarget(target);
|
|
117
|
+
status = await createStatus(
|
|
118
|
+
sock,
|
|
119
|
+
jid,
|
|
120
|
+
tr("🎨 Saving sticker...", "🎨 جارٍ حفظ الملصق..."),
|
|
121
|
+
{ replyTo: msg },
|
|
122
|
+
);
|
|
123
|
+
const { promise } = studio.createFromBuffer({
|
|
124
|
+
owner: who,
|
|
125
|
+
buffer,
|
|
126
|
+
source: target.type === "sticker" ? "WHATSAPP_STICKER" : "BOT_COMMAND",
|
|
127
|
+
packId: pack.id,
|
|
128
|
+
maxSourceSeconds: BOT_VIDEO_MAX_SECONDS,
|
|
129
|
+
});
|
|
130
|
+
const result = await promise;
|
|
131
|
+
line = result.created
|
|
132
|
+
? tr(`Saved sticker to ${pack.name}.`, `حُفظ الملصق في ${pack.name}.`)
|
|
133
|
+
: tr(
|
|
134
|
+
`Already in your library; added to ${pack.name}.`,
|
|
135
|
+
`الملصق موجود في مكتبتك بالفعل؛ أُضيف إلى ${pack.name}.`,
|
|
136
|
+
);
|
|
137
|
+
} catch (error) {
|
|
138
|
+
if (createdPack) {
|
|
139
|
+
try {
|
|
140
|
+
if (library.getPack(who, pack.id).pack.count === 0)
|
|
141
|
+
library.deletePack(who, pack.id);
|
|
142
|
+
} catch {
|
|
143
|
+
// Preserve the original conversion error; a concurrent change
|
|
144
|
+
// may have removed or filled the pack before cleanup.
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
throw error;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
if (status) await status.finish(line);
|
|
152
|
+
else await sock.sendMessage(jid, { text: line });
|
|
153
|
+
} catch (error) {
|
|
154
|
+
const line = errorText(error);
|
|
155
|
+
if (status) await status.finish(line);
|
|
156
|
+
else await sock.sendMessage(jid, { text: line });
|
|
157
|
+
}
|
|
158
|
+
},
|
|
159
|
+
};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
const { tr } = require("../utils/i18n.cjs");
|
|
2
|
+
const ownerModule = require("../stickers/owner.cjs");
|
|
3
|
+
const library = require("../stickers/library.cjs");
|
|
4
|
+
const { commandHint, countLabel, errorText } = require("../utils/stickerBot.cjs");
|
|
5
|
+
|
|
6
|
+
module.exports = {
|
|
7
|
+
name: "packs",
|
|
8
|
+
aliases: ["حزم"],
|
|
9
|
+
description: {
|
|
10
|
+
en: "List your sticker packs and library total.",
|
|
11
|
+
ar: "يعرض حزم ملصقاتك وإجمالي المكتبة.",
|
|
12
|
+
},
|
|
13
|
+
usage: { en: "packs", ar: "packs" },
|
|
14
|
+
chat: "all",
|
|
15
|
+
async execute(sock, msg) {
|
|
16
|
+
const jid = msg.key.remoteJid;
|
|
17
|
+
const who = await ownerModule.forMessage(msg, sock);
|
|
18
|
+
if (!who.key)
|
|
19
|
+
return sock.sendMessage(jid, {
|
|
20
|
+
text: tr("I couldn't identify the sender.", "تعذّر تحديد هوية المرسل."),
|
|
21
|
+
});
|
|
22
|
+
try {
|
|
23
|
+
const packs = library.listPacks(who);
|
|
24
|
+
const total = library.listStickers(who, { limit: 1 }).total;
|
|
25
|
+
if (!packs.length)
|
|
26
|
+
return sock.sendMessage(jid, {
|
|
27
|
+
text: tr(
|
|
28
|
+
`No packs yet. Reply to media with ${commandHint("pack", "<name>")} to start one. Library: ${countLabel(total)}.`,
|
|
29
|
+
`لا توجد حزم بعد. رد على وسائط بالأمر ${commandHint("pack", "<الاسم>")} لإنشاء حزمة. المكتبة: ${countLabel(total)}.`,
|
|
30
|
+
),
|
|
31
|
+
});
|
|
32
|
+
const lines = packs.slice(0, 30).map((pack) => `${pack.name} — ${countLabel(pack.count)}`);
|
|
33
|
+
if (packs.length > 30)
|
|
34
|
+
lines.push(
|
|
35
|
+
tr(
|
|
36
|
+
`and ${countLabel(packs.length - 30, "pack")} more`,
|
|
37
|
+
`و${countLabel(packs.length - 30, "pack")} أخرى`,
|
|
38
|
+
),
|
|
39
|
+
);
|
|
40
|
+
await sock.sendMessage(jid, {
|
|
41
|
+
text: `${tr("Your packs · Library:", "حزمك · المكتبة:")} ${countLabel(total)}\n${lines.join("\n")}`,
|
|
42
|
+
});
|
|
43
|
+
} catch (error) {
|
|
44
|
+
await sock.sendMessage(jid, { text: errorText(error) });
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
};
|
package/src/commands/send.cjs
CHANGED
|
@@ -8,28 +8,11 @@
|
|
|
8
8
|
// decrypt it again — nothing is cached and nothing is archived.
|
|
9
9
|
const { downloadContentFromMessage } = require("@whiskeysockets/baileys");
|
|
10
10
|
const { downloadMedia } = require("../utils/geminiMedia.cjs");
|
|
11
|
-
const {
|
|
11
|
+
const { visibleText, pickMedia, quotedOf } = require("../utils/messageContent.cjs");
|
|
12
12
|
const { createStatus } = require("../utils/statusMessage.cjs");
|
|
13
13
|
const logger = require("../utils/logger.cjs");
|
|
14
14
|
const { tr } = require("../utils/i18n.cjs");
|
|
15
15
|
|
|
16
|
-
// The media in a message plus the download type that decrypts it — the type
|
|
17
|
-
// WhatsApp filed it under, not the MIME type (same rule as the AI command).
|
|
18
|
-
function pickMedia(message) {
|
|
19
|
-
const inner = unwrapMessage(message);
|
|
20
|
-
if (inner.stickerMessage) return { media: inner.stickerMessage, type: "sticker" };
|
|
21
|
-
if (inner.imageMessage) return { media: inner.imageMessage, type: "image" };
|
|
22
|
-
if (inner.videoMessage) return { media: inner.videoMessage, type: "video" };
|
|
23
|
-
if (inner.audioMessage) return { media: inner.audioMessage, type: "audio" };
|
|
24
|
-
if (inner.documentMessage) return { media: inner.documentMessage, type: "document" };
|
|
25
|
-
return null;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
function quotedOf(msg) {
|
|
29
|
-
const own = unwrapMessage(msg.message);
|
|
30
|
-
return own.extendedTextMessage?.contextInfo?.quotedMessage || null;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
16
|
module.exports = {
|
|
34
17
|
name: "send",
|
|
35
18
|
description: {
|