Skip to content

Commit

Permalink
sth tests
Browse files Browse the repository at this point in the history
  • Loading branch information
grachevvladislav committed Jul 7, 2023
1 parent 234a9cc commit 9fcdf59
Show file tree
Hide file tree
Showing 9 changed files with 90 additions and 30 deletions.
5 changes: 3 additions & 2 deletions src/bot/constants/back_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

from bot.constants.states.main_states import States
from bot.handlers.assistance import receive_assistance
from bot.handlers.assistance_types import contact_with_us, select_type_of_help
from bot.handlers.assistance_types import select_type_of_help, show_contacts
from bot.handlers.main_handlers import start

FUNCTIONS: dict[str, Callable[[Any, Any], Awaitable[States]]] = {
States.REGION.value: receive_assistance,
States.ASSISTANCE.value: start,
States.ASSISTANCE_TYPE: select_type_of_help,
States.CONTACT_US: contact_with_us,
States.CONTACT_US: show_contacts,
States.SELECT_CONTACT_TYPE: show_contacts,
}
3 changes: 1 addition & 2 deletions src/bot/constants/buttons.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Общие кнопки
BACK_BUTTON = "Назад"
CONTACT_US_BUTTON = "Связаться с нами"
ASK_QUESTION = "Задать свой вопрос"

# Кнопки для блока "Помочь или получить помощь"
ASSISTANCE_BUTTON = "Получить помощь"
Expand All @@ -11,7 +12,6 @@
SOCIAL_HELP_BUTTON = "Социальная помощь"
PSYCHOLOGICAL_HELP_BUTTON = "Психологическая помощь"
PROGRAMS_BUTTON = "Наши программы"
ASK_QUESTION = "Задать свой вопрос"

# Способы связи
EMAIL = "Эл. почта"
Expand All @@ -20,4 +20,3 @@

# кнопки для блока "связаться с нами"
CONTACTS = "Контакты"
SEND_REQUEST = "Отправить запрос"
1 change: 1 addition & 0 deletions src/bot/constants/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
CONTACT_US_MESSAGE = "[Заглушка] Задать вопрос."

