Spaces:
Paused
Paused
Deploy Bot commited on
Commit ·
9827bc0
1
Parent(s): 404ae9f
Improve_Language_Change_Logic
Browse files- src/main.js +25 -4
src/main.js
CHANGED
|
@@ -182,15 +182,36 @@ bot.use(async (ctx, next) => {
|
|
| 182 |
// Language Selection Handlers
|
| 183 |
const setLanguage = async (ctx, lang) => {
|
| 184 |
try {
|
|
|
|
|
|
|
|
|
|
| 185 |
await User.updateOne({ id: ctx.from.id }, { language: lang });
|
|
|
|
|
|
|
| 186 |
const locales = require('./locales');
|
| 187 |
ctx.i18n = locales[lang];
|
| 188 |
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 192 |
} catch (e) {
|
| 193 |
-
console.error(e);
|
|
|
|
| 194 |
}
|
| 195 |
};
|
| 196 |
|
|
|
|
| 182 |
// Language Selection Handlers
|
| 183 |
const setLanguage = async (ctx, lang) => {
|
| 184 |
try {
|
| 185 |
+
await ctx.answerCbQuery(); // Stop loading animation
|
| 186 |
+
|
| 187 |
+
// 1. Update Database
|
| 188 |
await User.updateOne({ id: ctx.from.id }, { language: lang });
|
| 189 |
+
|
| 190 |
+
// 2. Update Context Locale Immediately
|
| 191 |
const locales = require('./locales');
|
| 192 |
ctx.i18n = locales[lang];
|
| 193 |
|
| 194 |
+
// 3. Clean up previous valid/invalid messages
|
| 195 |
+
try {
|
| 196 |
+
await ctx.deleteMessage();
|
| 197 |
+
} catch (e) {
|
| 198 |
+
// Message might be too old or already deleted
|
| 199 |
+
}
|
| 200 |
+
|
| 201 |
+
// 4. Send Confirmation in NEW Language
|
| 202 |
+
await ctx.reply(`✅ ${ctx.i18n.language_set}`, { parse_mode: 'HTML' });
|
| 203 |
+
|
| 204 |
+
// 5. Refresh Main Menu with NEW Language Buttons
|
| 205 |
+
// We pass a flag or text to start to indicate a refresh,
|
| 206 |
+
// but userController.start(ctx) usually handles simple menu generation.
|
| 207 |
+
// Let's ensure it sends the FULL welcome text again or just the menu.
|
| 208 |
+
// For "Maximal Logic", resetting to the main menu with a fresh "Welcome back" or just the menu is best.
|
| 209 |
+
|
| 210 |
+
userController.start(ctx);
|
| 211 |
+
|
| 212 |
} catch (e) {
|
| 213 |
+
console.error("Language Change Error:", e);
|
| 214 |
+
ctx.reply("⚠️ Error changing language. Please try again or /start");
|
| 215 |
}
|
| 216 |
};
|
| 217 |
|