Deploy Bot commited on
Commit
7f0a8de
Β·
1 Parent(s): 1a82561

Fix_Critical_Undefined_Button_Error_With_Fallbacks

Browse files
Files changed (1) hide show
  1. src/controllers/userController.js +17 -11
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] // Added Language Button
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], // Added Language Button here
31
- [i18n.btn_invite]
32
  ];
33
  }
34
 
35
- const msg = text || i18n.menu_main;
 
 
 
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
  };