ASK_YOUR_QUESTION = "Задайте Ваш вопрос"
HOW_TO_CONTACT = "Как Вам удобно связаться с нами?"
WHAT_IS_YOUR_NAME_MESSAGE = "Как к Вам обращаться?"
CONTACT_TYPE_MESSAGE = "{name}, как с Вами связаться?"
THANKS_FOR_THE_QUESTION = (
Expand Down
4 changes: 3 additions & 1 deletion src/bot/constants/states/main_states.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,7 @@ class States(str, enum.Enum):
ASK_QUESTION = "ask_question"

CONTACT_US = "contact_us"
SELECTED_TYPE = "selected_type"
SELECT_CONTACT_TYPE = "selected_type"
SHOW_CONTACT = "show_contact"

QUESTIONS_AND_CONTACTS = "questions_and_contacts"
7 changes: 4 additions & 3 deletions src/bot/handlers/assistance.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from bot.constants.messages import ASK_YOUR_QUESTION, ASSISTANCE_MESSAGE
from bot.constants.states.main_states import States
from bot.keyboards.assistance import (
assistance_questions_keyboard_contact,
contact_type_keyboard_markup,
region_keyboard_markup,
)

Expand All @@ -30,9 +30,10 @@ async def contact_with_us_assistance(
await query.answer()
await query.edit_message_text(
text=Contacts[context.user_data[States.REGION]].value,
reply_markup=assistance_questions_keyboard_contact,
reply_markup=contact_type_keyboard_markup,
)
return States.SELECTED_TYPE
print(States.SELECT_CONTACT_TYPE)
return States.SELECT_CONTACT_TYPE


async def ask_question_assistance(
Expand Down
12 changes: 6 additions & 6 deletions src/bot/handlers/assistance_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from bot.constants.regions import Regions
from bot.constants.states.main_states import States
from bot.keyboards.assistance import (
assistance_questions_keyboard_contact,
assistance_questions_keyboard_markup,
contact_show_keyboard_markup,
region_keyboard_markup,
)
Expand Down Expand Up @@ -41,7 +41,7 @@ async def selected_type_assistance(
text="Выбор вопроса из списка",
reply_markup=assistance_questions_keyboard_markup,
)
return States.SELECTED_TYPE
return States.QUESTIONS_AND_CONTACTS


async def fund_programs(update: Update, context: ContextTypes.DEFAULT_TYPE):
Expand All @@ -61,17 +61,17 @@ async def back_to_region(
return States.REGION


async def contact_with_us(
async def show_contacts(
update: Update, context: ContextTypes.DEFAULT_TYPE
) -> States:
"""Связаться с нами."""
query = update.callback_query
await query.answer()
await query.edit_message_text(
text="Выбор вопроса из списка",
reply_markup=assistance_questions_keyboard_contact,
text="Список контактов \n8-800-555-35-35",
reply_markup=assistance_questions_keyboard_markup,
)
return States.SELECTED_TYPE
return States.SELECT_CONTACT_TYPE


async def show_contact(
Expand Down
46 changes: 38 additions & 8 deletions src/bot/keyboards/assistance.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
BACK_BUTTON,
CONTACTS,
DONATION_BUTTON,
SEND_REQUEST,
)
from bot.constants.list_of_questions import LegalQuestions
from bot.constants.regions import Regions
from bot.constants.states.main_states import States
from bot.constants.urls import DONATION_URL

# assistance_keyboard

assistance_keyboard = [
[
InlineKeyboardButton(
Expand All @@ -24,6 +25,10 @@
],
]

assistance_keyboard_markup = InlineKeyboardMarkup(assistance_keyboard)

# region_keyboard

region_keyboard = [
[InlineKeyboardButton(region.value, callback_data=region.name)]
for region in Regions
Expand All @@ -37,6 +42,10 @@
]
)

region_keyboard_markup = InlineKeyboardMarkup(region_keyboard)

# contact_keyboard

contact_keyboard = [
[
InlineKeyboardButton(
Expand All @@ -50,19 +59,31 @@
],
]

contact_show_keyboard = [
contact_keyboard_markup = InlineKeyboardMarkup(contact_keyboard)

# contact_show_keyboard

contact_type_keyboard = [
[
InlineKeyboardButton(
SEND_REQUEST, callback_data=States.ASK_QUESTION.value
ASK_QUESTION, callback_data=States.ASK_QUESTION.value
),
],
[
InlineKeyboardButton(CONTACTS, callback_data=States.CONTACT_US.value),
],
[
InlineKeyboardButton(
BACK_BUTTON,
callback_data=f"back_to_{States.ASSISTANCE_TYPE.value}",
)
],
]

contact_type_keyboard_markup = InlineKeyboardMarkup(contact_type_keyboard)

# contact_questions_keyboard

contact_questions_keyboard = [
[InlineKeyboardButton(question.value, callback_data=question.name)]
for question in LegalQuestions
Expand All @@ -86,10 +107,19 @@
)


assistance_keyboard_markup = InlineKeyboardMarkup(assistance_keyboard)
region_keyboard_markup = InlineKeyboardMarkup(region_keyboard)
contact_keyboard_markup = InlineKeyboardMarkup(contact_keyboard)
contact_show_keyboard_markup = InlineKeyboardMarkup(contact_show_keyboard)
assistance_questions_keyboard_contact = InlineKeyboardMarkup(
assistance_questions_keyboard_markup = InlineKeyboardMarkup(
contact_questions_keyboard
)

# contact_show_keyboard

contact_show_keyboard = [
[
InlineKeyboardButton(
text=BACK_BUTTON,
callback_data=f"back_to_{States.SELECT_CONTACT_TYPE.value}",
)
]
]

contact_show_keyboard_markup = InlineKeyboardMarkup(contact_show_keyboard)
20 changes: 16 additions & 4 deletions src/bot/keyboards/assistance_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
from bot.constants.states.main_states import States
from bot.constants.types_of_assistance import AssistanceTypes

# assistance_types_keyboard

assistance_types_keyboard = [
[
InlineKeyboardButton(
Expand Down Expand Up @@ -49,11 +51,25 @@
],
]

assistance_types_keyboard_markup = InlineKeyboardMarkup(
assistance_types_keyboard
)

# assistance_questions_keyboard

assistance_questions_keyboard = [
[InlineKeyboardButton(question.value, callback_data=question.name)]
for question in LegalQuestions
]

assistance_questions_keyboard.append(
[
InlineKeyboardButton(
text=CONTACT_US_BUTTON, callback_data=States.CONTACT_US.value
)
]
)

assistance_questions_keyboard.append(
[
InlineKeyboardButton(
Expand All @@ -72,10 +88,6 @@
)


assistance_types_keyboard_markup = InlineKeyboardMarkup(
assistance_types_keyboard
)

assistance_questions_keyboard_markup = InlineKeyboardMarkup(
assistance_questions_keyboard
)
22 changes: 18 additions & 4 deletions src/run_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@
receive_assistance,
)
from bot.handlers.assistance_types import (
contact_with_us,
fund_programs,
select_type_of_help,
selected_type_assistance,
show_contact,
show_contacts,
)
from bot.handlers.back_handler import back_button
from bot.handlers.main_handlers import help_handler, start_handler
Expand Down Expand Up @@ -127,9 +127,19 @@ def main():
pattern=PATTERN.format(state=States.CONTACT_US.value),
),
],
States.QUESTIONS_AND_CONTACTS: [
CallbackQueryHandler(
ask_question_assistance,
pattern=PATTERN.format(state=States.ASK_QUESTION.value),
),
CallbackQueryHandler(
ask_question_assistance,
pattern=PATTERN.format(state=States.CONTACT_US.value),
),
],
States.CONTACT_US: [
CallbackQueryHandler(
contact_with_us,
show_contact,
pattern=PATTERN.format(state=States.CONTACT_US.value),
)
],
Expand All @@ -139,11 +149,15 @@ def main():
pattern=PATTERN.format(state=States.SHOW_CONTACT.value),
)
],
States.SELECTED_TYPE: [
States.SELECT_CONTACT_TYPE: [
CallbackQueryHandler(
ask_question_assistance,
pattern=PATTERN.format(state=States.ASK_QUESTION.value),
)
),
CallbackQueryHandler(
show_contacts,
pattern=PATTERN.format(state=States.CONTACT_US.value),
),
],
States.ASK_QUESTION: [ask_question_handler],
},
Expand Down

0 comments on commit 9fcdf59

Please sign in to comment.