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.
- package/README.md +1 -0
- package/package.json +1 -1
- package/public/dashboard/assets/index-5P8GnKLg.css +2 -0
- package/public/dashboard/assets/index-DXzno3X6.js +515 -0
- package/public/dashboard/index.html +2 -2
- package/public/dashboard.css +32 -0
- package/src/bootstrap/panel.js +16 -4
- package/src/commands/autoschedule.cjs +1 -1
- package/src/commands/blacklist.cjs +1 -1
- package/src/commands/calc.cjs +9 -9
- package/src/commands/gemini.cjs +26 -26
- package/src/commands/group/add.cjs +2 -2
- package/src/commands/group/demote.cjs +2 -2
- package/src/commands/group/members.cjs +2 -2
- package/src/commands/group/rules.cjs +1 -1
- package/src/commands/group/setname.cjs +3 -3
- package/src/commands/group/setpp.cjs +3 -3
- package/src/commands/group/setrules.cjs +1 -1
- package/src/commands/group/tagadmins.cjs +1 -1
- package/src/commands/group.cjs +1 -1
- package/src/commands/lang.cjs +3 -3
- package/src/commands/listschedules.cjs +1 -1
- package/src/commands/loop.cjs +3 -3
- package/src/commands/memory.cjs +18 -18
- package/src/commands/notes.cjs +1 -1
- package/src/commands/pack.cjs +159 -0
- package/src/commands/packs.cjs +47 -0
- package/src/commands/perm.cjs +2 -2
- package/src/commands/poll.cjs +3 -3
- package/src/commands/rand.cjs +2 -2
- package/src/commands/restart.cjs +4 -4
- package/src/commands/schedule.cjs +1 -1
- package/src/commands/send.cjs +3 -20
- package/src/commands/status.cjs +2 -2
- package/src/commands/sticker.cjs +77 -232
- package/src/commands/stickers.cjs +100 -0
- package/src/commands/stopbot.cjs +5 -5
- package/src/commands/stt.cjs +1 -1
- package/src/commands/toimage.cjs +88 -0
- package/src/commands/tts.cjs +2 -2
- 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 +381 -0
- package/src/db/store.cjs +729 -21
- package/src/handlers/command.handler.js +5 -1
- package/src/panel/password-reset.cjs +1 -1
- package/src/routes/dashboard.api.esm.js +43 -10
- package/src/routes/stickers.api.esm.js +570 -0
- package/src/services/aiAgent.cjs +2 -2
- package/src/services/aiProviders.cjs +1 -1
- package/src/services/aiTools.cjs +27 -27
- 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/memory.cjs +7 -7
- package/src/utils/messageContent.cjs +30 -4
- 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-BCXZoPGP.js +0 -446
- package/public/dashboard/assets/index-LvfJ8ybs.css +0 -2
package/src/services/aiTools.cjs
CHANGED
|
@@ -244,14 +244,14 @@ async function assertPublicUrl(rawUrl) {
|
|
|
244
244
|
try {
|
|
245
245
|
url = new URL(rawUrl);
|
|
246
246
|
} catch {
|
|
247
|
-
throw new Error("الرابط
|
|
247
|
+
throw new Error("الرابط غير صالح");
|
|
248
248
|
}
|
|
249
|
-
if (url.protocol !== "https:") throw new Error("
|
|
249
|
+
if (url.protocol !== "https:") throw new Error("يُسمح بروابط HTTPS فقط");
|
|
250
250
|
|
|
251
251
|
const host = url.hostname.replace(/^\[|\]$/g, "");
|
|
252
252
|
|
|
253
253
|
if (net.isIP(host)) {
|
|
254
|
-
if (isForbiddenIp(host)) throw new Error("الرابط
|
|
254
|
+
if (isForbiddenIp(host)) throw new Error("هذا الرابط محظور");
|
|
255
255
|
return { url, host, addresses: [{ address: host, family: net.isIP(host) }] };
|
|
256
256
|
}
|
|
257
257
|
|
|
@@ -259,10 +259,10 @@ async function assertPublicUrl(rawUrl) {
|
|
|
259
259
|
try {
|
|
260
260
|
addresses = await dns.lookup(host, { all: true, verbatim: true });
|
|
261
261
|
} catch {
|
|
262
|
-
throw new Error("
|
|
262
|
+
throw new Error("تعذّر الوصول إلى هذا النطاق");
|
|
263
263
|
}
|
|
264
264
|
if (!addresses.length || addresses.some((a) => isForbiddenIp(a.address))) {
|
|
265
|
-
throw new Error("الرابط
|
|
265
|
+
throw new Error("هذا الرابط محظور");
|
|
266
266
|
}
|
|
267
267
|
|
|
268
268
|
return { url, host, addresses };
|
|
@@ -281,7 +281,7 @@ function pinnedAgent(expectedHost, addresses) {
|
|
|
281
281
|
? addresses.filter(({ family }) => family === requestedFamily)
|
|
282
282
|
: addresses;
|
|
283
283
|
if (!candidates.length) {
|
|
284
|
-
const error = new Error("
|
|
284
|
+
const error = new Error("لا يوجد عنوان متوافق لهذا النطاق");
|
|
285
285
|
error.code = "EAI_ADDRFAMILY";
|
|
286
286
|
return callback(error);
|
|
287
287
|
}
|
|
@@ -328,7 +328,7 @@ async function fetchUrl(rawUrl) {
|
|
|
328
328
|
const location = response.headers?.location;
|
|
329
329
|
const isRedirect = response.status >= 300 && response.status < 400 && location;
|
|
330
330
|
if (!isRedirect) break;
|
|
331
|
-
if (hop >= MAX_REDIRECTS) throw new Error("الرابط
|
|
331
|
+
if (hop >= MAX_REDIRECTS) throw new Error("تجاوز الرابط الحد المسموح لعمليات إعادة التوجيه");
|
|
332
332
|
|
|
333
333
|
target = await assertPublicUrl(new URL(location, url).toString());
|
|
334
334
|
}
|
|
@@ -405,7 +405,7 @@ const TOOLS = {
|
|
|
405
405
|
required: ["query"],
|
|
406
406
|
},
|
|
407
407
|
},
|
|
408
|
-
describe: (args) => `🔍
|
|
408
|
+
describe: (args) => `🔍 جارٍ البحث عن: ${preview(args?.query, 50)}`,
|
|
409
409
|
describeEn: (args) => `🔍 Searching for: ${preview(args?.query, 50)}`,
|
|
410
410
|
async run(args) {
|
|
411
411
|
const query = String(args?.query || "").trim();
|
|
@@ -446,7 +446,7 @@ const TOOLS = {
|
|
|
446
446
|
required: ["query"],
|
|
447
447
|
},
|
|
448
448
|
},
|
|
449
|
-
describe: (args) => `📚
|
|
449
|
+
describe: (args) => `📚 جارٍ البحث في ويكيبيديا: ${preview(args?.query, 45)}`,
|
|
450
450
|
describeEn: (args) => `📚 Searching Wikipedia: ${preview(args?.query, 45)}`,
|
|
451
451
|
async run(args) {
|
|
452
452
|
const query = String(args?.query || "").trim();
|
|
@@ -476,7 +476,7 @@ const TOOLS = {
|
|
|
476
476
|
required: ["query"],
|
|
477
477
|
},
|
|
478
478
|
},
|
|
479
|
-
describe: (args) => `📰
|
|
479
|
+
describe: (args) => `📰 جارٍ البحث عن الأخبار: ${preview(args?.query, 45)}`,
|
|
480
480
|
describeEn: (args) => `📰 Searching news: ${preview(args?.query, 45)}`,
|
|
481
481
|
async run(args) {
|
|
482
482
|
const query = String(args?.query || "").trim();
|
|
@@ -505,7 +505,7 @@ const TOOLS = {
|
|
|
505
505
|
required: ["url"],
|
|
506
506
|
},
|
|
507
507
|
},
|
|
508
|
-
describe: (args) => `🌐
|
|
508
|
+
describe: (args) => `🌐 جارٍ فتح الرابط: ${preview(args?.url, 45)}`,
|
|
509
509
|
describeEn: (args) => `🌐 Opening link: ${preview(args?.url, 45)}`,
|
|
510
510
|
async run(args) {
|
|
511
511
|
const url = String(args?.url || "").trim();
|
|
@@ -518,7 +518,7 @@ const TOOLS = {
|
|
|
518
518
|
declaration: {
|
|
519
519
|
name: "save_memory",
|
|
520
520
|
description:
|
|
521
|
-
"Save a fact to long-term memory so it survives across conversations. Use it whenever the user says things like 'save this', 'remember that', 'احفظ
|
|
521
|
+
"Save a fact to long-term memory so it survives across conversations. Use it whenever the user says things like 'save this', 'remember that', 'احفظ هذا في ذاكرتك'. scope 'chat' keeps it to this conversation, scope 'global' shares it with every chat.",
|
|
522
522
|
parameters: {
|
|
523
523
|
type: T.OBJECT,
|
|
524
524
|
properties: {
|
|
@@ -535,7 +535,7 @@ const TOOLS = {
|
|
|
535
535
|
},
|
|
536
536
|
},
|
|
537
537
|
describe: (args) =>
|
|
538
|
-
`🧠
|
|
538
|
+
`🧠 جارٍ الحفظ في ${scopeOf(args) === "global" ? "الذاكرة العامة" : "ذاكرة المحادثة"}: ${preview(
|
|
539
539
|
args?.content,
|
|
540
540
|
)}`,
|
|
541
541
|
describeEn: (args) =>
|
|
@@ -585,7 +585,7 @@ const TOOLS = {
|
|
|
585
585
|
},
|
|
586
586
|
},
|
|
587
587
|
},
|
|
588
|
-
describe: () => "🧠
|
|
588
|
+
describe: () => "🧠 جارٍ البحث في الذاكرة...",
|
|
589
589
|
describeEn: () => "🧠 Searching memory...",
|
|
590
590
|
// `!memory search` reads both scopes for anyone who may run `!memory`.
|
|
591
591
|
access: { command: "memory" },
|
|
@@ -619,7 +619,7 @@ const TOOLS = {
|
|
|
619
619
|
required: ["ref"],
|
|
620
620
|
},
|
|
621
621
|
},
|
|
622
|
-
describe: (args) => `🗑️
|
|
622
|
+
describe: (args) => `🗑️ جارٍ الحذف من الذاكرة: ${preview(args?.ref)}`,
|
|
623
623
|
describeEn: (args) => `🗑️ Removing from memory: ${preview(args?.ref)}`,
|
|
624
624
|
// `!memory forget`: global needs the owner or a bot admin; chat memory
|
|
625
625
|
// also lets an admin of this group tidy their own chat.
|
|
@@ -659,7 +659,7 @@ const TOOLS = {
|
|
|
659
659
|
},
|
|
660
660
|
},
|
|
661
661
|
describe: (args) =>
|
|
662
|
-
`🔑
|
|
662
|
+
`🔑 جارٍ فحص صلاحيات: ${preview(args?.target, 25)} (${args?.role || "admin"})`,
|
|
663
663
|
describeEn: (args) =>
|
|
664
664
|
`🔑 Checking permissions: ${preview(args?.target, 25)} (${args?.role || "admin"})`,
|
|
665
665
|
// `!perm add`: that command's level (owner only unless the operator
|
|
@@ -699,7 +699,7 @@ const TOOLS = {
|
|
|
699
699
|
required: ["target"],
|
|
700
700
|
},
|
|
701
701
|
},
|
|
702
|
-
describe: (args) => `🔑
|
|
702
|
+
describe: (args) => `🔑 جارٍ سحب الصلاحية من: ${preview(args?.target, 25)}`,
|
|
703
703
|
describeEn: (args) => `🔑 Revoking permissions from: ${preview(args?.target, 25)}`,
|
|
704
704
|
// `!perm remove`, gated exactly like grant_role.
|
|
705
705
|
access: (args) => ({ command: "perm", role: roleOf(args) === "owner" ? "owner" : undefined }),
|
|
@@ -723,7 +723,7 @@ const TOOLS = {
|
|
|
723
723
|
"List who currently holds bot owner / admin roles. Allowed for whoever may run !perm (the owner, by default).",
|
|
724
724
|
parameters: { type: T.OBJECT, properties: {} },
|
|
725
725
|
},
|
|
726
|
-
describe: () => "🔑
|
|
726
|
+
describe: () => "🔑 جارٍ جلب قائمة الصلاحيات...",
|
|
727
727
|
describeEn: () => "🔑 Fetching roles list...",
|
|
728
728
|
// `!perm list` — the roster is `!perm`'s to show.
|
|
729
729
|
access: { command: "perm" },
|
|
@@ -753,7 +753,7 @@ const TOOLS = {
|
|
|
753
753
|
},
|
|
754
754
|
},
|
|
755
755
|
},
|
|
756
|
-
describe: () => "🕒
|
|
756
|
+
describe: () => "🕒 جارٍ التحقق من الوقت الحالي...",
|
|
757
757
|
describeEn: () => "🕒 Checking current time...",
|
|
758
758
|
async run(args) {
|
|
759
759
|
const timeZone = args?.timezone || settings.get("bot_timezone");
|
|
@@ -788,7 +788,7 @@ const TOOLS = {
|
|
|
788
788
|
required: ["expression"],
|
|
789
789
|
},
|
|
790
790
|
},
|
|
791
|
-
describe: (args) => `🧮
|
|
791
|
+
describe: (args) => `🧮 جارٍ الحساب: ${preview(args?.expression, 40)}`,
|
|
792
792
|
describeEn: (args) => `🧮 Calculating: ${preview(args?.expression, 40)}`,
|
|
793
793
|
async run(args) {
|
|
794
794
|
const expression = String(args?.expression || "").trim();
|
|
@@ -829,7 +829,7 @@ const TOOLS = {
|
|
|
829
829
|
required: ["message"],
|
|
830
830
|
},
|
|
831
831
|
},
|
|
832
|
-
describe: (args) => `⏰
|
|
832
|
+
describe: (args) => `⏰ جارٍ إعداد التذكير: ${preview(args?.message, 40)}`,
|
|
833
833
|
describeEn: (args) => `⏰ Setting a reminder: ${preview(args?.message, 40)}`,
|
|
834
834
|
// Posting into a chat at a later time is exactly what `!schedule` does, so
|
|
835
835
|
// it takes `!schedule`'s permission level — whatever the dashboard sets.
|
|
@@ -911,7 +911,7 @@ const TOOLS = {
|
|
|
911
911
|
required: ["id"],
|
|
912
912
|
},
|
|
913
913
|
},
|
|
914
|
-
describe: (args) => `⏰
|
|
914
|
+
describe: (args) => `⏰ جارٍ إلغاء التذكير: ${preview(args?.id, 20)}`,
|
|
915
915
|
describeEn: (args) => `⏰ Cancelling reminder: ${preview(args?.id, 20)}`,
|
|
916
916
|
// Deleting a scheduled job is `!deleteschedule`'s job, so its level.
|
|
917
917
|
access: { command: "deleteschedule" },
|
|
@@ -937,7 +937,7 @@ const TOOLS = {
|
|
|
937
937
|
declaration: {
|
|
938
938
|
name: "speak",
|
|
939
939
|
description:
|
|
940
|
-
"Send your answer as a WhatsApp VOICE NOTE (text-to-speech) instead of text. Only when the user explicitly asks to hear it — '
|
|
940
|
+
"Send your answer as a WhatsApp VOICE NOTE (text-to-speech) instead of text. Only when the user explicitly asks to hear it — 'اقرأها بصوت', 'read it aloud', 'send it as voice'. The text must be ready to be read aloud; keep it short.",
|
|
941
941
|
parameters: {
|
|
942
942
|
type: T.OBJECT,
|
|
943
943
|
properties: {
|
|
@@ -953,7 +953,7 @@ const TOOLS = {
|
|
|
953
953
|
required: ["text"],
|
|
954
954
|
},
|
|
955
955
|
},
|
|
956
|
-
describe: (args) => `🎙️
|
|
956
|
+
describe: (args) => `🎙️ جارٍ تحويل الرد لرسالة صوتية: ${preview(args?.text, 40)}`,
|
|
957
957
|
describeEn: (args) => `🎙️ Converting the reply to a voice note: ${preview(args?.text, 40)}`,
|
|
958
958
|
// Posting a voice note into this chat is what `!tts` does, so its level.
|
|
959
959
|
access: { command: "tts" },
|
|
@@ -1003,7 +1003,7 @@ const TOOLS = {
|
|
|
1003
1003
|
required: ["question", "options"],
|
|
1004
1004
|
},
|
|
1005
1005
|
},
|
|
1006
|
-
describe: (args) => `📊
|
|
1006
|
+
describe: (args) => `📊 جارٍ إنشاء الاستفتاء: ${preview(args?.question, 40)}`,
|
|
1007
1007
|
describeEn: (args) => `📊 Creating a poll: ${preview(args?.question, 40)}`,
|
|
1008
1008
|
// A poll is a group message like any other, so `!poll`'s level.
|
|
1009
1009
|
access: { command: "poll" },
|
|
@@ -1042,7 +1042,7 @@ const TOOLS = {
|
|
|
1042
1042
|
},
|
|
1043
1043
|
},
|
|
1044
1044
|
},
|
|
1045
|
-
describe: () => "🧠
|
|
1045
|
+
describe: () => "🧠 جارٍ تلخيص المحادثة وحفظ المهم...",
|
|
1046
1046
|
describeEn: () => "🧠 Summarizing the chat and saving what matters...",
|
|
1047
1047
|
// Saving chat memory is what `!memory add` allows here; the global scope
|
|
1048
1048
|
// reaches every chat's prompt, so it takes save_memory's owner/admin role.
|
|
@@ -1171,7 +1171,7 @@ async function summarizeWithProvider(transcript) {
|
|
|
1171
1171
|
function describeCall(name, args, lang = currentLang()) {
|
|
1172
1172
|
const tool = TOOLS[name];
|
|
1173
1173
|
const isEn = lang === "en";
|
|
1174
|
-
const fallback = isEn ? `⚙️ Running: ${name}` : `⚙️
|
|
1174
|
+
const fallback = isEn ? `⚙️ Running: ${name}` : `⚙️ جارٍ تشغيل: ${name}`;
|
|
1175
1175
|
if (!tool) return fallback;
|
|
1176
1176
|
try {
|
|
1177
1177
|
if (isEn && typeof tool.describeEn === "function") {
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
// Sticker Studio errors: one vocabulary for the panel and the bot.
|
|
2
|
+
//
|
|
3
|
+
// Every failure a person can see is a StickerError with a code from CODES.
|
|
4
|
+
// The panel API answers `{ error, code, ...details }` with the status below and
|
|
5
|
+
// the dashboard translates the code; a bot command replies with userMessage(),
|
|
6
|
+
// which goes through tr() so it follows the reply language of the message.
|
|
7
|
+
// Internal detail (ffmpeg stderr, paths) belongs in `cause` and the log, never
|
|
8
|
+
// in `message` or `details`.
|
|
9
|
+
|
|
10
|
+
const { tr } = require("../utils/i18n.cjs");
|
|
11
|
+
|
|
12
|
+
const CODES = Object.freeze({
|
|
13
|
+
NO_MEDIA: "NO_MEDIA",
|
|
14
|
+
UNSUPPORTED_TYPE: "UNSUPPORTED_TYPE",
|
|
15
|
+
TOO_LARGE: "TOO_LARGE",
|
|
16
|
+
DIMENSIONS_TOO_LARGE: "DIMENSIONS_TOO_LARGE",
|
|
17
|
+
VIDEO_TOO_LONG: "VIDEO_TOO_LONG",
|
|
18
|
+
CORRUPT: "CORRUPT",
|
|
19
|
+
CONVERSION_FAILED: "CONVERSION_FAILED",
|
|
20
|
+
OUTPUT_TOO_LARGE: "OUTPUT_TOO_LARGE",
|
|
21
|
+
ENCODER_MISSING: "ENCODER_MISSING",
|
|
22
|
+
TIMEOUT: "TIMEOUT",
|
|
23
|
+
BUSY: "BUSY",
|
|
24
|
+
NOT_FOUND: "NOT_FOUND",
|
|
25
|
+
PACK_NOT_FOUND: "PACK_NOT_FOUND",
|
|
26
|
+
PACK_EXISTS: "PACK_EXISTS",
|
|
27
|
+
INVALID_NAME: "INVALID_NAME",
|
|
28
|
+
INVALID_OPTIONS: "INVALID_OPTIONS",
|
|
29
|
+
LIBRARY_FULL: "LIBRARY_FULL",
|
|
30
|
+
PACK_LIMIT: "PACK_LIMIT",
|
|
31
|
+
IN_USE: "IN_USE",
|
|
32
|
+
STORAGE_UNAVAILABLE: "STORAGE_UNAVAILABLE",
|
|
33
|
+
NOT_CONNECTED: "NOT_CONNECTED",
|
|
34
|
+
CANCELLED: "CANCELLED",
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
const HTTP_STATUS = Object.freeze({
|
|
38
|
+
NO_MEDIA: 400,
|
|
39
|
+
UNSUPPORTED_TYPE: 415,
|
|
40
|
+
TOO_LARGE: 413,
|
|
41
|
+
DIMENSIONS_TOO_LARGE: 413,
|
|
42
|
+
VIDEO_TOO_LONG: 422,
|
|
43
|
+
CORRUPT: 422,
|
|
44
|
+
CONVERSION_FAILED: 422,
|
|
45
|
+
OUTPUT_TOO_LARGE: 422,
|
|
46
|
+
ENCODER_MISSING: 501,
|
|
47
|
+
TIMEOUT: 504,
|
|
48
|
+
BUSY: 429,
|
|
49
|
+
NOT_FOUND: 404,
|
|
50
|
+
PACK_NOT_FOUND: 404,
|
|
51
|
+
PACK_EXISTS: 409,
|
|
52
|
+
INVALID_NAME: 400,
|
|
53
|
+
INVALID_OPTIONS: 400,
|
|
54
|
+
LIBRARY_FULL: 409,
|
|
55
|
+
PACK_LIMIT: 409,
|
|
56
|
+
IN_USE: 409,
|
|
57
|
+
STORAGE_UNAVAILABLE: 503,
|
|
58
|
+
NOT_CONNECTED: 503,
|
|
59
|
+
CANCELLED: 409,
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
class StickerError extends Error {
|
|
63
|
+
/**
|
|
64
|
+
* @param {keyof CODES} code
|
|
65
|
+
* @param {object} [details] safe to show: numbers, names, ids — no paths
|
|
66
|
+
* @param {{ cause?: unknown }} [options]
|
|
67
|
+
*/
|
|
68
|
+
constructor(code, details = {}, options = {}) {
|
|
69
|
+
if (!CODES[code]) throw new TypeError(`unknown sticker error code: ${code}`);
|
|
70
|
+
super(code, options.cause === undefined ? undefined : { cause: options.cause });
|
|
71
|
+
this.name = "StickerError";
|
|
72
|
+
this.code = code;
|
|
73
|
+
this.details = details;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function isStickerError(error) {
|
|
78
|
+
return error instanceof StickerError;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function httpStatus(error) {
|
|
82
|
+
return isStickerError(error) ? HTTP_STATUS[error.code] : 500;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** The `{ error, code, ...details }` body the panel API answers with. */
|
|
86
|
+
function toResponseBody(error) {
|
|
87
|
+
if (!isStickerError(error)) return { error: "Sticker operation failed", code: "INTERNAL" };
|
|
88
|
+
return { error: userMessageIn("en", error), code: error.code, ...error.details };
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function userMessageIn(lang, error) {
|
|
92
|
+
const pick = (en, ar) => (lang === "ar" ? ar : en);
|
|
93
|
+
return message(pick, error);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** A reply for the person who sent the command, in the language of that message. */
|
|
97
|
+
function userMessage(error) {
|
|
98
|
+
return message(tr, error);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function message(pick, error) {
|
|
102
|
+
const d = (isStickerError(error) && error.details) || {};
|
|
103
|
+
switch (isStickerError(error) ? error.code : "INTERNAL") {
|
|
104
|
+
case "NO_MEDIA":
|
|
105
|
+
return pick(
|
|
106
|
+
"Send or reply to an image, GIF, video or sticker.",
|
|
107
|
+
"أرسل صورة أو صورة متحركة أو فيديو أو ملصقًا، أو رد على واحد منها.",
|
|
108
|
+
);
|
|
109
|
+
case "UNSUPPORTED_TYPE":
|
|
110
|
+
return pick(
|
|
111
|
+
"That file type can't be made into a sticker. Use a JPEG, PNG, WebP, GIF or MP4/WebM video.",
|
|
112
|
+
"لا يمكن تحويل هذا النوع من الملفات إلى ملصق. استخدم صورة JPEG أو PNG أو WebP أو GIF أو فيديو MP4/WebM.",
|
|
113
|
+
);
|
|
114
|
+
case "TOO_LARGE":
|
|
115
|
+
if (d.limitFrames) {
|
|
116
|
+
return pick(
|
|
117
|
+
`The animation has too many frames (limit ${d.limitFrames}).`,
|
|
118
|
+
`في الرسم المتحرك إطارات كثيرة جدًا (الحد ${d.limitFrames}).`,
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
return pick(
|
|
122
|
+
`The file is too large (limit ${formatMb(d.limitBytes)}).`,
|
|
123
|
+
`الملف كبير جدًا (الحد ${formatMb(d.limitBytes)}).`,
|
|
124
|
+
);
|
|
125
|
+
case "DIMENSIONS_TOO_LARGE":
|
|
126
|
+
return pick(
|
|
127
|
+
`The image is too large (limit ${d.limit || 4096} px per side).`,
|
|
128
|
+
`أبعاد الصورة كبيرة جدًا (الحد ${d.limit || 4096} بكسل لكل ضلع).`,
|
|
129
|
+
);
|
|
130
|
+
case "VIDEO_TOO_LONG":
|
|
131
|
+
return pick(
|
|
132
|
+
`The video is too long (limit ${d.limitSeconds || 10} seconds). Send a shorter clip, or trim it in the panel's Sticker Studio.`,
|
|
133
|
+
`الفيديو طويل جدًا (الحد ${secondsAr(d.limitSeconds || 10)}). أرسل مقطعًا أقصر، أو اقتطع جزءًا منه في استوديو الملصقات في لوحة التحكم.`,
|
|
134
|
+
);
|
|
135
|
+
case "CORRUPT":
|
|
136
|
+
return pick(
|
|
137
|
+
"The file is damaged or incomplete, so it can't be read.",
|
|
138
|
+
"الملف تالف أو غير مكتمل، ولا يمكن قراءته.",
|
|
139
|
+
);
|
|
140
|
+
case "CONVERSION_FAILED":
|
|
141
|
+
return pick(
|
|
142
|
+
"The sticker could not be created from this file.",
|
|
143
|
+
"تعذّر إنشاء ملصق من هذا الملف.",
|
|
144
|
+
);
|
|
145
|
+
case "OUTPUT_TOO_LARGE":
|
|
146
|
+
return pick(
|
|
147
|
+
"Even at the lowest quality the sticker is over WhatsApp's size limit. Try a shorter or simpler clip.",
|
|
148
|
+
"حجم الملصق يتجاوز حد واتساب حتى بأقل جودة. جرّب مقطعًا أقصر أو أبسط.",
|
|
149
|
+
);
|
|
150
|
+
case "ENCODER_MISSING":
|
|
151
|
+
return pick(
|
|
152
|
+
"This Levix build can't encode stickers (its FFmpeg has no WebP encoder). Update Levix.",
|
|
153
|
+
"لا يستطيع إصدار Levix هذا ترميز الملصقات (أداة FFmpeg فيه بلا مرمّز WebP). حدّث Levix.",
|
|
154
|
+
);
|
|
155
|
+
case "TIMEOUT":
|
|
156
|
+
return pick(
|
|
157
|
+
"The conversion took too long and was stopped.",
|
|
158
|
+
"استغرق التحويل وقتًا طويلًا فأُوقف.",
|
|
159
|
+
);
|
|
160
|
+
case "BUSY":
|
|
161
|
+
return pick(
|
|
162
|
+
"Levix is converting other stickers right now. Try again in a moment.",
|
|
163
|
+
"يحوّل Levix ملصقات أخرى الآن. حاول مرة أخرى بعد قليل.",
|
|
164
|
+
);
|
|
165
|
+
case "NOT_FOUND":
|
|
166
|
+
return pick("That sticker is not in your library.", "هذا الملصق غير موجود في مكتبتك.");
|
|
167
|
+
case "PACK_NOT_FOUND":
|
|
168
|
+
return pick(
|
|
169
|
+
`There is no pack named "${d.name || ""}".`,
|
|
170
|
+
`لا توجد حزمة باسم "${d.name || ""}".`,
|
|
171
|
+
);
|
|
172
|
+
case "PACK_EXISTS":
|
|
173
|
+
return pick(
|
|
174
|
+
`A pack named "${d.name || ""}" already exists.`,
|
|
175
|
+
`توجد حزمة باسم "${d.name || ""}" بالفعل.`,
|
|
176
|
+
);
|
|
177
|
+
case "INVALID_NAME":
|
|
178
|
+
return pick(
|
|
179
|
+
"Pack names are 1–40 letters, digits, spaces, - or _, and can't be a command word.",
|
|
180
|
+
"اسم الحزمة من 1 إلى 40 حرفًا أو رقمًا أو مسافة أو - أو _، ولا يجوز أن يكون كلمة أمر.",
|
|
181
|
+
);
|
|
182
|
+
case "INVALID_OPTIONS":
|
|
183
|
+
return pick("Those sticker options are not valid.", "خيارات الملصق هذه غير صالحة.");
|
|
184
|
+
case "LIBRARY_FULL":
|
|
185
|
+
return pick(
|
|
186
|
+
`Your sticker library is full (${d.limit || 0} stickers). Delete some first.`,
|
|
187
|
+
`مكتبة ملصقاتك ممتلئة (${d.limit || 0} ملصق). احذف بعضها أولًا.`,
|
|
188
|
+
);
|
|
189
|
+
case "PACK_LIMIT":
|
|
190
|
+
return pick(
|
|
191
|
+
`You can have at most ${d.limit || 0} packs.`,
|
|
192
|
+
`الحد الأقصى لعدد الحزم ${d.limit || 0}.`,
|
|
193
|
+
);
|
|
194
|
+
case "IN_USE":
|
|
195
|
+
return pick(
|
|
196
|
+
"This sticker is in one or more packs. Confirm to delete it everywhere.",
|
|
197
|
+
"هذا الملصق موجود في حزمة أو أكثر. أكّد لحذفه من كل مكان.",
|
|
198
|
+
);
|
|
199
|
+
case "STORAGE_UNAVAILABLE":
|
|
200
|
+
return pick(
|
|
201
|
+
"The sticker library can't be written right now.",
|
|
202
|
+
"لا يمكن الكتابة في مكتبة الملصقات الآن.",
|
|
203
|
+
);
|
|
204
|
+
case "NOT_CONNECTED":
|
|
205
|
+
return pick(
|
|
206
|
+
"WhatsApp is not connected, so nothing can be sent.",
|
|
207
|
+
"واتساب غير متصل، فلا يمكن إرسال شيء.",
|
|
208
|
+
);
|
|
209
|
+
case "CANCELLED":
|
|
210
|
+
return pick("The conversion was cancelled.", "أُلغي التحويل.");
|
|
211
|
+
default:
|
|
212
|
+
return pick("Something went wrong with the sticker.", "حدث خطأ في الملصق.");
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
// Arabic counts agree with the number: 3–10 take the plural, 11 and up the
|
|
217
|
+
// singular accusative.
|
|
218
|
+
function secondsAr(n) {
|
|
219
|
+
if (n === 1) return "ثانية واحدة";
|
|
220
|
+
if (n === 2) return "ثانيتان";
|
|
221
|
+
if (n >= 3 && n <= 10) return `${n} ثوانٍ`;
|
|
222
|
+
return `${n} ثانية`;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
function formatMb(bytes) {
|
|
226
|
+
const mb = Number(bytes) / (1024 * 1024);
|
|
227
|
+
return Number.isFinite(mb) && mb > 0 ? `${Math.round(mb)} MB` : "16 MB";
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
module.exports = {
|
|
231
|
+
CODES,
|
|
232
|
+
HTTP_STATUS,
|
|
233
|
+
StickerError,
|
|
234
|
+
isStickerError,
|
|
235
|
+
httpStatus,
|
|
236
|
+
toResponseBody,
|
|
237
|
+
userMessage,
|
|
238
|
+
userMessageIn,
|
|
239
|
+
};
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
// Sticker Studio's single FFmpeg runner. Forced demuxers and a file/pipe
|
|
2
|
+
// protocol whitelist prevent a crafted input from opening playlists or URLs.
|
|
3
|
+
const { spawn } = require("node:child_process");
|
|
4
|
+
const path = require("node:path");
|
|
5
|
+
const { ffmpegPath } = require("../utils/thumbnail.cjs");
|
|
6
|
+
const { StickerError } = require("./errors.cjs");
|
|
7
|
+
const { FFMPEG_STEP_TIMEOUT_MS } = require("./limits.cjs");
|
|
8
|
+
|
|
9
|
+
const DEMUXERS = new Set([
|
|
10
|
+
"png_pipe",
|
|
11
|
+
"jpeg_pipe",
|
|
12
|
+
"gif",
|
|
13
|
+
"webp_pipe",
|
|
14
|
+
"mov",
|
|
15
|
+
"matroska",
|
|
16
|
+
"rawvideo",
|
|
17
|
+
]);
|
|
18
|
+
|
|
19
|
+
function validateInputs(args) {
|
|
20
|
+
if (!Array.isArray(args) || args.some((arg) => typeof arg !== "string")) {
|
|
21
|
+
throw new TypeError("FFmpeg arguments must be strings");
|
|
22
|
+
}
|
|
23
|
+
let start = 0;
|
|
24
|
+
for (let i = 0; i < args.length; i++) {
|
|
25
|
+
if (args[i] !== "-i") continue;
|
|
26
|
+
const prefix = args.slice(start, i);
|
|
27
|
+
const f = prefix.lastIndexOf("-f");
|
|
28
|
+
const whitelist = prefix.lastIndexOf("-protocol_whitelist");
|
|
29
|
+
if (
|
|
30
|
+
f < 0 ||
|
|
31
|
+
!DEMUXERS.has(prefix[f + 1]) ||
|
|
32
|
+
whitelist < 0 ||
|
|
33
|
+
prefix[whitelist + 1] !== "file,pipe" ||
|
|
34
|
+
!(args[i + 1] === "pipe:0" || path.isAbsolute(args[i + 1] || ""))
|
|
35
|
+
) {
|
|
36
|
+
throw new StickerError("CONVERSION_FAILED");
|
|
37
|
+
}
|
|
38
|
+
start = i + 2;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function run(
|
|
43
|
+
args,
|
|
44
|
+
{
|
|
45
|
+
input,
|
|
46
|
+
signal,
|
|
47
|
+
maxOutputBytes = 32 * 1024 * 1024,
|
|
48
|
+
timeoutMs = FFMPEG_STEP_TIMEOUT_MS,
|
|
49
|
+
probe = false,
|
|
50
|
+
} = {},
|
|
51
|
+
) {
|
|
52
|
+
validateInputs(args);
|
|
53
|
+
return new Promise((resolve, reject) => {
|
|
54
|
+
if (signal?.aborted) return reject(new StickerError("TIMEOUT"));
|
|
55
|
+
const argv = [
|
|
56
|
+
"-hide_banner",
|
|
57
|
+
"-nostdin",
|
|
58
|
+
"-loglevel",
|
|
59
|
+
"error",
|
|
60
|
+
...(probe ? ["-loglevel", "info"] : []),
|
|
61
|
+
...args,
|
|
62
|
+
];
|
|
63
|
+
let child;
|
|
64
|
+
try {
|
|
65
|
+
child = spawn(ffmpegPath(), argv, { stdio: ["pipe", "pipe", "pipe"] });
|
|
66
|
+
} catch (cause) {
|
|
67
|
+
reject(new StickerError("CONVERSION_FAILED", {}, { cause }));
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
let total = 0;
|
|
71
|
+
let stderr = "";
|
|
72
|
+
let settled = false;
|
|
73
|
+
let timedOut = false;
|
|
74
|
+
let overflow = false;
|
|
75
|
+
let sourceError = null;
|
|
76
|
+
const pieces = [];
|
|
77
|
+
const abort = () => {
|
|
78
|
+
timedOut = true;
|
|
79
|
+
child.kill("SIGKILL");
|
|
80
|
+
};
|
|
81
|
+
signal?.addEventListener("abort", abort, { once: true });
|
|
82
|
+
const timer = setTimeout(abort, timeoutMs);
|
|
83
|
+
child.stdout.on("data", (part) => {
|
|
84
|
+
total += part.length;
|
|
85
|
+
if (total > maxOutputBytes) {
|
|
86
|
+
overflow = true;
|
|
87
|
+
child.kill("SIGKILL");
|
|
88
|
+
} else pieces.push(part);
|
|
89
|
+
});
|
|
90
|
+
child.stderr.on("data", (part) => {
|
|
91
|
+
stderr = (stderr + part.toString()).slice(-4096);
|
|
92
|
+
});
|
|
93
|
+
child.on("error", (cause) => {
|
|
94
|
+
if (settled) return;
|
|
95
|
+
settled = true;
|
|
96
|
+
clearTimeout(timer);
|
|
97
|
+
signal?.removeEventListener("abort", abort);
|
|
98
|
+
input?.destroy?.();
|
|
99
|
+
reject(new StickerError("CONVERSION_FAILED", {}, { cause }));
|
|
100
|
+
});
|
|
101
|
+
child.on("close", (code) => {
|
|
102
|
+
if (settled) return;
|
|
103
|
+
settled = true;
|
|
104
|
+
clearTimeout(timer);
|
|
105
|
+
signal?.removeEventListener("abort", abort);
|
|
106
|
+
input?.destroy?.();
|
|
107
|
+
if (sourceError) {
|
|
108
|
+
reject(
|
|
109
|
+
sourceError instanceof StickerError
|
|
110
|
+
? sourceError
|
|
111
|
+
: new StickerError("CONVERSION_FAILED", {}, { cause: sourceError }),
|
|
112
|
+
);
|
|
113
|
+
} else if (timedOut) {
|
|
114
|
+
reject(new StickerError("TIMEOUT"));
|
|
115
|
+
} else if (overflow || code !== 0) {
|
|
116
|
+
reject(new StickerError("CONVERSION_FAILED", {}, { cause: stderr }));
|
|
117
|
+
} else {
|
|
118
|
+
resolve({ buffer: Buffer.concat(pieces), stderr });
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
if (Buffer.isBuffer(input)) child.stdin.end(input);
|
|
122
|
+
else if (input) {
|
|
123
|
+
input.on("error", (error) => {
|
|
124
|
+
sourceError = error;
|
|
125
|
+
child.kill("SIGKILL");
|
|
126
|
+
});
|
|
127
|
+
input.pipe(child.stdin);
|
|
128
|
+
} else child.stdin.end();
|
|
129
|
+
child.stdin.on("error", () => {});
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
module.exports = { run };
|