def write_stats(bot, update): dp.remove_handler(text_handler) dp.remove_handler(none_work_handler) sql = SQL_worker(database=config.database_name) current_tasks = len( (str(sql.select_task(chat_id)).replace("('", '').replace("',)", '')).split(' ^$^ ')) stats = (str(sql.select_stats(chat_id)).replace("('", '').replace("',)", '')).split('/') try: temp = int(update.message.text) if current_tasks < temp: bot.send_message(chat_id=update.message.chat_id, text="Wrong value") stats[0] = str(int(stats[0]) + temp) stats[1] = str(int(stats[1]) + current_tasks) stats = "/".join(stats) sql.write_new_stats(stats=stats, user_id=update.message.chat_id) sql.write_new_task(task=locale.no_tasks, user_id=update.message.chat_id) bot.send_message(chat_id=update.message.chat_id, text=locale.done) except Exception: bot.send_message(chat_id=update.message.chat_id, text="Something went wrong. I don't understand you.")
def new_day(bot, job): sql = SQL_worker(database=config.database_name) current_tasks = (str(sql.select_task(chat_id)).replace("('", '').replace( "',)", '')).split(' ^$^ ') temp = "My tasks for today: \n" for i in current_tasks: print(i) temp += '- ' + i + '\n' print("It's a new day!\n" + temp) bot.send_message(job.context, text="It's a new day!\n" + temp)
def read_task(bot, update): sql = SQL_worker(database=config.database_name) current_tasks = (str(sql.select_task(update.message.chat_id)).replace( "('", '').replace("',)", '')).split(' ^$^ ') temp = "My tasks for today: \n" for i in current_tasks: print(i) temp += '- ' + i + '\n' print(temp) bot.send_message(chat_id=update.message.chat_id, text=temp)
def day_end(bot, job): """Send the alarm message.""" global text_handler, none_work_handler none_work_handler = RegexHandler("^(None)$", cancel_button) sql = SQL_worker(database=config.database_name) current_tasks = (str(sql.select_task(chat_id)).replace("('", '').replace( "',)", '')).split(' ^$^ ') none = telegram.ReplyKeyboardMarkup([["None"]]) bot.send_message(job.context, text="You had " + str(len(current_tasks)) + " tasks today\nHow many of them have you done?", reply_markup=none) text_handler = MessageHandler(Filters.text, write_stats) dp.add_handler(text_handler)
def task_writer(bot, update): sql = SQL_worker(database=config.database_name) current_tasks = (str(sql.select_task(update.message.chat_id)).replace( "('", '').replace("',)", '')).split(' ^$^ ') temp = str(update.message.text) if current_tasks[0] == "No actual tasks" or current_tasks[ 0] == "You haven't any tasks yet.": current_tasks = temp else: current_tasks = current_tasks + [temp] current_tasks = " ^$^ ".join(current_tasks) sql.write_new_task(current_tasks, update.message.chat_id) sql.close() bot.send_message(chat_id=update.message.chat_id, text=locale.done, reply_markup=telegram.ReplyKeyboardMarkup( locale.start_keyboard)) dp.remove_handler(cancel_work_handler) dp.remove_handler(new_task_handler)