From fc8fa5a30bf464557051ac22a75ca83de3a29f7b Mon Sep 17 00:00:00 2001 From: Andrew Guschin Date: Wed, 29 Jun 2022 17:45:07 +0400 Subject: =?UTF-8?q?=D0=9E=D1=81=D0=BD=D0=BE=D0=B2=D0=BD=D0=BE=D0=B9=20?= =?UTF-8?q?=D1=81=D0=BA=D0=B5=D0=BB=D0=B5=D1=82=20=D0=B1=D0=BE=D1=82=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- views.py | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 views.py (limited to 'views.py') diff --git a/views.py b/views.py new file mode 100644 index 0000000..692af49 --- /dev/null +++ b/views.py @@ -0,0 +1,71 @@ +from telegram import Update, User, Bot # Typing +from telegram.ext import CallbackContext # Typing +from telegram import ReplyKeyboardMarkup, ReplyKeyboardRemove + +from enums import UtilStates, MainStates +from keyboards import MenuKeyboard, BACK + +class UtilViews: + @staticmethod + def start(update: Update, context: CallbackContext): + update.message.reply_text( + "Welcome to The Club.", + reply_markup=ReplyKeyboardRemove() + ) + + user: User = update.message.from_user + if user.username is None: + return UtilViews.wait_for_username(update, context) + else: + return MainStatesView.main_menu(update, context) + + + @staticmethod + def wait_for_username(update: Update, context: CallbackContext): + user: User = update.message.from_user + if user.username is None: + update.message.reply_text( + "Этим ботом можно пользоваться только с указанным именем пользователя." + "Укажи его и возвращайся как только это сделаешь.", + reply_markup=ReplyKeyboardMarkup([['Я указал имя пользователя']]) + ) + return UtilStates.WAIT_FOR_USERNAME + + else: + return MainStatesView.main_menu(update, context) + + @staticmethod + def fallback(update: Update, context: CallbackContext): + update.message.reply_text("Команда не распознана") + + +class MainStatesView: + @staticmethod + def main_menu(update: Update, context: CallbackContext): + update.message.reply_text( + "Выбери следующее действие...", + reply_markup=MenuKeyboard.get_keyboard() + ) + + return MainStates.MAIN_MENU + + @staticmethod + def new_client_name(update: Update, context: CallbackContext): + update.message.reply_text( + "Введи имя для клиента (чтобы ты мог отличить клиентов в списке).", + reply_markup=ReplyKeyboardMarkup([[BACK]]) + ) + return MainStates.ENTERING_NAME + + @staticmethod + def new_client(update: Update, context: CallbackContext): + client_name = update.message.text.strip() + update.message.reply_text(f"Клиент |{client_name}| успешно добавлен") + return MainStatesView.main_menu(update, context) + + + @staticmethod + def list_clients(update: Update, context: CallbackContext): + update.message.reply_text("Список клиентов:") + return MainStatesView.main_menu(update, context) + -- cgit v1.2.3