levix-bot 4.1.0 → 4.2.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 (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 +159 -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 +44 -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 +99 -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
@@ -1,10 +1,10 @@
1
1
  // Speech-to-Text Command using FREE Gemini API
2
2
  const { GoogleGenAI } = require("@google/genai");
3
3
  const { downloadContentFromMessage } = require("@whiskeysockets/baileys");
4
- const fs = require("fs").promises;
5
- const path = require("path");
6
4
  const logger = require("../utils/logger.cjs");
7
5
  const { createStatus } = require("../utils/statusMessage.cjs");
6
+ const { unwrapMessage } = require("../utils/messageContent.cjs");
7
+ const { baseMimeType, downloadMedia, uploadToGemini } = require("../utils/geminiMedia.cjs");
8
8
 
9
9
  const settings = require("../config/settings.cjs");
10
10
  const {
@@ -12,6 +12,7 @@ const {
12
12
  assertProviderRequestUrl,
13
13
  safeProviderFetch,
14
14
  } = require("../utils/providerUrl.cjs");
15
+ const { tr } = require("../utils/i18n.cjs");
15
16
 
16
17
  // Built on first use from whatever key is in force, and
17
18
  // rebuilt if that key changes — the operator can paste one without a restart.
@@ -58,9 +59,55 @@ function resolveSttProvider() {
58
59
  : "gemini";
59
60
  }
60
61
 
62
+ const TRANSCRIBE_PROMPT =
63
+ "Please transcribe this audio message accurately. Return ONLY the transcription text without any additional commentary, explanations, or formatting. Just the raw transcribed text.";
64
+
65
+ // A voice note is a few hundred KB, so it rides inline in the request: one
66
+ // round trip, instead of an upload, a finalize and then the request. Past this
67
+ // size (Gemini caps a whole inline request at 20 MB) it goes through the Files
68
+ // API instead.
69
+ const INLINE_AUDIO_LIMIT = 15 * 1024 * 1024;
70
+
71
+ async function transcribeWithGemini(audioBuffer, mimetype) {
72
+ const gemini = geminiStt();
73
+ if (!gemini)
74
+ throw new Error(
75
+ tr("No Gemini key is set in the settings", "مفتاح Gemini غير مضبوط في الإعدادات"),
76
+ );
77
+ await assertProviderRequestUrl(settings.get("gemini_base_url"), {
78
+ allowLoopback: true,
79
+ });
80
+
81
+ // WhatsApp labels voice notes `audio/ogg; codecs=opus`; Gemini's type is
82
+ // `audio/ogg`, and the codec parameter is not part of it.
83
+ const mimeType = baseMimeType(mimetype, "audio");
84
+ let audioPart;
85
+ if (audioBuffer.length <= INLINE_AUDIO_LIMIT) {
86
+ audioPart = { inlineData: { mimeType, data: audioBuffer.toString("base64") } };
87
+ } else {
88
+ const file = await uploadToGemini(gemini.genAI, audioBuffer, mimeType, {
89
+ displayName: `audio-${Date.now()}`,
90
+ });
91
+ audioPart = { fileData: { mimeType: file.mimeType || mimeType, fileUri: file.uri } };
92
+ }
93
+
94
+ const response = await gemini.genAI.models.generateContent({
95
+ model: sttModel(),
96
+ contents: [{ role: "user", parts: [audioPart, { text: TRANSCRIBE_PROMPT }] }],
97
+ });
98
+ return (response.text ?? "").trim();
99
+ }
100
+
61
101
  async function transcribeWithOpenAi(audioBuffer, mimetype) {
62
102
  const apiKey = settings.get("openai_api_key");
63
- if (!apiKey) throw new Error("مفتاح OpenAI / Groq غير مضبوط في الإعدادات");
103
+ if (!apiKey) {
104
+ throw new Error(
105
+ tr(
106
+ "No OpenAI / Groq key is set in the settings",
107
+ "مفتاح OpenAI / Groq غير مضبوط في الإعدادات",
108
+ ),
109
+ );
110
+ }
64
111
  const baseUrl = assertProviderBaseUrl(
65
112
  settings.get("openai_base_url") || "https://api.openai.com/v1",
66
113
  { allowLoopback: true },
@@ -68,10 +115,10 @@ async function transcribeWithOpenAi(audioBuffer, mimetype) {
68
115
  const model = settings.get("openai_stt_model") || "whisper-large-v3";
69
116
 
70
117
  const formData = new FormData();
71
- const mime = mimetype || "audio/ogg";
118
+ const mime = baseMimeType(mimetype, "audio");
72
119
  const ext = mime.includes("mp4")
73
120
  ? "m4a"
74
- : mime.includes("mp3")
121
+ : mime.includes("mp3") || mime.includes("mpeg")
75
122
  ? "mp3"
76
123
  : mime.includes("wav")
77
124
  ? "wav"
@@ -83,14 +130,18 @@ async function transcribeWithOpenAi(audioBuffer, mimetype) {
83
130
  const controller = new AbortController();
84
131
  const timer = setTimeout(() => controller.abort(), 60000);
85
132
  try {
86
- const res = await safeProviderFetch(`${baseUrl}/audio/transcriptions`, {
87
- method: "POST",
88
- headers: {
89
- Authorization: `Bearer ${apiKey}`,
133
+ const res = await safeProviderFetch(
134
+ `${baseUrl}/audio/transcriptions`,
135
+ {
136
+ method: "POST",
137
+ headers: {
138
+ Authorization: `Bearer ${apiKey}`,
139
+ },
140
+ body: formData,
141
+ signal: controller.signal,
90
142
  },
91
- body: formData,
92
- signal: controller.signal,
93
- }, { allowLoopback: true });
143
+ { allowLoopback: true },
144
+ );
94
145
  if (!res.ok) {
95
146
  const err = await res.text().catch(() => "");
96
147
  throw new Error(`STT API (${res.status}): ${err}`);
@@ -102,140 +153,140 @@ async function transcribeWithOpenAi(audioBuffer, mimetype) {
102
153
  }
103
154
  }
104
155
 
156
+ /** Audio bytes -> text, on whichever engine the settings pick. */
157
+ async function transcribe(audioBuffer, mimetype) {
158
+ const provider = resolveSttProvider();
159
+ const hasOpenAi = !!settings.get("openai_api_key");
160
+ if (provider === "openai" && hasOpenAi) {
161
+ logger.info("[STT] Transcribing via OpenAI/Groq Whisper API");
162
+ return transcribeWithOpenAi(audioBuffer, mimetype);
163
+ }
164
+ if (geminiStt()) {
165
+ logger.info("[STT] Transcribing via Gemini");
166
+ return transcribeWithGemini(audioBuffer, mimetype);
167
+ }
168
+ if (hasOpenAi) {
169
+ logger.info("[STT] Fallback transcribing via OpenAI/Groq Whisper API");
170
+ return transcribeWithOpenAi(audioBuffer, mimetype);
171
+ }
172
+ throw new Error(
173
+ tr(
174
+ "No AI key (Gemini or OpenAI/Groq) is set",
175
+ "مفتاح الذكاء الاصطناعي (Gemini أو OpenAI/Groq) غير مضبوط",
176
+ ),
177
+ );
178
+ }
179
+
180
+ function sttErrorHint(error) {
181
+ const message = String(error?.message || "");
182
+ if (/quota|RESOURCE_EXHAUSTED|429/i.test(message)) {
183
+ return tr(
184
+ "The free quota is used up. Try again later.",
185
+ "تم تجاوز الحد المجاني. حاول مرة أخرى لاحقاً.",
186
+ );
187
+ }
188
+ if (/API key|API_KEY|401|403/i.test(message)) {
189
+ return tr(
190
+ "Check the API key in the control panel (Settings).",
191
+ "راجع مفتاح الـ API من لوحة التحكم (Settings).",
192
+ );
193
+ }
194
+ if (/upload/i.test(message)) {
195
+ return tr("Uploading the audio failed. Try again.", "فشل رفع الملف الصوتي. حاول مرة أخرى.");
196
+ }
197
+ return "";
198
+ }
199
+
105
200
  module.exports = {
106
201
  name: "stt",
107
202
  aliases: ["totext", "transcribe"],
108
- description: "Convert speech/audio to text (supports Gemini & Groq/OpenAI Whisper)",
109
- usage: "stt (قم بالرد على رسالة صوتية أو إرسالها مع الأمر)",
203
+ description: {
204
+ en: "Converts speech/audio to text (Gemini or Groq/OpenAI Whisper).",
205
+ ar: "يحوّل الكلام/الصوت إلى نص (عبر Gemini أو Groq/OpenAI Whisper).",
206
+ },
207
+ usage: {
208
+ en: "stt (reply to a voice note, or send one with the command)",
209
+ ar: "stt (رد على رسالة صوتية أو أرسلها مع الأمر)",
210
+ },
110
211
  chat: "all",
111
212
 
112
213
  async execute(sock, msg, args, body, groupMetadata) {
113
214
  const chatId = msg.key.remoteJid;
114
215
 
115
216
  // Check if message has audio or if it's a reply to an audio message
217
+ const own = unwrapMessage(msg.message);
116
218
  const audioMessage =
117
- msg.message?.audioMessage ||
118
- msg.message?.extendedTextMessage?.contextInfo?.quotedMessage?.audioMessage;
219
+ own.audioMessage ||
220
+ unwrapMessage(own.extendedTextMessage?.contextInfo?.quotedMessage).audioMessage;
119
221
 
120
222
  if (!audioMessage) {
121
223
  return await sock.sendMessage(chatId, {
122
- text: "📢 الاستخدام:\nأرسل رسالة صوتية أو قم بالرد على رسالة صوتية بالأمر !stt\n\n✨ يدعم تفريغ الصوت عبر Gemini و Groq/OpenAI Whisper\n🌍 يدعم العربية والإنجليزية وكافة اللغات",
224
+ text: tr(
225
+ "📢 Usage:\nSend a voice note, or reply to one, with !stt\n\n✨ Transcribes with Gemini or Groq/OpenAI Whisper\n🌍 Arabic, English and every other language",
226
+ "📢 الاستخدام:\nأرسل رسالة صوتية أو قم بالرد على رسالة صوتية بالأمر !stt\n\n✨ يدعم تفريغ الصوت عبر Gemini و Groq/OpenAI Whisper\n🌍 يدعم العربية والإنجليزية وكافة اللغات",
227
+ ),
123
228
  });
124
229
  }
125
230
 
126
- const provider = resolveSttProvider();
127
231
  const hasGemini = !!geminiStt();
128
232
  const hasOpenAi = !!settings.get("openai_api_key");
129
233
 
130
234
  if (!hasGemini && !hasOpenAi) {
131
235
  return await sock.sendMessage(chatId, {
132
- text: "⚠️ مفتاح الذكاء الاصطناعي (Gemini أو OpenAI/Groq) غير مضبوط. يرجى إضافته من لوحة التحكم (Settings).",
236
+ text: tr(
237
+ "⚠️ No AI key (Gemini or OpenAI/Groq) is set. Add one in the control panel (Settings).",
238
+ "⚠️ مفتاح الذكاء الاصطناعي (Gemini أو OpenAI/Groq) غير مضبوط. يرجى إضافته من لوحة التحكم (Settings).",
239
+ ),
133
240
  });
134
241
  }
135
242
 
136
- let tempAudioPath = null;
137
-
138
243
  // One message, edited from "transcribing" into the transcript itself.
139
- const status = await createStatus(sock, chatId, "🎧 جاري تحويل الصوت إلى نص...", {
140
- replyTo: msg,
141
- });
244
+ const status = await createStatus(
245
+ sock,
246
+ chatId,
247
+ tr("🎧 Transcribing...", "🎧 جاري تحويل الصوت إلى نص..."),
248
+ {
249
+ replyTo: msg,
250
+ },
251
+ );
142
252
 
143
253
  try {
144
- // Download audio content
145
- const audioBuffer = await downloadContentFromMessage(audioMessage, "audio");
146
-
147
- let transcription = "";
148
- if (provider === "openai" && hasOpenAi) {
149
- logger.info("[STT] Transcribing via OpenAI/Groq Whisper API");
150
- transcription = await transcribeWithOpenAi(audioBuffer, audioMessage.mimetype);
151
- } else if (hasGemini) {
152
- const gemini = geminiStt();
153
- await assertProviderRequestUrl(settings.get("gemini_base_url"), {
154
- allowLoopback: true,
155
- });
156
- // Save audio to temporary file
157
- tempAudioPath = path.join(__dirname, `stt_audio_${Date.now()}.ogg`);
158
- await fs.writeFile(tempAudioPath, audioBuffer);
159
-
160
- logger.info(`[STT] Saved audio to temporary file: ${tempAudioPath}`);
161
-
162
- // Upload audio to Gemini. ai.files.upload returns the File directly
163
- const uploaded = await gemini.genAI.files.upload({
164
- file: tempAudioPath,
165
- config: {
166
- mimeType: audioMessage.mimetype || "audio/ogg; codecs=opus",
167
- displayName: `audio-${Date.now()}`,
168
- },
169
- });
170
-
171
- logger.info(`[STT] Uploaded audio to Gemini: ${uploaded.uri}`);
172
-
173
- // Generate transcription using Gemini
174
- const response = await gemini.genAI.models.generateContent({
175
- model: sttModel(),
176
- contents: [
177
- {
178
- role: "user",
179
- parts: [
180
- {
181
- fileData: {
182
- mimeType: uploaded.mimeType,
183
- fileUri: uploaded.uri,
184
- },
185
- },
186
- {
187
- text: "Please transcribe this audio message accurately. Return ONLY the transcription text without any additional commentary, explanations, or formatting. Just the raw transcribed text.",
188
- },
189
- ],
190
- },
191
- ],
192
- });
193
-
194
- transcription = (response.text ?? "").trim();
195
- } else if (hasOpenAi) {
196
- logger.info("[STT] Fallback transcribing via OpenAI/Groq Whisper API");
197
- transcription = await transcribeWithOpenAi(audioBuffer, audioMessage.mimetype);
198
- }
254
+ // A real Buffer, not the download stream: the Whisper path wraps it in
255
+ // a Blob, and a stream in a Blob is the string "[object Object]".
256
+ const audioBuffer = await downloadMedia(downloadContentFromMessage, audioMessage, "audio");
257
+ const transcription = await transcribe(audioBuffer, audioMessage.mimetype);
199
258
 
200
- if (!transcription || transcription === "") {
259
+ if (!transcription) {
201
260
  await status.finish(
202
- "⚠️ لم أتمكن من استخراج أي نص من الرسالة الصوتية. تأكد من أن الصوت واضح.",
261
+ tr(
262
+ "⚠️ I couldn't get any text out of that voice note. Make sure the audio is clear.",
263
+ "⚠️ لم أتمكن من استخراج أي نص من الرسالة الصوتية. تأكد من أن الصوت واضح.",
264
+ ),
203
265
  );
204
266
  return;
205
267
  }
206
268
 
207
269
  // The status line becomes the transcript.
208
- await status.finish(`📝 النص المستخرج:\n\n${transcription}`);
270
+ await status.finish(
271
+ tr(`📝 Transcript:\n\n${transcription}`, `📝 النص المستخرج:\n\n${transcription}`),
272
+ );
209
273
 
210
- logger.info("[STT] Successfully transcribed audio to text (FREE - Gemini)");
274
+ logger.info("[STT] Successfully transcribed audio to text");
211
275
  } catch (error) {
212
276
  logger.error({ err: error }, "[STT] Error transcribing audio");
213
277
 
214
- let errorMessage = "❌ حدث خطأ أثناء تحويل الصوت إلى نص.";
215
-
216
- // Provide more specific error messages
217
- if (error.message?.includes("quota")) {
218
- errorMessage += "\n\nتم تجاوز الحد المجاني. حاول مرة أخرى لاحقاً.";
219
- } else if (error.message?.includes("API key")) {
220
- errorMessage += "\n\nخطأ في مفتاح API. تواصل مع المطور.";
221
- } else if (error.message?.includes("upload")) {
222
- errorMessage += "\n\nفشل رفع الملف الصوتي. حاول مرة أخرى.";
223
- }
224
-
225
- await status.finish(errorMessage);
226
- } finally {
227
- // Clean up temporary file
228
- if (tempAudioPath) {
229
- try {
230
- await fs.unlink(tempAudioPath);
231
- logger.info(`[STT] Deleted temporary file: ${tempAudioPath}`);
232
- } catch (cleanupErr) {
233
- logger.warn(
234
- { err: cleanupErr },
235
- `[STT] Failed to delete temporary file: ${tempAudioPath}`,
236
- );
237
- }
238
- }
278
+ // The real reason goes in the card — a bare "an error happened" left
279
+ // nothing to act on.
280
+ const details = String(error?.message || error || tr("unknown", "غير معروف")).slice(0, 800);
281
+ const hint = sttErrorHint(error);
282
+ await status.finish(
283
+ tr(
284
+ `❌ *Transcription failed*\n\n*Details:* ${details}${hint ? `\n\n${hint}` : ""}`,
285
+ `❌ *حدث خطأ أثناء تحويل الصوت إلى نص*\n\n*التفاصيل:* ${details}${hint ? `\n\n${hint}` : ""}`,
286
+ ),
287
+ );
239
288
  }
240
289
  },
241
290
  };
291
+
292
+ module.exports.transcribe = transcribe;
@@ -1,12 +1,19 @@
1
1
  // file: /commands/todo.cjs (Corrected Reply Logic)
2
2
  const { getUserTodos, saveUserTodos } = require("../utils/storage.cjs");
3
3
  const logger = require("../utils/logger.cjs");
4
+ const { tr } = require("../utils/i18n.cjs");
4
5
  const normalizeJid = require("../utils/normalizeJid.esm.js").default;
5
6
 
6
7
  module.exports = {
7
8
  name: "todo",
8
- description: "Manages your personal to-do list.",
9
- usage: "todo list\ntodo add <المهمة>\ntodo del <رقم المهمة>",
9
+ description: {
10
+ en: "Manages your personal to-do list.",
11
+ ar: "يدير قائمة مهامك الشخصية.",
12
+ },
13
+ usage: {
14
+ en: "todo list\ntodo add <task>\ntodo del <task number>",
15
+ ar: "todo list\ntodo add <المهمة>\ntodo del <رقم المهمة>",
16
+ },
10
17
  chat: "all",
11
18
 
12
19
  async execute(sock, msg, args) {
@@ -22,13 +29,16 @@ module.exports = {
22
29
  const taskToAdd = args.slice(1).join(" ");
23
30
  if (!taskToAdd) {
24
31
  return await sock.sendMessage(remoteJid, {
25
- text: "يرجى كتابة المهمة التي تريد إضافتها.",
32
+ text: tr("Write the task you want to add.", "يرجى كتابة المهمة التي تريد إضافتها."),
26
33
  });
27
34
  }
28
35
  userTasks.push(taskToAdd);
29
36
  saveUserTodos(senderId, userTasks);
30
37
  await sock.sendMessage(remoteJid, {
31
- text: `✅ يا @${senderId.split("@")[0]}، تمت إضافة المهمة لقائمتك.`,
38
+ text: tr(
39
+ `✅ @${senderId.split("@")[0]}, the task was added to your list.`,
40
+ `✅ يا @${senderId.split("@")[0]}، تمت إضافة المهمة لقائمتك.`,
41
+ ),
32
42
  mentions: [senderId],
33
43
  });
34
44
  break;
@@ -39,13 +49,16 @@ module.exports = {
39
49
  const taskNumber = parseInt(args[1], 10);
40
50
  if (isNaN(taskNumber) || taskNumber <= 0 || taskNumber > userTasks.length) {
41
51
  return await sock.sendMessage(remoteJid, {
42
- text: "رقم المهمة غير صالح.",
52
+ text: tr("That task number isn't valid.", "رقم المهمة غير صالح."),
43
53
  });
44
54
  }
45
55
  const removedTask = userTasks.splice(taskNumber - 1, 1);
46
56
  saveUserTodos(senderId, userTasks);
47
57
  await sock.sendMessage(remoteJid, {
48
- text: `☑️ يا @${senderId.split("@")[0]}، تم حذف المهمة: *${removedTask[0]}*`,
58
+ text: tr(
59
+ `☑️ @${senderId.split("@")[0]}, removed the task: *${removedTask[0]}*`,
60
+ `☑️ يا @${senderId.split("@")[0]}، تم حذف المهمة: *${removedTask[0]}*`,
61
+ ),
49
62
  mentions: [senderId],
50
63
  });
51
64
  break;
@@ -55,12 +68,18 @@ module.exports = {
55
68
  default: {
56
69
  if (userTasks.length === 0) {
57
70
  return await sock.sendMessage(remoteJid, {
58
- text: `قائمة مهامك فارغة يا @${senderId.split("@")[0]}.`,
71
+ text: tr(
72
+ `Your to-do list is empty, @${senderId.split("@")[0]}.`,
73
+ `قائمة مهامك فارغة يا @${senderId.split("@")[0]}.`,
74
+ ),
59
75
  mentions: [senderId],
60
76
  });
61
77
  }
62
78
 
63
- let reply = `*📋 قائمة مهامك يا @${senderId.split("@")[0]}:*\n\n`;
79
+ let reply = tr(
80
+ `*📋 Your to-do list, @${senderId.split("@")[0]}:*\n\n`,
81
+ `*📋 قائمة مهامك يا @${senderId.split("@")[0]}:*\n\n`,
82
+ );
64
83
  userTasks.forEach((task, index) => {
65
84
  reply += `${index + 1}. ${task}\n`;
66
85
  });
@@ -75,7 +94,10 @@ module.exports = {
75
94
  } catch (error) {
76
95
  logger.error({ err: error, command: "todo" }, "An error occurred in the todo command");
77
96
  await sock.sendMessage(msg.key.remoteJid, {
78
- text: "حدث خطأ أثناء معالجة قائمة المهام.",
97
+ text: tr(
98
+ "Something went wrong with the to-do list.",
99
+ "حدث خطأ أثناء معالجة قائمة المهام.",
100
+ ),
79
101
  });
80
102
  }
81
103
  },
@@ -23,6 +23,7 @@ const { sendBotMessage } = require("../utils/sendBotMessage.cjs");
23
23
  const execFileAsync = promisify(execFile);
24
24
 
25
25
  const { ffmpegPath } = require("../utils/thumbnail.cjs");
26
+ const { tr } = require("../utils/i18n.cjs");
26
27
 
27
28
  function tmpPath(ext) {
28
29
  return path.join(
@@ -133,8 +134,14 @@ async function synthesizeVoice(text, lang = "ar") {
133
134
  module.exports = {
134
135
  name: "tts",
135
136
  aliases: ["tovoice", "speak"],
136
- description: "Convert text to speech (FREE - no API costs)",
137
- usage: "tts <النص> (أو رد على رسالة نصية)",
137
+ description: {
138
+ en: "Converts text to speech (free — no API costs).",
139
+ ar: "يحوّل النص إلى كلام مسموع (مجاني — بدون تكلفة API).",
140
+ },
141
+ usage: {
142
+ en: "tts <text> (or reply to a text message)",
143
+ ar: "tts <النص> (أو رد على رسالة نصية)",
144
+ },
138
145
  chat: "all",
139
146
 
140
147
  async execute(sock, msg, args) {
@@ -152,16 +159,24 @@ module.exports = {
152
159
  sock,
153
160
  chatId,
154
161
  {
155
- text: "📢 الاستخدام:\n!tts <النص>\n\nأو رد على رسالة نصية بالأمر !tts\n\n✨ مجاني تماماً - بدون تكاليف!",
162
+ text: tr(
163
+ "📢 Usage:\n!tts <text>\n\nor reply to a text message with !tts\n\n✨ Completely free — no costs!",
164
+ "📢 الاستخدام:\n!tts <النص>\n\nأو رد على رسالة نصية بالأمر !tts\n\n✨ مجاني تماماً - بدون تكاليف!",
165
+ ),
156
166
  },
157
167
  { replyTo: msg },
158
168
  );
159
169
  }
160
170
 
161
171
  // One status line: it disappears once the voice note is on its way.
162
- const status = await createStatus(sock, chatId, "🎙️ بحوّل النص لصوت...", {
163
- replyTo: msg,
164
- });
172
+ const status = await createStatus(
173
+ sock,
174
+ chatId,
175
+ tr("🎙️ Turning the text into speech...", "🎙️ بحوّل النص لصوت..."),
176
+ {
177
+ replyTo: msg,
178
+ },
179
+ );
165
180
 
166
181
  try {
167
182
  const voice = await synthesizeVoice(textToConvert);
@@ -198,7 +213,10 @@ module.exports = {
198
213
  logger.info("[TTS] Successfully delivered TTS audio");
199
214
  } catch (error) {
200
215
  logger.error({ err: error }, "[TTS] Error converting text to speech");
201
- await status.fail(error, "حصلت مشكلة وأنا بحوّل النص لصوت");
216
+ await status.fail(
217
+ error,
218
+ tr("Something went wrong turning the text into speech", "حصلت مشكلة وأنا بحوّل النص لصوت"),
219
+ );
202
220
  }
203
221
  },
204
222
 
@@ -1,11 +1,18 @@
1
1
  // file: /commands/unblock.js (Upgraded with private chat context)
2
2
  const logger = require("../utils/logger.cjs");
3
3
  const normalizeJid = require("../utils/normalizeJid.esm.js");
4
+ const { tr } = require("../utils/i18n.cjs");
4
5
 
5
6
  module.exports = {
6
7
  name: "unblock",
7
- description: "Unblocks a user.",
8
- usage: "unblock [@عضو|رقم] (أو رد على رسالته)",
8
+ description: {
9
+ en: "Unblocks a user.",
10
+ ar: "يلغي حظر مستخدم.",
11
+ },
12
+ usage: {
13
+ en: "unblock [@member|number] (or reply to their message)",
14
+ ar: "unblock [@عضو|رقم] (أو رد على رسالته)",
15
+ },
9
16
  chat: "all",
10
17
 
11
18
  async execute(sock, msg, args) {
@@ -25,7 +32,10 @@ module.exports = {
25
32
  targetJid = `${numberArg.replace(/\D/g, "")}@s.whatsapp.net`;
26
33
  } else {
27
34
  return await sock.sendMessage(remoteJid, {
28
- text: "لفك حظر عضو، استخدم الأمر في شاته الخاص، أو قم بعمل منشن له، أو كتابة رقمه.",
35
+ text: tr(
36
+ "To unblock someone, use this in their private chat, mention them, or type their number.",
37
+ "لفك حظر عضو، استخدم الأمر في شاته الخاص، أو قم بعمل منشن له، أو كتابة رقمه.",
38
+ ),
29
39
  });
30
40
  }
31
41
  }
@@ -46,7 +56,10 @@ module.exports = {
46
56
  } catch (error) {
47
57
  logger.error({ err: error, command: "unblock" }, "Error in !unblock command");
48
58
  await sock.sendMessage(remoteJid, {
49
- text: "حدث خطأ أثناء محاولة فك حظر المستخدم.",
59
+ text: tr(
60
+ "Something went wrong while unblocking the user.",
61
+ "حدث خطأ أثناء محاولة فك حظر المستخدم.",
62
+ ),
50
63
  });
51
64
  }
52
65
  },
@@ -5,17 +5,30 @@ const logger = require("../utils/logger.cjs");
5
5
  const { createStatus } = require("../utils/statusMessage.cjs");
6
6
 
7
7
  const settings = require("../config/settings.cjs");
8
+ const { tr } = require("../utils/i18n.cjs");
8
9
 
9
10
  module.exports = {
10
11
  name: "weather",
11
- description: "Gets the current weather for a specific city.",
12
- usage: "weather <المدينة بالإنجليزية>",
12
+ description: {
13
+ en: "Shows the current weather for a city.",
14
+ ar: "يعرض حالة الطقس الحالية لمدينة معيّنة.",
15
+ },
16
+ usage: {
17
+ en: "weather <city in English>",
18
+ ar: "weather <اسم المدينة بالإنجليزية>",
19
+ },
13
20
  chat: "all",
21
+ // The city is asked for in English whatever language you speak, so it says
22
+ // nothing about which language to answer in (see utils/i18n.cjs).
23
+ neutralArgs: true,
14
24
 
15
25
  async execute(sock, msg, args) {
16
26
  if (!args || args.length === 0) {
17
27
  return await sock.sendMessage(msg.key.remoteJid, {
18
- text: "يرجى تقديم اسم المدينة باللغة الانجليزية.\n\n*مثال:* `!weather cairo`",
28
+ text: tr(
29
+ "Give the city's name in English.\n\n*Example:* `!weather cairo`",
30
+ "يرجى تقديم اسم المدينة باللغة الانجليزية.\n\n*مثال:* `!weather cairo`",
31
+ ),
19
32
  });
20
33
  }
21
34
 
@@ -23,14 +36,19 @@ module.exports = {
23
36
 
24
37
  // URL الخاص بـ OpenWeatherMap للحصول على الطقس الحالي
25
38
  // - units=metric للحصول على درجة الحرارة بالسيليزيوس
26
- // - lang=ar للحصول على الوصف باللغة العربية
39
+ // - lang: الوصف بلغة الرد
27
40
  const apiKey = settings.get("openweathermap_api_key");
28
- const API_URL = `https://api.openweathermap.org/data/2.5/weather?q=${city}&appid=${apiKey}&units=metric&lang=ar`;
41
+ const API_URL = `https://api.openweathermap.org/data/2.5/weather?q=${city}&appid=${apiKey}&units=metric&lang=${tr("en", "ar")}`;
29
42
 
30
43
  // One message: it starts as "looking it up" and turns into the forecast.
31
- const status = await createStatus(sock, msg.key.remoteJid, `🔍 بدور على طقس ${city}...`, {
32
- replyTo: msg,
33
- });
44
+ const status = await createStatus(
45
+ sock,
46
+ msg.key.remoteJid,
47
+ tr(`🔍 Looking up the weather in ${city}...`, `🔍 بدور على طقس ${city}...`),
48
+ {
49
+ replyTo: msg,
50
+ },
51
+ );
34
52
 
35
53
  try {
36
54
  const response = await axios.get(API_URL);
@@ -44,28 +62,48 @@ module.exports = {
44
62
  const windSpeed = weatherData.wind.speed;
45
63
 
46
64
  // تنسيق رسالة الرد مع الأيقونات
47
- const reply =
65
+ const reply = tr(
66
+ `*Weather in ${city}:*\n\n` +
67
+ `🌤️ Conditions: ${weatherDescription}\n` +
68
+ `🌡️ Temperature: ${currentTemp}°C\n` +
69
+ `🤔 Feels like: ${feelsLike}°C\n` +
70
+ `💧 Humidity: ${humidity}%\n` +
71
+ `🌬️ Wind: ${windSpeed} m/s`,
48
72
  `*حالة الطقس في مدينة ${city}:*\n\n` +
49
- `🌤️ الوصف: ${weatherDescription}\n` +
50
- `🌡️ درجة الحرارة: ${currentTemp}°C\n` +
51
- `🤔 الإحساس الفعلي: ${feelsLike}°C\n` +
52
- `💧 الرطوبة: ${humidity}%\n` +
53
- `🌬️ سرعة الرياح: ${windSpeed} متر/ثانية`;
73
+ `🌤️ الوصف: ${weatherDescription}\n` +
74
+ `🌡️ درجة الحرارة: ${currentTemp}°C\n` +
75
+ `🤔 الإحساس الفعلي: ${feelsLike}°C\n` +
76
+ `💧 الرطوبة: ${humidity}%\n` +
77
+ `🌬️ سرعة الرياح: ${windSpeed} متر/ثانية`,
78
+ );
54
79
 
55
80
  await status.finish(reply);
56
81
  } catch (error) {
57
82
  // التعامل مع الأخطاء
58
83
  if (error.response && error.response.status === 404) {
59
84
  // خطأ 404 يعني أن المدينة غير موجودة
60
- await status.finish(`لم أتمكن من العثور على مدينة باسم "${city}". يرجى التحقق من الاسم.`);
85
+ await status.finish(
86
+ tr(
87
+ `I couldn't find a city called "${city}". Check the name.`,
88
+ `لم أتمكن من العثور على مدينة باسم "${city}". يرجى التحقق من الاسم.`,
89
+ ),
90
+ );
61
91
  } else if (error.response && error.response.status === 401) {
62
92
  // خطأ 401 يعني أن مفتاح الـ API غير صالح
63
93
  logger.error("[Error] Invalid API Key for OpenWeatherMap.");
64
- await status.finish(`حدث خطأ في المصادقة مع خدمة الطقس. يرجى مراجعة مفتاح الـ API.`);
94
+ await status.finish(
95
+ tr(
96
+ "The weather service rejected the API key. Check it in the settings.",
97
+ `حدث خطأ في المصادقة مع خدمة الطقس. يرجى مراجعة مفتاح الـ API.`,
98
+ ),
99
+ );
65
100
  } else {
66
101
  // أي أخطاء أخرى
67
102
  logger.error(error.message, "[Error] in Weather API:");
68
- await status.fail(error, "عذرًا، حدث خطأ أثناء جلب بيانات الطقس");
103
+ await status.fail(
104
+ error,
105
+ tr("Sorry, fetching the weather failed", "عذرًا، حدث خطأ أثناء جلب بيانات الطقس"),
106
+ );
69
107
  }
70
108
  }
71
109
  },