Spaces:
Paused
Paused
Deploy Bot commited on
Commit Β·
7f0a8de
1
Parent(s): 1a82561
Fix_Critical_Undefined_Button_Error_With_Fallbacks
Browse files
src/controllers/userController.js
CHANGED
|
@@ -13,26 +13,32 @@ exports.start = (ctx, text) => {
|
|
| 13 |
// Ensure i18n is available (fallback if direct call)
|
| 14 |
const i18n = ctx.i18n || require('../locales').uz;
|
| 15 |
|
|
|
|
|
|
|
|
|
|
| 16 |
let buttons = [];
|
| 17 |
if (isAdmin) {
|
| 18 |
buttons = [
|
| 19 |
-
[i18n.btn_catalog, i18n.btn_search],
|
| 20 |
-
[i18n.btn_orders, i18n.btn_cart],
|
| 21 |
-
["π¨βπΌ Admin Panel", i18n.btn_contact],
|
| 22 |
-
[i18n.btn_channel, i18n.btn_group],
|
| 23 |
-
[i18n.btn_invite, i18n.btn_lang
|
| 24 |
];
|
| 25 |
} else {
|
| 26 |
buttons = [
|
| 27 |
-
[i18n.btn_catalog, i18n.btn_search],
|
| 28 |
-
[i18n.btn_orders, i18n.btn_cart],
|
| 29 |
-
[i18n.btn_channel, i18n.btn_group],
|
| 30 |
-
[i18n.btn_contact, i18n.btn_lang
|
| 31 |
-
[i18n.btn_invite]
|
| 32 |
];
|
| 33 |
}
|
| 34 |
|
| 35 |
-
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
return ctx.replyWithHTML(msg, Markup.keyboard(buttons).resize());
|
| 38 |
};
|
|
|
|
| 13 |
// Ensure i18n is available (fallback if direct call)
|
| 14 |
const i18n = ctx.i18n || require('../locales').uz;
|
| 15 |
|
| 16 |
+
// Ensure proper buttons with fallbacks
|
| 17 |
+
const btn = (key, fallback) => key || fallback;
|
| 18 |
+
|
| 19 |
let buttons = [];
|
| 20 |
if (isAdmin) {
|
| 21 |
buttons = [
|
| 22 |
+
[btn(i18n.btn_catalog, "π Katalog"), btn(i18n.btn_search, "π Qidiruv")],
|
| 23 |
+
[btn(i18n.btn_orders, "π¦ Buyurtmalarim"), btn(i18n.btn_cart, "π Savat")],
|
| 24 |
+
["π¨βπΌ Admin Panel", btn(i18n.btn_contact, "π Aloqa")],
|
| 25 |
+
[btn(i18n.btn_channel, "π’ Kanal"), btn(i18n.btn_group, "π₯ Guruh")],
|
| 26 |
+
[btn(i18n.btn_invite, "π₯ Taklif"), btn(i18n.btn_lang, "π Til")]
|
| 27 |
];
|
| 28 |
} else {
|
| 29 |
buttons = [
|
| 30 |
+
[btn(i18n.btn_catalog, "π Katalog"), btn(i18n.btn_search, "π Qidiruv")],
|
| 31 |
+
[btn(i18n.btn_orders, "π¦ Buyurtmalarim"), btn(i18n.btn_cart, "π Savat")],
|
| 32 |
+
[btn(i18n.btn_channel, "π’ Kanal"), btn(i18n.btn_group, "π₯ Guruh")],
|
| 33 |
+
[btn(i18n.btn_contact, "π Aloqa"), btn(i18n.btn_lang, "π Til")],
|
| 34 |
+
[btn(i18n.btn_invite, "π₯ Taklif")]
|
| 35 |
];
|
| 36 |
}
|
| 37 |
|
| 38 |
+
// Filter out any undefined or empty strings just in case
|
| 39 |
+
buttons = buttons.map(row => row.filter(b => b));
|
| 40 |
+
|
| 41 |
+
const msg = text || i18n.menu_main || "Menu";
|
| 42 |
|
| 43 |
return ctx.replyWithHTML(msg, Markup.keyboard(buttons).resize());
|
| 44 |
};
|