fix(tasklist): Fix error handling.
Also adds better pathway for selecting all tasks.
This commit is contained in:
@@ -308,6 +308,16 @@ class TasklistCog(LionCog):
|
|||||||
appcmds.Choice(name=task_string, value=label)
|
appcmds.Choice(name=task_string, value=label)
|
||||||
for label, task_string in matching
|
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):
|
elif multi and (',' in partial or '-' in partial):
|
||||||
# Try parsing input as a multi-list
|
# Try parsing input as a multi-list
|
||||||
try:
|
try:
|
||||||
@@ -691,7 +701,7 @@ class TasklistCog(LionCog):
|
|||||||
@appcmds.describe(
|
@appcmds.describe(
|
||||||
taskidstr=_p(
|
taskidstr=_p(
|
||||||
'cmd:tasks_remove|param:taskidstr|desc',
|
'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(
|
created_before=_p(
|
||||||
'cmd:tasks_remove|param:created_before|desc',
|
'cmd:tasks_remove|param:created_before|desc',
|
||||||
@@ -737,10 +747,10 @@ class TasklistCog(LionCog):
|
|||||||
if not taskids:
|
if not taskids:
|
||||||
# Explicitly error if none of the ranges matched
|
# Explicitly error if none of the ranges matched
|
||||||
await ctx.interaction.edit_original_response(
|
await ctx.interaction.edit_original_response(
|
||||||
embed=error_embed(
|
embed=error_embed(t(_p(
|
||||||
'cmd:tasks_remove_cmd|error:no_matching',
|
'cmd:tasks_remove_cmd|error:no_matching',
|
||||||
"No tasks on your tasklist match `{input}`"
|
"No tasks on your tasklist match `{input}`"
|
||||||
).format(input=taskidstr)
|
))).format(input=taskidstr)
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -761,10 +771,10 @@ class TasklistCog(LionCog):
|
|||||||
tasks = await self.data.Task.fetch_where(*conditions, userid=ctx.author.id)
|
tasks = await self.data.Task.fetch_where(*conditions, userid=ctx.author.id)
|
||||||
if not tasks:
|
if not tasks:
|
||||||
await ctx.interaction.edit_original_response(
|
await ctx.interaction.edit_original_response(
|
||||||
embed=error_embed(
|
embed=error_embed(t(_p(
|
||||||
'cmd:tasks_remove_cmd|error:no_matching',
|
'cmd:tasks_remove_cmd|error:no_matching',
|
||||||
"No tasks on your tasklist matching all the given conditions!"
|
"No tasks on your tasklist matching all the given conditions!"
|
||||||
).format(input=taskidstr)
|
))).format(input=taskidstr)
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
taskids = [task.taskid for task in tasks]
|
taskids = [task.taskid for task in tasks]
|
||||||
@@ -804,7 +814,7 @@ class TasklistCog(LionCog):
|
|||||||
@appcmds.describe(
|
@appcmds.describe(
|
||||||
taskidstr=_p(
|
taskidstr=_p(
|
||||||
'cmd:tasks_tick|param:taskidstr|desc',
|
'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(
|
cascade=_p(
|
||||||
'cmd:tasks_tick|param:cascade|desc',
|
'cmd:tasks_tick|param:cascade|desc',
|
||||||
@@ -832,10 +842,10 @@ class TasklistCog(LionCog):
|
|||||||
if not taskids:
|
if not taskids:
|
||||||
# Explicitly error if none of the ranges matched
|
# Explicitly error if none of the ranges matched
|
||||||
await ctx.interaction.edit_original_response(
|
await ctx.interaction.edit_original_response(
|
||||||
embed=error_embed(
|
embed=error_embed(t(_p(
|
||||||
'cmd:tasks_remove_cmd|error:no_matching',
|
'cmd:tasks_remove_cmd|error:no_matching',
|
||||||
"No tasks on your tasklist match `{input}`"
|
"No tasks on your tasklist match `{input}`"
|
||||||
).format(input=taskidstr)
|
))).format(input=taskidstr)
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -880,7 +890,7 @@ class TasklistCog(LionCog):
|
|||||||
@appcmds.describe(
|
@appcmds.describe(
|
||||||
taskidstr=_p(
|
taskidstr=_p(
|
||||||
'cmd:tasks_untick|param:taskidstr|desc',
|
'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(
|
cascade=_p(
|
||||||
'cmd:tasks_untick|param:cascade|desc',
|
'cmd:tasks_untick|param:cascade|desc',
|
||||||
@@ -907,10 +917,10 @@ class TasklistCog(LionCog):
|
|||||||
if not taskids:
|
if not taskids:
|
||||||
# Explicitly error if none of the ranges matched
|
# Explicitly error if none of the ranges matched
|
||||||
await ctx.interaction.edit_original_response(
|
await ctx.interaction.edit_original_response(
|
||||||
embed=error_embed(
|
embed=error_embed(t(_p(
|
||||||
'cmd:tasks_remove_cmd|error:no_matching',
|
'cmd:tasks_remove_cmd|error:no_matching',
|
||||||
"No tasks on your tasklist match `{input}`"
|
"No tasks on your tasklist match `{input}`"
|
||||||
).format(input=taskidstr)
|
))).format(input=taskidstr)
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|||||||
@@ -233,6 +233,9 @@ class Tasklist:
|
|||||||
|
|
||||||
May raise `UserInputError`.
|
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()}
|
labelmap = {label: task.taskid for label, task in self.labelled.items()}
|
||||||
|
|
||||||
splits = labelstr.split(',')
|
splits = labelstr.split(',')
|
||||||
|
|||||||
Reference in New Issue
Block a user