From d14b0880eb4807fc85f0ec73126986fca9789d39 Mon Sep 17 00:00:00 2001 From: Conatum Date: Mon, 11 Sep 2023 10:17:01 +0300 Subject: [PATCH] fix(tasklist): Fix error handling. Also adds better pathway for selecting all tasks. --- src/modules/tasklist/cog.py | 32 +++++++++++++++++++++----------- src/modules/tasklist/tasklist.py | 3 +++ 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/src/modules/tasklist/cog.py b/src/modules/tasklist/cog.py index 976f1a50..92518416 100644 --- a/src/modules/tasklist/cog.py +++ b/src/modules/tasklist/cog.py @@ -308,6 +308,16 @@ class TasklistCog(LionCog): appcmds.Choice(name=task_string, value=label) for label, task_string in matching ] + elif multi and partial.lower().strip() in ('-', 'all'): + options = [ + appcmds.Choice( + name=t(_p( + 'argtype:taskid|match:all', + "All tasks" + )), + value='-' + ) + ] elif multi and (',' in partial or '-' in partial): # Try parsing input as a multi-list try: @@ -691,7 +701,7 @@ class TasklistCog(LionCog): @appcmds.describe( taskidstr=_p( 'cmd:tasks_remove|param:taskidstr|desc', - "List of task numbers or ranges to remove (e.g. 1, 2, 5-7, 8.1-3, 9-)." + "List of task numbers or ranges to remove (e.g. 1, 2, 5-7, 8.1-3, 9-), or `-` to remove all." ), created_before=_p( 'cmd:tasks_remove|param:created_before|desc', @@ -737,10 +747,10 @@ class TasklistCog(LionCog): if not taskids: # Explicitly error if none of the ranges matched await ctx.interaction.edit_original_response( - embed=error_embed( + embed=error_embed(t(_p( 'cmd:tasks_remove_cmd|error:no_matching', "No tasks on your tasklist match `{input}`" - ).format(input=taskidstr) + ))).format(input=taskidstr) ) return @@ -761,10 +771,10 @@ class TasklistCog(LionCog): tasks = await self.data.Task.fetch_where(*conditions, userid=ctx.author.id) if not tasks: await ctx.interaction.edit_original_response( - embed=error_embed( + embed=error_embed(t(_p( 'cmd:tasks_remove_cmd|error:no_matching', "No tasks on your tasklist matching all the given conditions!" - ).format(input=taskidstr) + ))).format(input=taskidstr) ) return taskids = [task.taskid for task in tasks] @@ -804,7 +814,7 @@ class TasklistCog(LionCog): @appcmds.describe( taskidstr=_p( 'cmd:tasks_tick|param:taskidstr|desc', - "List of task numbers or ranges to remove (e.g. 1, 2, 5-7, 8.1-3, 9-)." + "List of task numbers or ranges to tick (e.g. 1, 2, 5-7, 8.1-3, 9-) or '-' to tick all." ), cascade=_p( 'cmd:tasks_tick|param:cascade|desc', @@ -832,10 +842,10 @@ class TasklistCog(LionCog): if not taskids: # Explicitly error if none of the ranges matched await ctx.interaction.edit_original_response( - embed=error_embed( + embed=error_embed(t(_p( 'cmd:tasks_remove_cmd|error:no_matching', "No tasks on your tasklist match `{input}`" - ).format(input=taskidstr) + ))).format(input=taskidstr) ) return @@ -880,7 +890,7 @@ class TasklistCog(LionCog): @appcmds.describe( taskidstr=_p( 'cmd:tasks_untick|param:taskidstr|desc', - "List of task numbers or ranges to remove (e.g. 1, 2, 5-7, 8.1-3, 9-)." + "List of task numbers or ranges to untick (e.g. 1, 2, 5-7, 8.1-3, 9-) or '-' to untick all." ), cascade=_p( 'cmd:tasks_untick|param:cascade|desc', @@ -907,10 +917,10 @@ class TasklistCog(LionCog): if not taskids: # Explicitly error if none of the ranges matched await ctx.interaction.edit_original_response( - embed=error_embed( + embed=error_embed(t(_p( 'cmd:tasks_remove_cmd|error:no_matching', "No tasks on your tasklist match `{input}`" - ).format(input=taskidstr) + ))).format(input=taskidstr) ) return diff --git a/src/modules/tasklist/tasklist.py b/src/modules/tasklist/tasklist.py index 4e53ffda..ddc2de77 100644 --- a/src/modules/tasklist/tasklist.py +++ b/src/modules/tasklist/tasklist.py @@ -233,6 +233,9 @@ class Tasklist: May raise `UserInputError`. """ + if labelstr.strip().lower() in ('-', 'all'): + return list(self.tasklist.keys()) + labelmap = {label: task.taskid for label, task in self.labelled.items()} splits = labelstr.split(',')