Spaces:
Paused
Paused
Deploy Bot commited on
Commit ยท
41e9bf8
1
Parent(s): 852aacf
Restore_Admin_Panel_And_Fix_Language_Logic
Browse files- src/controllers/userController.js +2 -2
- src/main.js +18 -7
src/controllers/userController.js
CHANGED
|
@@ -21,9 +21,9 @@ exports.start = (ctx, text) => {
|
|
| 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 |
[btn(i18n.btn_channel, "๐ข Kanal"), btn(i18n.btn_group, "๐ฅ Guruh")],
|
| 25 |
-
[btn(i18n.
|
| 26 |
-
[btn(i18n.btn_invite, "๐ฅ Taklif")]
|
| 27 |
];
|
| 28 |
} else {
|
| 29 |
buttons = [
|
|
|
|
| 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")], // JOINED
|
| 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 = [
|
src/main.js
CHANGED
|
@@ -104,16 +104,27 @@ bot.start(async (ctx) => {
|
|
| 104 |
try {
|
| 105 |
const user = ctx.from;
|
| 106 |
let dbUser = await User.findOne({ id: user.id });
|
|
|
|
|
|
|
|
|
|
|
|
|
| 107 |
if (!dbUser) {
|
| 108 |
-
|
|
|
|
| 109 |
id: user.id,
|
| 110 |
first_name: user.first_name,
|
| 111 |
-
username: user.username
|
| 112 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 113 |
}
|
| 114 |
|
| 115 |
-
//
|
| 116 |
-
// Even if middleware didn't catch it (because isStart was true), we must prompt it here.
|
| 117 |
if (!dbUser.language) {
|
| 118 |
return ctx.reply("๐บ๐ฟ Iltimos, tilni tanlang:\n๐ท๐บ ะะพะถะฐะปัะนััะฐ, ะฒัะฑะตัะธัะต ัะทัะบ:\n๐ฌ๐ง Please select a language:", Markup.inlineKeyboard([
|
| 119 |
[Markup.button.callback("๐บ๐ฟ O'zbekcha", "set_lang_uz")],
|
|
@@ -122,11 +133,11 @@ bot.start(async (ctx) => {
|
|
| 122 |
]));
|
| 123 |
}
|
| 124 |
|
| 125 |
-
//
|
|
|
|
| 126 |
const locales = require('./locales');
|
| 127 |
ctx.i18n = locales[dbUser.language] || locales.uz;
|
| 128 |
|
| 129 |
-
// Pass control to controller
|
| 130 |
userController.start(ctx);
|
| 131 |
} catch (err) {
|
| 132 |
console.error(err);
|
|
|
|
| 104 |
try {
|
| 105 |
const user = ctx.from;
|
| 106 |
let dbUser = await User.findOne({ id: user.id });
|
| 107 |
+
|
| 108 |
+
// Handle Referral
|
| 109 |
+
const payload = ctx.startPayload;
|
| 110 |
+
|
| 111 |
if (!dbUser) {
|
| 112 |
+
// NEW USER: Create with null language to force selection
|
| 113 |
+
dbUser = new User({
|
| 114 |
id: user.id,
|
| 115 |
first_name: user.first_name,
|
| 116 |
+
username: user.username,
|
| 117 |
+
language: null // Explicitly null
|
| 118 |
+
});
|
| 119 |
+
await dbUser.save();
|
| 120 |
+
|
| 121 |
+
// If referral exists, handle it
|
| 122 |
+
if (payload && payload !== user.id.toString()) {
|
| 123 |
+
userController.handleReferral(ctx, payload);
|
| 124 |
+
}
|
| 125 |
}
|
| 126 |
|
| 127 |
+
// FORCE LANGUAGE SELECTION IF NULL
|
|
|
|
| 128 |
if (!dbUser.language) {
|
| 129 |
return ctx.reply("๐บ๐ฟ Iltimos, tilni tanlang:\n๐ท๐บ ะะพะถะฐะปัะนััะฐ, ะฒัะฑะตัะธัะต ัะทัะบ:\n๐ฌ๐ง Please select a language:", Markup.inlineKeyboard([
|
| 130 |
[Markup.button.callback("๐บ๐ฟ O'zbekcha", "set_lang_uz")],
|
|
|
|
| 133 |
]));
|
| 134 |
}
|
| 135 |
|
| 136 |
+
// If language exists, proceed to menu
|
| 137 |
+
// Attach locale using the user's language
|
| 138 |
const locales = require('./locales');
|
| 139 |
ctx.i18n = locales[dbUser.language] || locales.uz;
|
| 140 |
|
|
|
|
| 141 |
userController.start(ctx);
|
| 142 |
} catch (err) {
|
| 143 |
console.error(err);
|