Refactor bot username retrieval in bulk promo code creation
- Updated the logic to retrieve the bot username dynamically, enhancing the accuracy of CSV links for promo codes. - Improved error handling to log failures in fetching the bot username, ensuring better traceability. - Adjusted the promo code service initialization in the start command handler to use the message context, improving consistency in bot interactions.
This commit is contained in:
@@ -439,8 +439,19 @@ async def create_bulk_promo_codes_final(callback_or_message,
|
|||||||
"Команда для старта", "Ссылка для активации"
|
"Команда для старта", "Ссылка для активации"
|
||||||
])
|
])
|
||||||
|
|
||||||
# Add bot username from settings
|
# Get real bot username
|
||||||
bot_username = getattr(settings, 'BOT_USERNAME', 'your_bot')
|
bot_username = 'your_bot' # fallback
|
||||||
|
try:
|
||||||
|
if hasattr(callback_or_message, 'message'):
|
||||||
|
bot = callback_or_message.message.bot
|
||||||
|
else:
|
||||||
|
bot = callback_or_message.bot
|
||||||
|
|
||||||
|
bot_info = await bot.get_me()
|
||||||
|
bot_username = bot_info.username or 'your_bot'
|
||||||
|
except Exception as e:
|
||||||
|
logging.error(f"Failed to get bot username for CSV links: {e}")
|
||||||
|
bot_username = 'your_bot'
|
||||||
|
|
||||||
for code in created_codes:
|
for code in created_codes:
|
||||||
# Determine validity info
|
# Determine validity info
|
||||||
|
|||||||
@@ -224,7 +224,7 @@ async def start_command_handler(message: types.Message,
|
|||||||
if promo_code_to_apply:
|
if promo_code_to_apply:
|
||||||
try:
|
try:
|
||||||
from bot.services.promo_code_service import PromoCodeService
|
from bot.services.promo_code_service import PromoCodeService
|
||||||
promo_code_service = PromoCodeService(settings, subscription_service, bot, i18n)
|
promo_code_service = PromoCodeService(settings, subscription_service, message.bot, i18n)
|
||||||
|
|
||||||
success, result = await promo_code_service.apply_promo_code(
|
success, result = await promo_code_service.apply_promo_code(
|
||||||
session, user_id, promo_code_to_apply, current_lang
|
session, user_id, promo_code_to_apply, current_lang
|
||||||
|
|||||||
Reference in New Issue
Block a user