diff options
| author | Andrew Guschin <guschin.drew@gmail.com> | 2022-06-29 17:45:07 +0400 |
|---|---|---|
| committer | Andrew Guschin <guschin.drew@gmail.com> | 2022-06-29 17:45:07 +0400 |
| commit | fc8fa5a30bf464557051ac22a75ca83de3a29f7b (patch) | |
| tree | 39af088ddf259deb080f2f21f31d89c2206e6ab2 /bot.py | |
Diffstat (limited to 'bot.py')
| -rw-r--r-- | bot.py | 52 |
1 files changed, 52 insertions, 0 deletions
@@ -0,0 +1,52 @@ +from telegram.ext import Updater, CommandHandler, ConversationHandler, MessageHandler, Filters +from telegram import Update, User, Bot # Typing + +from config import TG_TOKEN + +from enums import UtilStates, MainStates +from views import UtilViews, MainStatesView +from keyboards import MenuKeyboard, BACK + +from logger_config import logger + + +def error(bot, update, error): + logger.warning('Update "%s" caused error "%s"', update, error) + + +def main(): + conversation = ConversationHandler( + entry_points=[ + CommandHandler('start', UtilViews.start), + ], + + states={ + UtilStates.WAIT_FOR_USERNAME: [MessageHandler(Filters.text, UtilViews.wait_for_username)], + MainStates.MAIN_MENU: [ + MessageHandler(Filters.regex(MenuKeyboard.NEW_CLIENT), MainStatesView.new_client_name), + MessageHandler(Filters.regex(MenuKeyboard.LIST_CLIENTS), MainStatesView.list_clients), + ], + MainStates.ENTERING_NAME: [ + MessageHandler(Filters.regex(BACK), MainStatesView.main_menu), + MessageHandler(Filters.text, MainStatesView.new_client), + ], + }, + + fallbacks=[ + MessageHandler(Filters.text, UtilViews.fallback), + ] + ) + + + updater = Updater(TG_TOKEN) + + dp = updater.dispatcher + dp.add_error_handler(error) + dp.add_handler(conversation) + + updater.start_polling() + updater.idle() + + +if __name__ == "__main__": + main() |