def confirm_edit(message): Chat.set(message) memory = Chat.get(message).memory.split(separator) if memory[3] == commands.remove and memory[4] == commands.yes: try: if memory[1] == commands.categories: Category.remove(message) elif memory[1] == commands.positions: Position.remove(message) except Exception as e: print(e) msg = messages.error else: msg = messages.deleted elif memory[3] == commands.rename: try: if memory[1] == commands.categories: Category.set_name(message) elif memory[1] == commands.positions: Position.set_name(message) except Exception as e: print(e) msg = messages.error else: msg = messages.renamed else: msg = messages.error Chat.reset(message) markup = get_markup(message) bot.send_message(message.chat.id, msg, reply_markup=markup)
def select_category(message): Chat.set(message) Category.add(message) memory = Chat.get(message).memory.split(separator) markup = get_markup(message) if memory[0] == commands.main_menu.expense and len(memory) == 2: msg = messages.select_subcategory next_step = bot.send_message(message.chat.id, msg, reply_markup=markup) bot.register_next_step_handler(next_step, select_category) else: msg = messages.input_value next_step = bot.send_message(message.chat.id, msg, reply_markup=markup) bot.register_next_step_handler(next_step, input_value)
def get_markup(message): markup = types.ReplyKeyboardMarkup(one_time_keyboard=True, resize_keyboard=True) memory = Chat.get(message).memory.split(separator) if memory[0] == commands.none: for category in Category.get_all(message): markup.row(category) elif memory[0] == commands.report: if len(memory) == 1: for year in Transaction.get_years(message): markup.row(year) if len(memory) == 2: for month in Transaction.get_months(message): markup.row(month) elif memory[0] == commands.edit: markup.row(commands.categories) markup.row(commands.positions) elif len(memory) == 1: for position in Position.get_all_in_category(message): markup.row(position) if memory[0] != commands.none: markup.row(commands.cancel) else: markup.row(commands.report) markup.row(commands.edit) return markup
def process_message(message): Chat.set(message) markup = get_markup(message) if message.text == commands.report: msg = messages.select_year next_step = bot.send_message(message.chat.id, msg, reply_markup=markup) bot.register_next_step_handler(next_step, select_year) elif message.text == commands.edit: msg = messages.select_edit next_step = bot.send_message(message.chat.id, msg, reply_markup=markup) bot.register_next_step_handler(next_step, select_edit) else: Category.add(message) msg = messages.select_position next_step = bot.send_message(message.chat.id, msg, reply_markup=markup) bot.register_next_step_handler(next_step, select_position)
def get_markup(message): markup = types.ReplyKeyboardMarkup(one_time_keyboard=True, resize_keyboard=True) memory = Chat.get(message).memory.split(separator) if memory[0] == commands.none: for command in commands.main_menu.values(): markup.row(command) elif memory[0] == commands.main_menu.report: if len(memory) == 1: for year in Transaction.get_years(message): markup.row(year) if len(memory) == 2: for month in Transaction.get_months(message): markup.row(month) elif memory[0] in commands.main_menu.values(): if memory[0] == commands.main_menu.expense and len(memory) == 2: for category in Category.get_subcategories(message): markup.row(category) elif len(memory) == 1: for category in Category.get_all(message): markup.row(category) if memory[0] != commands.none: markup.row(commands.cancel) return markup
def select_pos(message): Chat.set(message) markup = types.ReplyKeyboardMarkup(one_time_keyboard=True, resize_keyboard=True) if message.text in Category.get_all(message)\ or Position.get_all(message) or Transaction.get_all(message): msg = messages.select_edit markup.row(commands.rename) markup.row(commands.remove) markup.row(commands.cancel) next_step = bot.send_message(message.chat.id, msg, reply_markup=markup) bot.register_next_step_handler(next_step, select_what_to_do) else: msg = messages.try_again memory = Chat.get(message).memory.split(separator) if memory[1] == commands.categories: res = Category.get_all(message) else: res = Position.get_all(message) for pos in res: markup.row(pos) markup.row(commands.cancel) next_step = bot.send_message(message.chat.id, msg, reply_markup=markup) bot.register_next_step_handler(next_step, select_pos)
def select_edit(message): Chat.set(message) markup = types.ReplyKeyboardMarkup(one_time_keyboard=True, resize_keyboard=True) memory = Chat.get(message).memory.split(separator) if memory[1] == commands.categories: res = Category.get_all(message) else: res = Position.get_all(message) for pos in res: markup.row(pos) markup.row(commands.cancel) if message.text == commands.categories or commands.positions: if message.text == commands.categories: msg = messages.select_category_to_edit else: msg = messages.select_position_to_edit next_step = bot.send_message(message.chat.id, msg, reply_markup=markup) bot.register_next_step_handler(next_step, select_pos) else: msg = messages.try_again next_step = bot.send_message(message.chat.id, msg, reply_markup=markup) bot.register_next_step_handler(next_step, select_edit)