1+ import re
12from aiogram import Router , types , F
23from aiogram .filters import Command
34from aiogram .fsm .context import FSMContext
45from aiogram .fsm .state import State , StatesGroup
56from aiogram .types .message import Message
6-
77from services .llm import generate_study_plan , translate_text
88from services .pdf import save_plan_to_pdf
99from services .txt import save_plan_to_txt
1010from services .db import save_user_plan , get_user_plan , get_user_language
11- import re
1211
1312router = Router ()
1413
@@ -38,7 +37,9 @@ async def handle_topic(message: types.Message, state: FSMContext):
3837 topic = message .text .strip ()
3938
4039 # Send waiting message
41- await send_translated (message , "⏳ Please wait a moment. Generating your study plan..." )
40+ await send_translated (
41+ message , "⏳ Please wait a moment. Generating your study plan..."
42+ )
4243
4344 # Send "typing" action to show the bot is working
4445 if message .bot and message .chat and message .chat .id :
@@ -62,21 +63,26 @@ async def handle_topic(message: types.Message, state: FSMContext):
6263 await state .set_state (PlanFormat .waiting_for_format )
6364 user_id = message .from_user .id if message .from_user else 0
6465 user_lang = get_user_language (user_id ) or "en"
65- prompt = await translate_text ("In which format do you want to save the plan?" , user_lang )
66+ prompt = await translate_text (
67+ "In which format do you want to save the plan?" , user_lang
68+ )
6669 await send_translated (message , prompt )
6770 keyboard = types .InlineKeyboardMarkup (
6871 inline_keyboard = [
6972 [
7073 types .InlineKeyboardButton (
71- text = await translate_text ("📄 pdf" , user_lang ), callback_data = "format_pdf"
74+ text = await translate_text ("📄 pdf" , user_lang ),
75+ callback_data = "format_pdf" ,
7276 ),
7377 types .InlineKeyboardButton (
74- text = await translate_text ("📄 txt" , user_lang ), callback_data = "format_txt"
78+ text = await translate_text ("📄 txt" , user_lang ),
79+ callback_data = "format_txt" ,
7580 ),
7681 ],
7782 [
7883 types .InlineKeyboardButton (
79- text = await translate_text ("⏭ Skip" , user_lang ), callback_data = "format_skip"
84+ text = await translate_text ("⏭ Skip" , user_lang ),
85+ callback_data = "format_skip" ,
8086 )
8187 ],
8288 ]
@@ -135,27 +141,31 @@ async def show_next_actions(message: types.Message, state: FSMContext):
135141 await state .set_state (PlanFormat .waiting_for_next_action )
136142 user_id = message .from_user .id if message .from_user else 0
137143 user_lang = get_user_language (user_id ) or "en"
138- await send_translated (message , await translate_text ("What else would you like to do?" , user_lang ))
144+ await send_translated (
145+ message , await translate_text ("What else would you like to do?" , user_lang )
146+ )
139147 keyboard = types .InlineKeyboardMarkup (
140148 inline_keyboard = [
141149 [
142150 types .InlineKeyboardButton (
143151 text = await translate_text ("⏰ Schedule reminders" , user_lang ),
144- callback_data = "schedule_reminders"
152+ callback_data = "schedule_reminders" ,
145153 )
146154 ],
147155 [
148156 types .InlineKeyboardButton (
149157 text = await translate_text ("🔄 Create a new plan" , user_lang ),
150- callback_data = "new_plan"
158+ callback_data = "new_plan" ,
151159 )
152160 ],
153161 [
154162 types .InlineKeyboardButton (
155- text = await translate_text ("👋 Nothing, have a nice day!" , user_lang ),
156- callback_data = "goodbye"
163+ text = await translate_text (
164+ "👋 Nothing, have a nice day!" , user_lang
165+ ),
166+ callback_data = "goodbye" ,
157167 )
158- ]
168+ ],
159169 ]
160170 )
161171 await message .answer ("Choose your next action:" , reply_markup = keyboard )
@@ -254,13 +264,13 @@ async def send_translated(message, text):
254264 if user_lang != "en" :
255265 text = await translate_text (text , user_lang )
256266 # Clean/escape unsupported HTML/Markdown links and tags
257- text = re .sub (r' <(https?://[^>]+)>' , r'\1' , text )
258- text = re .sub (r' <([^ >]+)>' , r'\1' , text )
267+ text = re .sub (r" <(https?://[^>]+)>" , r"\1" , text )
268+ text = re .sub (r" <([^ >]+)>" , r"\1" , text )
259269 # If text is empty or only whitespace, send an informative message
260- if not text or text .strip () == '' :
270+ if not text or text .strip () == "" :
261271 await message .answer ("[Error] Empty text for user message." )
262272 return
263273 # If text is longer than Telegram limit, split into parts
264274 max_len = 4096
265275 for i in range (0 , len (text ), max_len ):
266- await message .answer (text [i : i + max_len ])
276+ await message .answer (text [i : i + max_len ])
0 commit comments