1
0

create function get_task_ids_from_context, use in functions delete and do

This commit is contained in:
Akbar Rahman 2021-02-27 15:16:51 +00:00
parent c08281b83a
commit 043cebe8b4
2 changed files with 12 additions and 13 deletions

View File

@ -44,12 +44,7 @@ def ls(update, context):
dispatcher.add_handler(CommandHandler('ls', ls)) dispatcher.add_handler(CommandHandler('ls', ls))
def do(update, context): def do(update, context):
for arg in context.args: task_ids = db.get_task_ids_from_context(update.effective_user, context)
if not arg.isnumeric():
task_ids = [db.fuzzy_get_task_id(update.effective_user, ' '.join(context.args))]
break
else:
task_ids = [int(x) for x in context.args]
for task_id in task_ids: for task_id in task_ids:
task = db.get_task(update.effective_user, task_id) task = db.get_task(update.effective_user, task_id)
@ -72,13 +67,7 @@ def new_task(update, context):
dispatcher.add_handler(MessageHandler(Filters.text & (~Filters.command), new_task)) dispatcher.add_handler(MessageHandler(Filters.text & (~Filters.command), new_task))
def delete(update, context): def delete(update, context):
print(db._get_db()) task_ids = db.get_task_ids_from_context(update.effective_user, context)
for arg in context.args:
if not arg.isnumeric():
task_ids = [db.fuzzy_get_task_id(update.effective_user, ' '.join(context.args))]
break
else:
task_ids = [int(x) for x in context.args]
for task_id in task_ids: for task_id in task_ids:
task = db.remove_task_by_id(update.effective_user, task_id) task = db.remove_task_by_id(update.effective_user, task_id)

View File

@ -54,6 +54,16 @@ def fuzzy_get_task_id(user, text):
task_strs = [str(task) for task in get_all_user_tasks(user)] task_strs = [str(task) for task in get_all_user_tasks(user)]
return task_strs.index(fuzzyprocess.extractOne(text, task_strs)[0]) return task_strs.index(fuzzyprocess.extractOne(text, task_strs)[0])
def get_task_ids_from_context(user, context):
for arg in context.args:
if not arg.isnumeric():
task_ids = [fuzzy_get_task_id(user, ' '.join(context.args))]
break
else:
task_ids = [int(x) for x in context.args]
return task_ids
def create_user(db, user: telegram.User): def create_user(db, user: telegram.User):
if str(user.id) not in db[DbKeys.USER_TASKS].keys(): if str(user.id) not in db[DbKeys.USER_TASKS].keys():
db[DbKeys.USER_TASKS][str(user.id)] = [] db[DbKeys.USER_TASKS][str(user.id)] = []