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_position(message): Chat.set(message) Position.add(message) msg = messages.input_value markup = get_markup(message) next_step = bot.send_message(message.chat.id, msg, reply_markup=markup) bot.register_next_step_handler(next_step, input_value)
def input_value(message): if not Transaction.add(message): msg = messages.try_again next_step = bot.send_message(message.chat.id, msg) bot.register_next_step_handler(next_step, input_value) else: Chat.reset(message) msg = messages.transaction_success 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 select_what_to_do(message): Chat.set(message) markup = types.ReplyKeyboardMarkup(one_time_keyboard=True, resize_keyboard=True) if message.text == commands.rename or commands.remove: if message.text == commands.rename: msg = messages.enter_new_name else: msg = messages.confirm_delete markup.row(commands.yes) markup.row(commands.cancel) next_step = bot.send_message(message.chat.id, msg, reply_markup=markup) bot.register_next_step_handler(next_step, confirm_edit) 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_what_to_do)
def set_balance(message): if Chat.add(message): msg = messages.new_wallet_created markup = get_markup(message) bot.send_message(message.chat.id, msg, reply_markup=markup) else: msg = messages.try_again next_step = bot.send_message(message.chat.id, msg) bot.register_next_step_handler(next_step, set_balance)
def wrapper(message): if not User.get(message): if not User.add(message): msg = messages.error_adding_user bot.send_message(message.chat.id, msg) if not Chat.get(message): msg = messages.creating_new_wallet next_step = bot.send_message(message.chat.id, msg) return bot.register_next_step_handler(next_step, set_balance) return func(message)
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)
def process_message(message): if message.text in commands.main_menu.values(): Chat.set(message) if message.text == commands.main_menu.report: msg = messages.select_year markup = get_markup(message) 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.main_menu.balance: Chat.reset(message) msg = Chat.get(message).balance + ' ' + currency markup = get_markup(message) bot.send_message(message.chat.id, msg, reply_markup=markup) else: msg = messages.select_category markup = get_markup(message) next_step = bot.send_message(message.chat.id, msg, reply_markup=markup) bot.register_next_step_handler(next_step, select_category) else: msg = messages.error markup = get_markup(message) bot.send_message(message.chat.id, msg, reply_markup=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 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_year(message): Chat.set(message) msg = messages.select_month markup = get_markup(message) next_step = bot.send_message(message.chat.id, msg, reply_markup=markup) bot.register_next_step_handler(next_step, select_month)
def process_cancel(message): Chat.reset(message) msg = messages.memory_cleared bot.send_message(message.chat.id, msg, reply_markup=get_markup(message))
def select_month(message): Chat.set(message) msg = Transaction.get_report(message) Chat.reset(message) markup = get_markup(message) bot.send_message(message.chat.id, msg, reply_markup=markup)