levix-bot 4.1.0 → 4.2.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.
Files changed (82) hide show
  1. package/package.json +1 -1
  2. package/public/dashboard/assets/{index-DngAcp-o.js → index-4AuqfnH5.js} +80 -80
  3. package/public/dashboard/index.html +1 -1
  4. package/scheduler.cjs +6 -1
  5. package/src/commands/autoschedule.cjs +40 -10
  6. package/src/commands/blacklist.cjs +35 -10
  7. package/src/commands/block.cjs +18 -5
  8. package/src/commands/calc.cjs +90 -24
  9. package/src/commands/debt.cjs +59 -33
  10. package/src/commands/deleteschedule.cjs +21 -5
  11. package/src/commands/digit.cjs +34 -8
  12. package/src/commands/gemini.cjs +217 -87
  13. package/src/commands/group/add.cjs +46 -13
  14. package/src/commands/group/all.cjs +15 -5
  15. package/src/commands/group/antiSpam.cjs +11 -4
  16. package/src/commands/group/antilink.cjs +36 -18
  17. package/src/commands/group/approveall.cjs +22 -7
  18. package/src/commands/group/clearwarns.cjs +18 -5
  19. package/src/commands/group/deletenote.cjs +18 -5
  20. package/src/commands/group/demote.cjs +25 -7
  21. package/src/commands/group/kick.cjs +28 -12
  22. package/src/commands/group/media.cjs +31 -12
  23. package/src/commands/group/members.cjs +21 -6
  24. package/src/commands/group/note.cjs +14 -4
  25. package/src/commands/group/promote.cjs +22 -6
  26. package/src/commands/group/removeall.cjs +13 -3
  27. package/src/commands/group/rules.cjs +20 -5
  28. package/src/commands/group/save.cjs +20 -5
  29. package/src/commands/group/setname.cjs +19 -6
  30. package/src/commands/group/setpp.cjs +21 -6
  31. package/src/commands/group/setrules.cjs +17 -5
  32. package/src/commands/group/setwarn.cjs +23 -7
  33. package/src/commands/group/tagadmins.cjs +16 -6
  34. package/src/commands/group/warn.cjs +35 -15
  35. package/src/commands/group/warns.cjs +33 -13
  36. package/src/commands/group/welcome.cjs +34 -16
  37. package/src/commands/group.cjs +96 -70
  38. package/src/commands/help.cjs +270 -135
  39. package/src/commands/lang.cjs +46 -13
  40. package/src/commands/listschedules.cjs +28 -11
  41. package/src/commands/loop.cjs +43 -9
  42. package/src/commands/memory.cjs +90 -30
  43. package/src/commands/mod.cjs +69 -27
  44. package/src/commands/notes.cjs +15 -5
  45. package/src/commands/perm.cjs +52 -20
  46. package/src/commands/ping.cjs +15 -3
  47. package/src/commands/poll.cjs +40 -9
  48. package/src/commands/prayer.cjs +28 -12
  49. package/src/commands/qr.cjs +20 -5
  50. package/src/commands/rand.cjs +54 -12
  51. package/src/commands/restart.cjs +13 -3
  52. package/src/commands/schedule.cjs +32 -9
  53. package/src/commands/score.cjs +26 -10
  54. package/src/commands/setprefix.cjs +27 -5
  55. package/src/commands/shortlink.cjs +36 -10
  56. package/src/commands/shutdown.cjs +13 -3
  57. package/src/commands/status.cjs +32 -11
  58. package/src/commands/sticker.cjs +34 -7
  59. package/src/commands/stt.cjs +163 -108
  60. package/src/commands/todo.cjs +31 -9
  61. package/src/commands/tts.cjs +25 -7
  62. package/src/commands/unblock.cjs +17 -4
  63. package/src/commands/weather.cjs +55 -17
  64. package/src/config/settings.cjs +1 -1
  65. package/src/handlers/command.handler.js +50 -10
  66. package/src/handlers/group.handler.js +5 -1
  67. package/src/handlers/message.handler.js +9 -0
  68. package/src/middleware/antispam.middleware.js +9 -2
  69. package/src/services/aiAgent.cjs +40 -39
  70. package/src/services/aiProviders.cjs +46 -19
  71. package/src/services/aiRouter.cjs +2 -1
  72. package/src/services/aiTools.cjs +2 -1
  73. package/src/utils/commandDocs.cjs +58 -0
  74. package/src/utils/geminiMedia.cjs +168 -0
  75. package/src/utils/i18n.cjs +113 -0
  76. package/src/utils/markdownParser.cjs +4 -2
  77. package/src/utils/memory.cjs +2 -1
  78. package/src/utils/permissionLevel.cjs +34 -6
  79. package/src/utils/providerUrl.cjs +29 -2
  80. package/src/utils/sendBotMessage.cjs +7 -3
  81. package/src/utils/sendBotMessage.esm.js +13 -3
  82. package/src/utils/statusMessage.cjs +11 -4
