def add_task(message): with db_session: try: if Chat.exists(id=str(message.chat.id)): if message.reply_to_message is not None: if message.reply_to_message.from_user.id == ME: bot.reply_to(message, "Cannot save my own messages") return add_new_task(task=message.reply_to_message.text, chat=str(message.chat.id), complete=False) bot.reply_to(message, "Task was added.") else: task = message.text.split("/add ", 1)[1] add_new_task(task=task, chat=str(message.chat.id), complete=False) bot.reply_to(message, "Task was added.") else: add_new_chat(message) except TransactionIntegrityError as e: print(str(e)) except IndexError as error: # is a group if not message.text.startswith("/add@Todo_taskBot"): return task = message.text.split("/add@Todo_taskBot ", 1)[1] add_new_task(task=task, chat=str(message.chat.id), complete=False) bot.reply_to(message, "Task was added.") else: pass
def list_all_task(message): with db_session: try: if not Chat.exists(id=str(message.chat.id)): add_new_chat(message) else: task_list = list( Task.select(lambda t: t.chat.id == str(message.chat.id))) if len(task_list) == 0: bot.reply_to(message, "Your TO-DO list is empty") return all_tasks = "This is your TO-DO List: \n" for task in task_list: all_tasks += "📍" + task.task + " [" + str( task.id_in_chat) + "]\n\n" print(all_tasks) bot.reply_to(message, all_tasks) except ApiException as e: print(str(e)) else: pass
def chat_id_validator(self, value): if Chat.exists(value): return value else: abort(400, chat_id='chat_id does\'t exist')
def chat_id_validator(self, value): if Chat.exists(value): return value else: raise ValueError(description='chat_id does\'t exist', ok=False)
def send_welcome(message): with db_session: if not Chat.exists(id=str(message.chat.id)): add_new_chat(message) bot.reply_to(message, "Howdy, how are you doing?")