diff --git a/app/telegram/functions/main_settings/settings.py b/app/telegram/functions/main_settings/settings.py index 92ee946..df7e2c3 100644 --- a/app/telegram/functions/main_settings/settings.py +++ b/app/telegram/functions/main_settings/settings.py @@ -15,6 +15,34 @@ logger = logging.getLogger("main_settings") router_main_settings = Router() +def is_number(value: str) -> bool: + """ + Checks if a given string represents a number. + + Args: + value (str): The string to check. + + Returns: + bool: True if the string represents a number, False otherwise. + """ + try: + # Convert the string to a float + num = float(value) + # Check if the number is positive + if num <= 0: + return False + # Check if the string contains "+" or "-" + if "+" in value or "-" in value: + return False + # Check if the string contains only digits + allowed_chars = set("0123456789.") + if not all(ch in allowed_chars for ch in value): + return False + return True + except ValueError: + return False + + async def reg_new_user_default_main_settings(id, message): tg_id = id @@ -124,7 +152,6 @@ async def state_trading_mode(callback: CallbackQuery, state): logger.error("Ошибка при обновлении режима торговли: %s", e) - async def switch_mode_enabled_message(message, state): await state.set_state(update_main_settings.switch_mode_enabled) @@ -304,7 +331,7 @@ async def state_starting_quantity(message: Message, state): data = await state.get_data() data_settings = await rq.get_user_main_settings(message.from_user.id) - if data['starting_quantity'].isdigit(): + if is_number(data['starting_quantity']): await message.answer(f"✅ Изменено: {data_settings['starting_quantity']} → {data['starting_quantity']}") await rq.update_starting_quantity(message.from_user.id, data['starting_quantity']) @@ -345,4 +372,4 @@ async def state_maximal_quantity(message: Message, state): f'⛔️ Ошибка: ваше значение ({val}) или выше лимита (100) или вы вводите неверные символы') logger.error(f'⛔️ Ошибка: ваше значение ({val}) или выше лимита (100) или вы вводите неверные символы') - await main_settings_message(message.from_user.id, message) \ No newline at end of file + await main_settings_message(message.from_user.id, message)