diff --git a/src/admin.py b/src/admin.py index 29b231e..e39bca9 100644 --- a/src/admin.py +++ b/src/admin.py @@ -15,7 +15,7 @@ from kb_builder import back_btn, main_kb from resources.TEXT_MESSAGES import (BUG_TEXT, DEVS_TEXT, DONE_TEXT, HELLO_MESSAGE, IDEA_TEXT, - OUR_PRODUCTS_TEXT, SUPPORT_TEXT) + OUR_PRODUCTS_TEXT, SUPPORT_TEXT, INCORRECT_INPUT_FORMAT_ERROR) from send_data import send_messages from send_logs import send_log_to_dev from StatesGroup import GetBug, GetIdea @@ -66,7 +66,7 @@ async def send_admin_answer(message: Message): parts = message.text.split(" | ") if len(parts) != 3: - logger.error("Incorrect input format") + logger.error(INCORRECT_INPUT_FORMAT_ERROR) else: client_id = parts[1] source_message = parts[2] diff --git a/src/client.py b/src/client.py index f9b109d..061e0be 100644 --- a/src/client.py +++ b/src/client.py @@ -21,7 +21,7 @@ @dp.callback_query(F.data == "SuggestIdea") -async def GetUserIdea(callback: types.CallbackQuery, state: FSMContext): +async def get_users_idea(callback: types.CallbackQuery, state: FSMContext): try: await state.set_state(GetIdea.wait_for_message) logger.debug(f"{callback.message.chat.id} - idea suggest") @@ -42,7 +42,7 @@ async def GetUserIdea(callback: types.CallbackQuery, state: FSMContext): @dp.callback_query(F.data == "BugReport") -async def GetUserBug(callback: types.CallbackQuery, state: FSMContext): +async def get_users_bug(callback: types.CallbackQuery, state: FSMContext): try: await state.set_state(GetBug.wait_for_message) logger.debug(f"{callback.message.chat.id} - bug report") @@ -63,7 +63,7 @@ async def GetUserBug(callback: types.CallbackQuery, state: FSMContext): @dp.message(GetIdea.wait_for_message) -async def IdeaUserMessage(message: Message, state: FSMContext): +async def user_message_idea(message: Message, state: FSMContext): try: username = message.from_user.username logger.debug(f"Idea suggest from {username}: {message.text}") @@ -93,7 +93,7 @@ async def IdeaUserMessage(message: Message, state: FSMContext): @dp.message(GetBug.wait_for_message) -async def BugUserMessage(message: types.Message, state: FSMContext): +async def user_message_bug(message: types.Message, state: FSMContext): try: username = message.from_user.username logger.debug(f"Bug report from {username}: {message.text}") @@ -125,8 +125,6 @@ async def BugUserMessage(message: types.Message, state: FSMContext): @dp.message(GetIdea.done) async def send_done_message_idea(message: types.Message, state: FSMContext): try: - username = message.from_user.username - user_id = message.from_user.id logger.debug(await message.answer(DONE_TEXT)) except Exception as err: @@ -137,8 +135,6 @@ async def send_done_message_idea(message: types.Message, state: FSMContext): @dp.message(GetBug.done) async def send_done_message_bug(message: types.Message, state: FSMContext): try: - username = message.from_user.username - user_id = message.from_user.id logger.debug(await message.answer(DONE_TEXT)) except Exception as err: @@ -147,7 +143,7 @@ async def send_done_message_bug(message: types.Message, state: FSMContext): @dp.callback_query(F.data == "Back") -async def BackToStartMenu(callback: types.CallbackQuery, state: FSMContext): +async def back_to_menu(callback: types.CallbackQuery, state: FSMContext): try: logger.debug(f"{callback.message.chat.id} - back button") message_id = callback.message.message_id @@ -170,7 +166,7 @@ async def BackToStartMenu(callback: types.CallbackQuery, state: FSMContext): @dp.callback_query(F.data == "Contacts") -async def Contacts(callback: types.CallbackQuery): +async def contacts(callback: types.CallbackQuery): try: user_id = callback.from_user.id logger.debug(f"{user_id} - contacts") @@ -191,7 +187,7 @@ async def Contacts(callback: types.CallbackQuery): @dp.callback_query(F.data == "OurProducts") -async def OurProducts(callback: types.CallbackQuery): +async def our_products(callback: types.CallbackQuery): try: user_id = callback.from_user.id logger.debug(f"{user_id} - our products") @@ -213,7 +209,7 @@ async def OurProducts(callback: types.CallbackQuery): @dp.callback_query(F.data == "SupportMe") -async def SupportMe(callback: types.CallbackQuery): +async def support_me(callback: types.CallbackQuery): try: user_id = callback.from_user.id logger.debug(f"{user_id} - support me") diff --git a/src/resources/TEXT_MESSAGES.py b/src/resources/TEXT_MESSAGES.py index bb5c2d0..5f0e699 100644 --- a/src/resources/TEXT_MESSAGES.py +++ b/src/resources/TEXT_MESSAGES.py @@ -50,3 +50,5 @@ `UQCF-sPDO0QqkNtvy5CKSvYWEsZS6l7vzaytV36oYM0SNhKt` """ + +INCORRECT_INPUT_FORMAT_ERROR = "Incorrect input format" diff --git a/src/send_data.py b/src/send_data.py index 541ab47..c1fa54f 100644 --- a/src/send_data.py +++ b/src/send_data.py @@ -12,6 +12,8 @@ from db.check_for_qsl_injection import is_sql_injection_attempt from db.db import get_id_by_message, create_connection +DEFAULT_CAPTION = "No description provided." + async def send_messages(message: types.Message, username: str, status: str, date: str): forward_text = "" channel_message = ( @@ -24,34 +26,34 @@ async def send_messages(message: types.Message, username: str, status: str, date if message.text: forward_text += message.text - id = await get_id_by_message(await create_connection(), forward_text, date, message.from_user.id, status.lower()) - channel_message += f"`/set_ticket_status | {id} | {status.lower()} | status`\n" - channel_message += f"`/get_ticket_status | {id} | {status.lower()}`\n" + message_id = await get_id_by_message(await create_connection(), forward_text, date, message.from_user.id, status.lower()) + channel_message += f"`/set_ticket_status | {message_id} | {status.lower()} | status`\n" + channel_message += f"`/get_ticket_status | {message_id} | {status.lower()}`\n" if message.photo: photo = message.photo[-1] - caption = message.caption if message.caption else "No description provided." - id = await get_id_by_message(await create_connection(), caption, date, message.from_user.id, status.lower()) - channel_message += f"`/set_ticket_status | {id} | {status.lower()} | status`\n" - channel_message += f"`/get_ticket_status | {id} | {status.lower()}`\n" + caption = message.caption if message.caption else DEFAULT_CAPTION + message_id = await get_id_by_message(await create_connection(), caption, date, message.from_user.id, status.lower()) + channel_message += f"`/set_ticket_status | {message_id} | {status.lower()} | status`\n" + channel_message += f"`/get_ticket_status | {message_id} | {status.lower()}`\n" channel_message += f"\n🔥 Report: {caption}" await bot.send_photo(chat_id=CHANNEL, photo=photo.file_id, caption=channel_message, parse_mode="Markdown") elif message.document: document = message.document - caption = message.caption if message.caption else "No description provided." - id = await get_id_by_message(await create_connection(), caption, date, message.from_user.id, status.lower()) - channel_message += f"`/set_ticket_status | {id} | {status.lower()} | status`\n" - channel_message += f"`/get_ticket_status | {id} | {status.lower()}`\n" + caption = message.caption if message.caption else DEFAULT_CAPTION + message_id = await get_id_by_message(await create_connection(), caption, date, message.from_user.id, status.lower()) + channel_message += f"`/set_ticket_status | {message_id} | {status.lower()} | status`\n" + channel_message += f"`/get_ticket_status | {message_id} | {status.lower()}`\n" channel_message += f"\n🔥 Report: {caption}" await bot.send_document(chat_id=CHANNEL, document=document.file_id, caption=channel_message, parse_mode="Markdown") elif message.video: video = message.video - caption = message.caption if message.caption else "No description provided." - id = await get_id_by_message(await create_connection(), caption, date, message.from_user.id, status.lower()) - channel_message += f"`/set_ticket_status | {id} | {status.lower()} | status`\n" - channel_message += f"`/get_ticket_status | {id} | {status.lower()}`\n" + caption = message.caption if message.caption else DEFAULT_CAPTION + message_id = await get_id_by_message(await create_connection(), caption, date, message.from_user.id, status.lower()) + channel_message += f"`/set_ticket_status | {message_id} | {status.lower()} | status`\n" + channel_message += f"`/get_ticket_status | {message_id} | {status.lower()}`\n" channel_message += f"\n🔥 Report: {caption}" await bot.send_video(chat_id=CHANNEL, video=video.file_id, caption=channel_message, parse_mode="Markdown")