create function get_task_ids_from_context, use in functions delete and do
This commit is contained in:
parent
c08281b83a
commit
043cebe8b4
15
src/bot.py
15
src/bot.py
@ -44,12 +44,7 @@ def ls(update, context):
|
||||
dispatcher.add_handler(CommandHandler('ls', ls))
|
||||
|
||||
def do(update, 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]
|
||||
task_ids = db.get_task_ids_from_context(update.effective_user, context)
|
||||
|
||||
for task_id in task_ids:
|
||||
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))
|
||||
|
||||
def delete(update, context):
|
||||
print(db._get_db())
|
||||
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]
|
||||
task_ids = db.get_task_ids_from_context(update.effective_user, context)
|
||||
|
||||
for task_id in task_ids:
|
||||
task = db.remove_task_by_id(update.effective_user, task_id)
|
||||
|
10
src/db.py
10
src/db.py
@ -54,6 +54,16 @@ def fuzzy_get_task_id(user, text):
|
||||
task_strs = [str(task) for task in get_all_user_tasks(user)]
|
||||
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):
|
||||
if str(user.id) not in db[DbKeys.USER_TASKS].keys():
|
||||
db[DbKeys.USER_TASKS][str(user.id)] = []
|
||||
|
Reference in New Issue
Block a user