@@ -10,7 +10,7 @@
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-DngAcp-o.js"></script>
13
+ <script type="module" crossorigin src="/dashboard/assets/index-4AuqfnH5.js"></script>
14
14
  <link rel="stylesheet" crossorigin href="/dashboard/assets/index-LvfJ8ybs.css">
15
15
  </head>
16
16
  <body>
package/scheduler.cjs CHANGED
@@ -7,6 +7,7 @@ const logger = require("./src/utils/logger.cjs");
7
7
  const settings = require("./src/config/settings.cjs");
8
8
  const { ensureDataDir } = require("./src/config/paths.cjs");
9
9
  const storage = require("./src/utils/storage.cjs");
10
+ const { detectLang, withLang, tr } = require("./src/utils/i18n.cjs");
10
11
 
11
12
  // الجدولة كانت في config/schedule.json: الداشبورد مش شايفاه، وكراش وسط
12
13
  // الكتابة كان ممكن يقصّه. دلوقتي جدول في نفس قاعدة البيانات زي أي حاجة تانية.
@@ -161,7 +162,11 @@ async function deliverScheduledJob(sock, job) {
161
162
 
162
163
  try {
163
164
  await sock.sendMessage(job.targetJid, {
164
- text: `*رسالة مجدولة 🗓️*\n\n${job.message}`,
165
+ // No message is being answered here, so the header follows the scheduled
166
+ // text itself (in "auto"), or the bot's language.
167
+ text: withLang(detectLang(job.message), () =>
168
+ tr(`*Scheduled message 🗓️*\n\n${job.message}`, `*رسالة مجدولة 🗓️*\n\n${job.message}`),
169
+ ),
165
170
  });
166
171
  recordDelivery(job.id, "sent", runAt);
167
172
  logger.info(`[Scheduler] Executed job ${job.id} -> ${job.targetJid}`);
@@ -2,11 +2,18 @@ const { scheduleNewJob, saveScheduledJob } = require("../../scheduler.cjs");
2
2
  const { randomUUID } = require("node:crypto");
3
3
  const { defaultTimezone } = require("../utils/datetime.cjs");
4
4
  const { parseRecurringArgs } = require("../utils/recurrence.cjs");
5
+ const { tr } = require("../utils/i18n.cjs");
5
6
 
6
7
  module.exports = {
7
8
  name: "autoschedule",
8
- description: "Schedules a recurring message (daily, weekly).",
9
- usage: "autoschedule daily <HH:mm> <الرسالة>\nautoschedule weekly <اليوم> <HH:mm> <الرسالة>",
9
+ description: {
10
+ en: "Schedules a recurring message (daily or weekly).",
11
+ ar: "يجدول رسالة متكررة (يومية أو أسبوعية).",
12
+ },
13
+ usage: {
14
+ en: "autoschedule daily <HH:mm> <message>\nautoschedule weekly <day> <HH:mm> <message>",
15
+ ar: "autoschedule daily <HH:mm> <الرسالة>\nautoschedule weekly <اليوم> <HH:mm> <الرسالة>",
16
+ },
10
17
  chat: "all",
11
18
 
12
19
  async execute(sock, msg, args) {
@@ -16,12 +23,26 @@ module.exports = {
16
23
 
17
24
  if (parsed.error) {
18
25
  const errors = {
19
- usage:
26
+ usage: tr(
27
+ "Wrong format. Use:\n`!autoschedule daily HH:mm your message`\n`!autoschedule weekly day HH:mm your message`",
20
28
  "الصيغة غير صحيحة. استخدم:\n`!autoschedule daily HH:mm رسالتك`\n`!autoschedule weekly day HH:mm رسالتك`",
21
- type: "النوع غير مدعوم. استخدم: `daily` أو `weekly`.",
22
- day: "اليوم غير صالح. استخدم اسم اليوم بالعربية أو الإنجليزية، أو رقمًا من 0 إلى 7 (0 و7 للأحد).",
23
- time: "الوقت غير صالح. استخدم صيغة `HH:mm` (مثال: `09:30`).",
24
- message: "اكتب الرسالة التي تريد جدولتها بعد الوقت.",
29
+ ),
30
+ type: tr(
31
+ "Unsupported type. Use `daily` or `weekly`.",
32
+ "النوع غير مدعوم. استخدم: `daily` أو `weekly`.",
33
+ ),
34
+ day: tr(
35
+ "Invalid day. Use the day's name in English or Arabic, or a number from 0 to 7 (0 and 7 are Sunday).",
36
+ "اليوم غير صالح. استخدم اسم اليوم بالعربية أو الإنجليزية، أو رقمًا من 0 إلى 7 (0 و7 للأحد).",
37
+ ),
38
+ time: tr(
39
+ "Invalid time. Use `HH:mm` (for example `09:30`).",
40
+ "الوقت غير صالح. استخدم صيغة `HH:mm` (مثال: `09:30`).",
41
+ ),
42
+ message: tr(
43
+ "Write the message you want to schedule after the time.",
44
+ "اكتب الرسالة التي تريد جدولتها بعد الوقت.",
45
+ ),
25
46
  };
26
47
  return await sock.sendMessage(creatorJid, {
27
48
  text: errors[parsed.error],
@@ -41,7 +62,10 @@ module.exports = {
41
62
  // الجدولة الأول: جوب مش قادرين نجدوله ما يتخزّنش في الملف أصلاً.
42
63
  if (!scheduleNewJob(sock, newJob)) {
43
64
  return await sock.sendMessage(creatorJid, {
44
- text: "معرفتش أجدول الرسالة دي. راجع الوقت وجرب تاني.",
65
+ text: tr(
66
+ "I couldn't schedule that message. Check the time and try again.",
67
+ "معرفتش أجدول الرسالة دي. راجع الوقت وجرب تاني.",
68
+ ),
45
69
  });
46
70
  }
47
71
 
@@ -50,8 +74,14 @@ module.exports = {
50
74
  await sock.sendMessage(creatorJid, {
51
75
  text:
52
76
  parsed.type === "weekly"
53
- ? `✅ تم جدولة الرسالة أسبوعيًا يوم ${args[1]} الساعة ${parsed.time} (${defaultTimezone()})`
54
- : `✅ تم جدولة الرسالة يوميًا الساعة ${parsed.time} (${defaultTimezone()})`,
77
+ ? tr(
78
+ `✅ Scheduled weekly on ${args[1]} at ${parsed.time} (${defaultTimezone()})`,
79
+ `✅ تم جدولة الرسالة أسبوعيًا يوم ${args[1]} الساعة ${parsed.time} (${defaultTimezone()})`,
80
+ )
81
+ : tr(
82
+ `✅ Scheduled daily at ${parsed.time} (${defaultTimezone()})`,
83
+ `✅ تم جدولة الرسالة يوميًا الساعة ${parsed.time} (${defaultTimezone()})`,
84
+ ),
55
85
  });
56
86
  },
57
87
  };
@@ -3,6 +3,7 @@ const { getGroupSettings, saveGroupSettings } = require("../utils/storage.cjs");
3
3
  const logger = require("../utils/logger.cjs");
4
4
  const normalizeJid = require("../utils/normalizeJid.esm.js").default;
5
5
  const { isAdminInGroupSync, sameUserSync } = require("../utils/permissions.cjs");
6
+ const { tr } = require("../utils/i18n.cjs");
6
7
 
7
8
  function sameIdentity(a, b) {
8
9
  return normalizeJid(a) === normalizeJid(b) || sameUserSync(a, b);
@@ -11,8 +12,14 @@ function sameIdentity(a, b) {
11
12
  module.exports = {
12
13
  name: "blacklist",
13
14
  aliases: ["unblacklist", "block", "unblock"], // We keep aliases here for a reason
14
- description: "Manages the group's user blacklist.",
15
- usage: "blacklist [add|remove|list] [@عضو|رقم]",
15
+ description: {
16
+ en: "Manages the group's user blacklist.",
17
+ ar: "يدير القائمة السوداء لأعضاء المجموعة.",
18
+ },
19
+ usage: {
20
+ en: "blacklist [add|remove|list] [@member|number]",
21
+ ar: "blacklist [add|remove|list] [@عضو|رقم]",
22
+ },
16
23
  chat: "group",
17
24
  userAdminRequired: true,
18
25
 
@@ -44,10 +51,13 @@ module.exports = {
44
51
  if (action === "list") {
45
52
  if (settings.blacklist.length === 0)
46
53
  return await sock.sendMessage(groupId, {
47
- text: "القائمة السوداء فارغة حاليًا.",
54
+ text: tr("The blacklist is empty.", "القائمة السوداء فارغة حاليًا."),
48
55
  });
49
56
 
50
- let listReply = "*🚫 قائمة المستخدمين المحظورين من البوت:*\n\n";
57
+ let listReply = tr(
58
+ "*🚫 Users blocked from the bot:*\n\n",
59
+ "*🚫 قائمة المستخدمين المحظورين من البوت:*\n\n",
60
+ );
51
61
  settings.blacklist.forEach((jid) => {
52
62
  listReply += `» @${jid.split("@")[0]}\n`;
53
63
  });
@@ -64,7 +74,10 @@ module.exports = {
64
74
 
65
75
  if (!targetJid)
66
76
  return await sock.sendMessage(groupId, {
67
- text: `لتنفيذ هذا الإجراء، قم بعمل منشن للعضو أو كتابة رقمه.`,
77
+ text: tr(
78
+ "Mention the member or type their number to do that.",
79
+ "لتنفيذ هذا الإجراء، قم بعمل منشن للعضو أو كتابة رقمه.",
80
+ ),
68
81
  });
69
82
 
70
83
  const normalizedTargetJid = normalizeJid(targetJid);
@@ -81,23 +94,32 @@ module.exports = {
81
94
  );
82
95
  if (targetIsAdmin)
83
96
  return await sock.sendMessage(groupId, {
84
- text: "لا يمكن حظر المشرفين.",
97
+ text: tr("Admins can't be blacklisted.", "لا يمكن حظر المشرفين."),
85
98
  });
86
99
  if (settings.blacklist.some((jid) => sameIdentity(jid, normalizedTargetJid)))
87
100
  return await sock.sendMessage(groupId, {
88
- text: `العضو @${normalizedTargetJid.split("@")[0]} محظور بالفعل.`,
101
+ text: tr(
102
+ `@${normalizedTargetJid.split("@")[0]} is already blacklisted.`,
103
+ `العضو @${normalizedTargetJid.split("@")[0]} محظور بالفعل.`,
104
+ ),
89
105
  mentions: [normalizedTargetJid],
90
106
  });
91
107
 
92
108
  settings.blacklist.push(normalizedTargetJid);
93
109
  await sock.sendMessage(groupId, {
94
- text: `🚫 تم إضافة @${normalizedTargetJid.split("@")[0]} إلى القائمة السوداء بنجاح.`,
110
+ text: tr(
111
+ `🚫 @${normalizedTargetJid.split("@")[0]} was added to the blacklist.`,
112
+ `🚫 تم إضافة @${normalizedTargetJid.split("@")[0]} إلى القائمة السوداء بنجاح.`,
113
+ ),
95
114
  mentions: [normalizedTargetJid],
96
115
  });
97
116
  } else if (action === "remove") {
98
117
  if (!settings.blacklist.some((jid) => sameIdentity(jid, normalizedTargetJid)))
99
118
  return await sock.sendMessage(groupId, {
100
- text: `العضو @${normalizedTargetJid.split("@")[0]} ليس في القائمة السوداء أصلاً.`,
119
+ text: tr(
120
+ `@${normalizedTargetJid.split("@")[0]} isn't on the blacklist.`,
121
+ `العضو @${normalizedTargetJid.split("@")[0]} ليس في القائمة السوداء أصلاً.`,
122
+ ),
101
123
  mentions: [normalizedTargetJid],
102
124
  });
103
125
 
@@ -105,7 +127,10 @@ module.exports = {
105
127
  (jid) => !sameIdentity(jid, normalizedTargetJid),
106
128
  );
107
129
  await sock.sendMessage(groupId, {
108
- text: `✅ تم إزالة @${normalizedTargetJid.split("@")[0]} من القائمة السوداء.`,
130
+ text: tr(
131
+ `✅ @${normalizedTargetJid.split("@")[0]} was removed from the blacklist.`,
132
+ `✅ تم إزالة @${normalizedTargetJid.split("@")[0]} من القائمة السوداء.`,
133
+ ),
109
134
  mentions: [normalizedTargetJid],
110
135
  });
111
136
  }
@@ -2,11 +2,18 @@
2
2
  const logger = require("../utils/logger.cjs");
3
3
  const { isOwnerJidSync } = require("../utils/permissions.cjs");
4
4
  const normalizeJid = require("../utils/normalizeJid.esm.js");
5
+ const { tr } = require("../utils/i18n.cjs");
5
6
 
6
7
  module.exports = {
7
8
  name: "block",
8
- description: "Blocks a user from contacting the bot on WhatsApp.",
9
- usage: "block [@عضو|رقم] (أو رد على رسالته)",
9
+ description: {
10
+ en: "Blocks a user from contacting the bot on WhatsApp.",
11
+ ar: "يحظر مستخدمًا من التواصل مع البوت على واتساب.",
12
+ },
13
+ usage: {
14
+ en: "block [@member|number] (or reply to their message)",
15
+ ar: "block [@عضو|رقم] (أو رد على رسالته)",
16
+ },
10
17
  chat: "all",
11
18
 
12
19
  async execute(sock, msg, args) {
@@ -33,7 +40,10 @@ module.exports = {
33
40
  targetJid = `${numberArg.replace(/\D/g, "")}@s.whatsapp.net`;
34
41
  } else {
35
42
  return await sock.sendMessage(remoteJid, {
36
- text: "لكي يعمل هذا الأمر، استخدمه في شات خاص بدون وسائط، أو قم بعمل منشن/رد/كتابة رقم المستخدم.",
43
+ text: tr(
44
+ "Use this in a private chat with no arguments, or mention / reply to / type the number of the user.",
45
+ "لكي يعمل هذا الأمر، استخدمه في شات خاص بدون وسائط، أو قم بعمل منشن/رد/كتابة رقم المستخدم.",
46
+ ),
37
47
  });
38
48
  }
39
49
  }
@@ -43,7 +53,7 @@ module.exports = {
43
53
  // Safety Check
44
54
  if (isOwnerJidSync(normalizedTargetJid)) {
45
55
  return await sock.sendMessage(remoteJid, {
46
- text: "لا يمكنك حظر مالك البوت.",
56
+ text: tr("You can't block the bot owner.", "لا يمكنك حظر مالك البوت."),
47
57
  });
48
58
  }
49
59
 
@@ -61,7 +71,10 @@ module.exports = {
61
71
  } catch (error) {
62
72
  logger.error({ err: error, command: "block" }, "Error in !block command");
63
73
  await sock.sendMessage(remoteJid, {
64
- text: "حدث خطأ أثناء محاولة حظر المستخدم.",
74
+ text: tr(
75
+ "Something went wrong while blocking the user.",
76
+ "حدث خطأ أثناء محاولة حظر المستخدم.",
77
+ ),
65
78
  });
66
79
  }
67
80
  },
@@ -10,6 +10,7 @@
10
10
  // FUNCTIONS.
11
11
 
12
12
  const { sendBotMessage } = require("../utils/sendBotMessage.cjs");
13
+ const { tr } = require("../utils/i18n.cjs");
13
14
 
14
15
  // ---------------------------------------------------------------------------
15
16
  // whitelist
@@ -59,8 +60,12 @@ const FUNCTIONS = {
59
60
  };
60
61
 
61
62
  function factorial(n) {
62
- if (!Number.isInteger(n)) throw new CalcError("المضروب (!) يشتغل على أرقام صحيحة بس");
63
- if (n < 0) throw new CalcError("مفيش مضروب لرقم سالب");
63
+ if (!Number.isInteger(n)) {
64
+ throw new CalcError(
65
+ tr("Factorial (!) only works on whole numbers", "المضروب (!) يشتغل على أرقام صحيحة بس"),
66
+ );
67
+ }
68
+ if (n < 0) throw new CalcError(tr("Negative numbers have no factorial", "مفيش مضروب لرقم سالب"));
64
69
  if (n > 170) return Infinity; // beyond this a double is Infinity anyway
65
70
  let result = 1;
66
71
  for (let i = 2; i <= n; i++) result *= i;
@@ -129,7 +134,9 @@ function tokenize(text) {
129
134
  while (i < text.length && /[0-9]/.test(text[i])) raw += text[i++];
130
135
  }
131
136
  const value = Number(raw);
132
- if (!Number.isFinite(value)) throw new CalcError(`رقم غير صالح: \`${raw}\``);
137
+ if (!Number.isFinite(value)) {
138
+ throw new CalcError(tr(`Invalid number: \`${raw}\``, `رقم غير صالح: \`${raw}\``));
139
+ }
133
140
  tokens.push({ type: "num", value });
134
141
  continue;
135
142
  }
@@ -147,7 +154,7 @@ function tokenize(text) {
147
154
  continue;
148
155
  }
149
156
 
150
- throw new CalcError(`رمز مش مفهوم: \`${char}\``);
157
+ throw new CalcError(tr(`Unknown symbol: \`${char}\``, `رمز مش مفهوم: \`${char}\``));
151
158
  }
152
159
 
153
160
  return tokens;
@@ -191,13 +198,17 @@ function parse(tokens) {
191
198
  left *= parseUnary();
192
199
  } else if (eat("/")) {
193
200
  const right = parseUnary();
194
- if (right === 0) throw new CalcError("القسمة على صفر ملهاش لازمة 😅");
201
+ if (right === 0) {
202
+ throw new CalcError(tr("Division by zero isn't defined 😅", "القسمة على صفر ملهاش لازمة 😅"));
203
+ }
195
204
  left /= right;
196
205
  } else if (peek()?.type === "%" && startsValue(peek(1))) {
197
206
  // infix `%` is modulo; the postfix «15%» form is handled in parsePostfix
198
207
  pos++;
199
208
  const right = parseUnary();
200
- if (right === 0) throw new CalcError("باقي القسمة على صفر مش معرّف");
209
+ if (right === 0) {
210
+ throw new CalcError(tr("Modulo by zero isn't defined", "باقي القسمة على صفر مش معرّف"));
211
+ }
201
212
  left %= right;
202
213
  } else if (startsValue(peek())) {
203
214
  // implicit multiplication: 2(3+4), 3pi, 2sqrt(9)
@@ -236,11 +247,11 @@ function parse(tokens) {
236
247
 
237
248
  function parsePrimary() {
238
249
  const token = peek();
239
- if (!token) throw new CalcError("المعادلة ناقصة");
250
+ if (!token) throw new CalcError(tr("The expression is incomplete", "المعادلة ناقصة"));
240
251
 
241
252
  if (eat("(")) {
242
253
  const value = parseExpression();
243
- expect(")", "قوس مفتوح ومقفلش");
254
+ expect(")", tr("A bracket was opened and never closed", "قوس مفتوح ومقفلش"));
244
255
  return value;
245
256
  }
246
257
 
@@ -255,43 +266,64 @@ function parse(tokens) {
255
266
 
256
267
  if (FUNCTIONS[name]) {
257
268
  const spec = FUNCTIONS[name];
258
- expect("(", `الدالة \`${name}\` محتاجة أقواس، زي \`${name}(9)\``);
269
+ expect(
270
+ "(",
271
+ tr(
272
+ `The function \`${name}\` needs brackets, like \`${name}(9)\``,
273
+ `الدالة \`${name}\` محتاجة أقواس، زي \`${name}(9)\``,
274
+ ),
275
+ );
259
276
  const args = [];
260
277
  if (peek()?.type !== ")") {
261
278
  args.push(parseExpression());
262
279
  while (eat(",")) args.push(parseExpression());
263
280
  }
264
- expect(")", `قوس \`${name}\` مقفلش`);
281
+ expect(")", tr(`The bracket of \`${name}\` is never closed`, `قوس \`${name}\` مقفلش`));
265
282
  if (spec.arity !== -1 && args.length !== spec.arity) {
266
283
  throw new CalcError(
267
- `الدالة \`${name}\` بتاخد ${spec.arity} ${spec.arity === 1 ? "قيمة" : "قيم"}`,
284
+ tr(
285
+ `The function \`${name}\` takes ${spec.arity} ${spec.arity === 1 ? "value" : "values"}`,
286
+ `الدالة \`${name}\` بتاخد ${spec.arity} ${spec.arity === 1 ? "قيمة" : "قيم"}`,
287
+ ),
288
+ );
289
+ }
290
+ if (!args.length) {
291
+ throw new CalcError(
292
+ tr(`The function \`${name}\` got no values`, `الدالة \`${name}\` من غير قيم`),
268
293
  );
269
294
  }
270
- if (!args.length) throw new CalcError(`الدالة \`${name}\` من غير قيم`);
271
295
  return spec.fn(...args);
272
296
  }
273
297
 
274
298
  if (name in CONSTANTS) return CONSTANTS[name];
275
299
 
276
- throw new CalcError(`مش عارف يعني إيه \`${name}\``);
300
+ throw new CalcError(tr(`I don't know what \`${name}\` is`, `مش عارف يعني إيه \`${name}\``));
277
301
  }
278
302
 
279
- throw new CalcError(`مكان غلط للرمز \`${token.type}\``);
303
+ throw new CalcError(
304
+ tr(`\`${token.type}\` is in the wrong place`, `مكان غلط للرمز \`${token.type}\``),
305
+ );
280
306
  }
281
307
 
282
308
  const result = parseExpression();
283
- if (pos < tokens.length) throw new CalcError("في زيادة في آخر المعادلة");
309
+ if (pos < tokens.length) {
310
+ throw new CalcError(
311
+ tr("There is something extra at the end of the expression", "في زيادة في آخر المعادلة"),
312
+ );
313
+ }
284
314
  return result;
285
315
  }
286
316
 
287
317
  function evaluate(expression) {
288
318
  const normalized = normalize(expression);
289
- if (!normalized) throw new CalcError("اكتب معادلة الأول");
290
- if (normalized.length > 300) throw new CalcError("المعادلة طويلة أوي");
319
+ if (!normalized) throw new CalcError(tr("Type an expression first", "اكتب معادلة الأول"));
320
+ if (normalized.length > 300) {
321
+ throw new CalcError(tr("The expression is too long", "المعادلة طويلة أوي"));
322
+ }
291
323
 
292
324
  const value = parse(tokenize(normalized));
293
325
  if (typeof value !== "number" || Number.isNaN(value)) {
294
- throw new CalcError("النتيجة مش رقم صالح");
326
+ throw new CalcError(tr("The result isn't a valid number", "النتيجة مش رقم صالح"));
295
327
  }
296
328
  return { normalized, value };
297
329
  }
@@ -316,7 +348,27 @@ function formatNumber(value) {
316
348
  return fraction ? `${grouped}.${fraction}` : grouped;
317
349
  }
318
350
 
319
- const HELP_TEXT =
351
+ const helpText = () =>
352
+ tr(
353
+ "🧮 *Calculator*\n\n" +
354
+ "*Usage:* `!calc <expression>`\n" +
355
+ "or reply to a message containing an expression with `!calc`\n\n" +
356
+ "*Operators:* `+` `-` `*` `/` `%` (modulo) `^` (power) `!` (factorial)\n" +
357
+ "*Percentages:* `15%` · `20% of 300`\n" +
358
+ "*Constants:* `pi` · `e` · `tau`\n" +
359
+ "*Functions:* sqrt, cbrt, abs, round, floor, ceil, ln, log, log2, exp,\n" +
360
+ "sin, cos, tan, sind, cosd, tand, asin, acos, atan, deg, rad,\n" +
361
+ "pow, root, hypot, min, max, avg, sum, fact\n\n" +
362
+ "*Examples:*\n" +
363
+ "`!calc (12 + 8) * 3`\n" +
364
+ "`!calc 2^10`\n" +
365
+ "`!calc 25% of 480`\n" +
366
+ "`!calc sqrt(144) + 5!`\n" +
367
+ "`!calc max(3, 9, 4) * pi`",
368
+ HELP_TEXT_AR,
369
+ );
370
+
371
+ const HELP_TEXT_AR =
320
372
  "🧮 *الآلة الحاسبة*\n\n" +
321
373
  "*الاستخدام:* `!calc <معادلة>`\n" +
322
374
  "أو رد على رسالة فيها معادلة واكتب `!calc`\n\n" +
@@ -336,8 +388,14 @@ const HELP_TEXT =
336
388
  module.exports = {
337
389
  name: "calc",
338
390
  aliases: ["calculate", "حساب", "احسب", "="],
339
- description: "آلة حاسبة: عمليات حسابية، نِسب، أُسس، ودوال رياضية.",
340
- usage: "calc <معادلة>",
391
+ description: {
392
+ en: "Calculator: arithmetic, percentages, powers and math functions.",
393
+ ar: "آلة حاسبة: عمليات حسابية، ونِسب مئوية، وأُسس، ودوال رياضية.",
394
+ },
395
+ usage: {
396
+ en: "calc <expression>",
397
+ ar: "calc <معادلة>",
398
+ },
341
399
  chat: "all",
342
400
 
343
401
  async execute(sock, msg, args) {
@@ -350,7 +408,7 @@ module.exports = {
350
408
  const expression = args.join(" ").trim() || quotedText.trim();
351
409
 
352
410
  if (!expression) {
353
- return sendBotMessage(sock, chatId, { text: HELP_TEXT }, { replyTo: msg });
411
+ return sendBotMessage(sock, chatId, { text: helpText() }, { replyTo: msg });
354
412
  }
355
413
 
356
414
  try {
@@ -364,11 +422,19 @@ module.exports = {
364
422
  { replyTo: msg },
365
423
  );
366
424
  } catch (error) {
367
- const reason = error instanceof CalcError ? error.message : "المعادلة مش مفهومة";
425
+ const reason =
426
+ error instanceof CalcError
427
+ ? error.message
428
+ : tr("I couldn't understand that expression", "المعادلة مش مفهومة");
368
429
  return sendBotMessage(
369
430
  sock,
370
431
  chatId,
371
- { text: `❌ ${reason}\n\nاكتب \`!calc\` لوحده عشان تشوف الأمثلة.` },
432
+ {
433
+ text: tr(
434
+ `❌ ${reason}\n\nSend \`!calc\` on its own to see examples.`,
435
+ `❌ ${reason}\n\nاكتب \`!calc\` لوحده عشان تشوف الأمثلة.`,
436
+ ),
437
+ },
372
438
  { replyTo: msg },
373
439
  );
374
440
  }