def event_token_handler( self, update: Update, _: CallbackContext, ) -> NoReturn: event_token = update.effective_message.text user_id = update.effective_user.id try: self._splitwise.get_event_info(event_token) except KeyError: update.effective_chat.send_message( 'Мероприятия с таким токеном не существует. ' 'Введи корректный токен или нажми кнопку \'Отмена\'', reply_markup=buttons.get_cancel_button()) return None if self._splitwise.user_participates_in_event(user_id, event_token): update.effective_chat.send_message( 'Не прокатит! Ты уже зарегистрирован в этом мероприятии') update.effective_chat.send_message( 'Меню:', reply_markup=buttons.get_menu_keyboard()) return ConversationHandler.END self._splitwise.add_user_to_event(user_id, event_token) update.effective_chat.send_message( 'Ты успешно присоединился к мероприятию') update.effective_chat.send_message( 'Меню:', reply_markup=buttons.get_menu_keyboard()) return ConversationHandler.END
def get_menu( self, update: Update, _: CallbackContext, ): update.effective_chat.send_message( 'Меню:', reply_markup=buttons.get_menu_keyboard())
def text_handler( self, update: Update, _: CallbackContext, ): update.effective_chat.send_message('Выберите пункт меню:') update.effective_chat.send_message( 'Меню:', reply_markup=buttons.get_menu_keyboard())
def callback_handler( self, update: Update, _: CallbackContext, ): if update.callback_query.data == menu_items.CANCEL: update.callback_query.edit_message_text('Меню:') update.callback_query.edit_message_reply_markup( reply_markup=buttons.get_menu_keyboard()) return ConversationHandler.END else: update.callback_query.answer('Не на ту кнопку жмешь', )
def callback_query_handler( self, update: Update, context: CallbackContext, ) -> NoReturn: data = update.callback_query.data event_token = context.user_data[States.CURRENT_EVENT_TOKEN] event = self._splitwise.get_event_info(event_token) user_id = update.effective_user.id if data == menu_items.SHOW_DEBTS: lenders_info, debtors_info = self._splitwise.get_final_transactions( event_token) if user_id in debtors_info: update.callback_query.edit_message_text( 'Вы должны: \n' + str(debtors_info[user_id]) + f'\n\n {event.name}\nВыберите пункт меню:') elif user_id in lenders_info: update.callback_query.edit_message_text( 'Вам должны: \n' + str(lenders_info[user_id]) + f'\n\n {event.name}\nВыберите пункт меню:') else: update.callback_query.edit_message_text( 'Вы никому не должны и вам никто не должен!!!' + f'\n\n {event.name}\nВыберите пункт меню:') update.callback_query.edit_message_reply_markup( reply_markup=buttons.get_event_commands_keyboard()) update.callback_query.answer() return States.EVENT_ACTIONS elif data == menu_items.ADD_EXPENSE: event_token = context.user_data[States.CURRENT_EVENT_TOKEN] try: self._splitwise.get_event_info(event_token) except KeyError: update.effective_chat.send_message( 'Мероприятия с таким токеном не существует. Повторите создание траты:' ) return ConversationHandler.END expense = Expense() expense.event_token = event_token expense.lender_id = user_id context.user_data[States.EXPENSE] = expense update.callback_query.edit_message_text( 'Введи название траты или нажми \'Отмена\'', reply_markup=buttons.get_cancel_button()) return States.EXPENSE_NAME elif data == menu_items.CANCEL: del context.user_data[States.CURRENT_EVENT_TOKEN] update.callback_query.edit_message_text('Меню:') update.callback_query.edit_message_reply_markup( reply_markup=buttons.get_menu_keyboard()) update.callback_query.answer() return ConversationHandler.END
def event_name_handler( self, update: Update, _: CallbackContext, ) -> NoReturn: event_name = update.effective_message.text event_token = self._splitwise.create_event( user_id=update.effective_user.id, event_name=event_name, ) update.effective_chat.send_message( f'Мероприятие "{event_name}" создано. Токен: `{event_token}`', parse_mode=ParseMode.MARKDOWN) update.effective_chat.send_message( 'Меню:', reply_markup=buttons.get_menu_keyboard()) return ConversationHandler.END
def start_handler( self, update: Update, _: CallbackContext, ) -> NoReturn: id_ = update.effective_user.id name = update.effective_user.username if self._splitwise.user_exists(id_): name = self._splitwise.get_user_info(id_).name update.effective_chat.send_message( f'Привет, {name}! Ты уже был(а) здесь!') else: self._splitwise.add_new_user(User(id_, name)) update.effective_chat.send_message( f'Привет, {name}! Ты здесь впервые!') update.effective_chat.send_message( 'Меню:', reply_markup=buttons.get_menu_keyboard())
def asking_for_action( self, update: Update, context: CallbackContext, ): if update.callback_query.data == menu_items.CANCEL: context.user_data.pop(States.CURRENT_EVENT_TOKEN, None) update.callback_query.edit_message_text('Меню:') update.callback_query.edit_message_reply_markup( reply_markup=buttons.get_menu_keyboard()) update.callback_query.answer() return ConversationHandler.END event_token = update.callback_query.data context.user_data[States.CURRENT_EVENT_TOKEN] = event_token event = self._splitwise.get_event_info(event_token) update.callback_query.edit_message_text( f'{event.name}\nВыберите пункт меню:') update.callback_query.edit_message_reply_markup( reply_markup=buttons.get_event_commands_keyboard()) update.callback_query.answer() return States.EVENT_ACTIONS