Mohammed Foud
commited on
Commit
·
8e517c1
1
Parent(s):
1b99e9c
all
Browse files
src/bots/handlers/balanceHandlers.ts
CHANGED
|
@@ -24,14 +24,14 @@ const paymentMethodStates = new Map<number, PaymentMethod>();
|
|
| 24 |
export const handleTopUpAction = async (ctx: BotContext) => {
|
| 25 |
const telegramId = ctx.from?.id;
|
| 26 |
|
| 27 |
-
if (!telegramId || !authService.isUserLoggedIn(telegramId)) {
|
| 28 |
return {
|
| 29 |
message: messageManager.getMessage('auth_required'),
|
| 30 |
options: getMainMenuKeyboard()
|
| 31 |
};
|
| 32 |
}
|
| 33 |
|
| 34 |
-
const user = await authService.getUserByTelegramId(telegramId);
|
| 35 |
|
| 36 |
if (!user) {
|
| 37 |
return {
|
|
@@ -60,7 +60,7 @@ export const handleTopUpAction = async (ctx: BotContext) => {
|
|
| 60 |
export const handleCustomAmountRequest = async (ctx: BotContext) => {
|
| 61 |
const telegramId = ctx.from?.id;
|
| 62 |
|
| 63 |
-
if (!telegramId || !authService.isUserLoggedIn(telegramId)) {
|
| 64 |
return {
|
| 65 |
message: messageManager.getMessage('auth_required'),
|
| 66 |
options: getMainMenuKeyboard()
|
|
@@ -84,7 +84,7 @@ export const handleCustomAmountRequest = async (ctx: BotContext) => {
|
|
| 84 |
export const handlePaymentMethodSelection = async (ctx: BotContext, method: PaymentMethod) => {
|
| 85 |
const telegramId = ctx.from?.id;
|
| 86 |
|
| 87 |
-
if (!telegramId || !authService.isUserLoggedIn(telegramId)) {
|
| 88 |
return {
|
| 89 |
message: messageManager.getMessage('auth_required'),
|
| 90 |
options: getMainMenuKeyboard()
|
|
@@ -118,14 +118,14 @@ export const handlePaymentMethodSelection = async (ctx: BotContext, method: Paym
|
|
| 118 |
export const handleTopUpAmount = async (ctx: BotContext, amount: number) => {
|
| 119 |
const telegramId = ctx.from?.id;
|
| 120 |
|
| 121 |
-
if (!telegramId || !authService.isUserLoggedIn(telegramId)) {
|
| 122 |
return {
|
| 123 |
message: messageManager.getMessage('auth_required'),
|
| 124 |
options: getMainMenuKeyboard()
|
| 125 |
};
|
| 126 |
}
|
| 127 |
|
| 128 |
-
const user = await authService.getUserByTelegramId(telegramId);
|
| 129 |
const paymentMethod = paymentMethodStates.get(telegramId);
|
| 130 |
|
| 131 |
if (!user) {
|
|
|
|
| 24 |
export const handleTopUpAction = async (ctx: BotContext) => {
|
| 25 |
const telegramId = ctx.from?.id;
|
| 26 |
|
| 27 |
+
if (!telegramId || !authService.isUserLoggedIn(telegramId,ctx)) {
|
| 28 |
return {
|
| 29 |
message: messageManager.getMessage('auth_required'),
|
| 30 |
options: getMainMenuKeyboard()
|
| 31 |
};
|
| 32 |
}
|
| 33 |
|
| 34 |
+
const user = await authService.getUserByTelegramId(telegramId,ctx);
|
| 35 |
|
| 36 |
if (!user) {
|
| 37 |
return {
|
|
|
|
| 60 |
export const handleCustomAmountRequest = async (ctx: BotContext) => {
|
| 61 |
const telegramId = ctx.from?.id;
|
| 62 |
|
| 63 |
+
if (!telegramId || !authService.isUserLoggedIn(telegramId,ctx)) {
|
| 64 |
return {
|
| 65 |
message: messageManager.getMessage('auth_required'),
|
| 66 |
options: getMainMenuKeyboard()
|
|
|
|
| 84 |
export const handlePaymentMethodSelection = async (ctx: BotContext, method: PaymentMethod) => {
|
| 85 |
const telegramId = ctx.from?.id;
|
| 86 |
|
| 87 |
+
if (!telegramId || !authService.isUserLoggedIn(telegramId,ctx)) {
|
| 88 |
return {
|
| 89 |
message: messageManager.getMessage('auth_required'),
|
| 90 |
options: getMainMenuKeyboard()
|
|
|
|
| 118 |
export const handleTopUpAmount = async (ctx: BotContext, amount: number) => {
|
| 119 |
const telegramId = ctx.from?.id;
|
| 120 |
|
| 121 |
+
if (!telegramId || !authService.isUserLoggedIn(telegramId,ctx)) {
|
| 122 |
return {
|
| 123 |
message: messageManager.getMessage('auth_required'),
|
| 124 |
options: getMainMenuKeyboard()
|
| 125 |
};
|
| 126 |
}
|
| 127 |
|
| 128 |
+
const user = await authService.getUserByTelegramId(telegramId,ctx);
|
| 129 |
const paymentMethod = paymentMethodStates.get(telegramId);
|
| 130 |
|
| 131 |
if (!user) {
|
src/bots/handlers/giftHandlers.ts
CHANGED
|
@@ -12,7 +12,7 @@ export const giftStates = new Map<number, { step: number; recipientEmail?: strin
|
|
| 12 |
export const handleGiftBalanceAction = async (ctx: BotContext) => {
|
| 13 |
const telegramId = ctx.from?.id;
|
| 14 |
|
| 15 |
-
if (!telegramId || !authService.isUserLoggedIn(telegramId)) {
|
| 16 |
return {
|
| 17 |
message: messageManager.getMessage('auth_required'),
|
| 18 |
options: getMainMenuKeyboard()
|
|
@@ -95,7 +95,7 @@ export const handleGiftAmountInput = async (ctx: BotContext) => {
|
|
| 95 |
|
| 96 |
try {
|
| 97 |
// Get sender's current balance
|
| 98 |
-
const sender = await authService.getUserByTelegramId(telegramId);
|
| 99 |
if (!sender || (sender.balance || 0) < amount) {
|
| 100 |
return {
|
| 101 |
message: "❌ رصيدك غير كافي لإتمام هذه العملية.",
|
|
|
|
| 12 |
export const handleGiftBalanceAction = async (ctx: BotContext) => {
|
| 13 |
const telegramId = ctx.from?.id;
|
| 14 |
|
| 15 |
+
if (!telegramId || !authService.isUserLoggedIn(telegramId,ctx)) {
|
| 16 |
return {
|
| 17 |
message: messageManager.getMessage('auth_required'),
|
| 18 |
options: getMainMenuKeyboard()
|
|
|
|
| 95 |
|
| 96 |
try {
|
| 97 |
// Get sender's current balance
|
| 98 |
+
const sender = await authService.getUserByTelegramId(telegramId,ctx);
|
| 99 |
if (!sender || (sender.balance || 0) < amount) {
|
| 100 |
return {
|
| 101 |
message: "❌ رصيدك غير كافي لإتمام هذه العملية.",
|
src/bots/handlers/historyHandlers.ts
CHANGED
|
@@ -23,7 +23,7 @@ export const setupHistoryHandlers = (bot: any) => {
|
|
| 23 |
};
|
| 24 |
export const handleHistoryAction = async (ctx: BotContext) => {
|
| 25 |
const telegramId = ctx.from?.id;
|
| 26 |
-
if (!telegramId || !authService.isUserLoggedIn(telegramId)) {
|
| 27 |
return {
|
| 28 |
message: messageManager.getMessage('auth_required'),
|
| 29 |
options: getMainMenuKeyboard()
|
|
@@ -39,7 +39,7 @@ export const handleHistoryAction = async (ctx: BotContext) => {
|
|
| 39 |
|
| 40 |
export const handleNumbersHistoryAction = async (ctx: BotContext) => {
|
| 41 |
const telegramId = ctx.from?.id;
|
| 42 |
-
if (!telegramId || !authService.isUserLoggedIn(telegramId)) {
|
| 43 |
return {
|
| 44 |
message: messageManager.getMessage('auth_required'),
|
| 45 |
options: getMainMenuKeyboard()
|
|
@@ -96,7 +96,7 @@ export const handleNumbersHistoryAction = async (ctx: BotContext) => {
|
|
| 96 |
|
| 97 |
export const handlePurchasesHistoryAction = async (ctx: BotContext) => {
|
| 98 |
const telegramId = ctx.from?.id;
|
| 99 |
-
if (!telegramId || !authService.isUserLoggedIn(telegramId)) {
|
| 100 |
return {
|
| 101 |
message: messageManager.getMessage('auth_required'),
|
| 102 |
options: getMainMenuKeyboard()
|
|
|
|
| 23 |
};
|
| 24 |
export const handleHistoryAction = async (ctx: BotContext) => {
|
| 25 |
const telegramId = ctx.from?.id;
|
| 26 |
+
if (!telegramId || !authService.isUserLoggedIn(telegramId,ctx)) {
|
| 27 |
return {
|
| 28 |
message: messageManager.getMessage('auth_required'),
|
| 29 |
options: getMainMenuKeyboard()
|
|
|
|
| 39 |
|
| 40 |
export const handleNumbersHistoryAction = async (ctx: BotContext) => {
|
| 41 |
const telegramId = ctx.from?.id;
|
| 42 |
+
if (!telegramId || !authService.isUserLoggedIn(telegramId,ctx)) {
|
| 43 |
return {
|
| 44 |
message: messageManager.getMessage('auth_required'),
|
| 45 |
options: getMainMenuKeyboard()
|
|
|
|
| 96 |
|
| 97 |
export const handlePurchasesHistoryAction = async (ctx: BotContext) => {
|
| 98 |
const telegramId = ctx.from?.id;
|
| 99 |
+
if (!telegramId || !authService.isUserLoggedIn(telegramId,ctx)) {
|
| 100 |
return {
|
| 101 |
message: messageManager.getMessage('auth_required'),
|
| 102 |
options: getMainMenuKeyboard()
|
src/bots/handlers/languageHandlers.ts
CHANGED
|
@@ -27,7 +27,7 @@ export const setupLanguageHandlers = (bot: any) => {
|
|
| 27 |
|
| 28 |
export const handleLanguageSelection = async (ctx: BotContext) => {
|
| 29 |
const telegramId = ctx.from?.id;
|
| 30 |
-
const isLoggedIn = authService.isUserLoggedIn(telegramId) ;
|
| 31 |
|
| 32 |
return {
|
| 33 |
message: "🌐 Choose your preferred language:\nاختر لغتك المفضلة:",
|
|
@@ -37,7 +37,7 @@ export const handleLanguageSelection = async (ctx: BotContext) => {
|
|
| 37 |
|
| 38 |
export const handleLanguageChange = async (ctx: BotContext, language: 'en' | 'ar') => {
|
| 39 |
const telegramId = ctx.from?.id;
|
| 40 |
-
const isLoggedIn = telegramId ? authService.isUserLoggedIn(telegramId) : false;
|
| 41 |
|
| 42 |
try {
|
| 43 |
// Update message manager language for current session
|
|
|
|
| 27 |
|
| 28 |
export const handleLanguageSelection = async (ctx: BotContext) => {
|
| 29 |
const telegramId = ctx.from?.id;
|
| 30 |
+
const isLoggedIn = authService.isUserLoggedIn(telegramId,ctx) ;
|
| 31 |
|
| 32 |
return {
|
| 33 |
message: "🌐 Choose your preferred language:\nاختر لغتك المفضلة:",
|
|
|
|
| 37 |
|
| 38 |
export const handleLanguageChange = async (ctx: BotContext, language: 'en' | 'ar') => {
|
| 39 |
const telegramId = ctx.from?.id;
|
| 40 |
+
const isLoggedIn = telegramId ? authService.isUserLoggedIn(telegramId,ctx) : false;
|
| 41 |
|
| 42 |
try {
|
| 43 |
// Update message manager language for current session
|
src/bots/handlers/mainMenuHandlers.ts
CHANGED
|
@@ -39,7 +39,7 @@ export const handleLoginAction = async (ctx: BotContext) => {
|
|
| 39 |
};
|
| 40 |
}
|
| 41 |
|
| 42 |
-
if (authService.isUserLoggedIn(telegramId)) {
|
| 43 |
return {
|
| 44 |
message: messageManager.getMessage('login_already_logged_in'),
|
| 45 |
options: getLoggedInMenuKeyboard()
|
|
@@ -55,7 +55,7 @@ export const handleLoginAction = async (ctx: BotContext) => {
|
|
| 55 |
};
|
| 56 |
}
|
| 57 |
|
| 58 |
-
let user = await authService.loginUser(telegramId );
|
| 59 |
|
| 60 |
if (user) {
|
| 61 |
logger.info(`User ${telegramId} logged in successfully`);
|
|
@@ -83,7 +83,7 @@ export const handleLoginAction = async (ctx: BotContext) => {
|
|
| 83 |
}
|
| 84 |
|
| 85 |
const { user: newUser, password } = await authService.createUser(telegramId, firstName, botId);
|
| 86 |
-
authService.setUserLoggedIn(telegramId, true);
|
| 87 |
|
| 88 |
logger.info(`New user ${telegramId} created successfully with bot ID ${botId}`);
|
| 89 |
return {
|
|
@@ -134,7 +134,7 @@ export const handleMainMenuAction = async (ctx: BotContext) => {
|
|
| 134 |
const name = ctx.from?.first_name || messageManager.getMessage('default_user_name');
|
| 135 |
const telegramId = ctx.from?.id;
|
| 136 |
|
| 137 |
-
if (telegramId && authService.isUserLoggedIn(telegramId)) {
|
| 138 |
return {
|
| 139 |
message: messageManager.getMessage('main_menu_welcome_back').replace('{name}', name),
|
| 140 |
options: getLoggedInMenuKeyboard()
|
|
|
|
| 39 |
};
|
| 40 |
}
|
| 41 |
|
| 42 |
+
if (authService.isUserLoggedIn(telegramId,ctx)) {
|
| 43 |
return {
|
| 44 |
message: messageManager.getMessage('login_already_logged_in'),
|
| 45 |
options: getLoggedInMenuKeyboard()
|
|
|
|
| 55 |
};
|
| 56 |
}
|
| 57 |
|
| 58 |
+
let user = await authService.loginUser(telegramId,ctx );
|
| 59 |
|
| 60 |
if (user) {
|
| 61 |
logger.info(`User ${telegramId} logged in successfully`);
|
|
|
|
| 83 |
}
|
| 84 |
|
| 85 |
const { user: newUser, password } = await authService.createUser(telegramId, firstName, botId);
|
| 86 |
+
authService.setUserLoggedIn(telegramId,ctx, true);
|
| 87 |
|
| 88 |
logger.info(`New user ${telegramId} created successfully with bot ID ${botId}`);
|
| 89 |
return {
|
|
|
|
| 134 |
const name = ctx.from?.first_name || messageManager.getMessage('default_user_name');
|
| 135 |
const telegramId = ctx.from?.id;
|
| 136 |
|
| 137 |
+
if (telegramId && authService.isUserLoggedIn(telegramId,ctx)) {
|
| 138 |
return {
|
| 139 |
message: messageManager.getMessage('main_menu_welcome_back').replace('{name}', name),
|
| 140 |
options: getLoggedInMenuKeyboard()
|