(Reminders): Small UI improvements.
This commit is contained in:
@@ -34,12 +34,11 @@ async def cmd_remindme(ctx, flags):
|
|||||||
Usage``:
|
Usage``:
|
||||||
{prefix}remindme in <duration> to <task>
|
{prefix}remindme in <duration> to <task>
|
||||||
{prefix}remindme every <duration> to <task>
|
{prefix}remindme every <duration> to <task>
|
||||||
|
|
||||||
{prefix}reminders
|
{prefix}reminders
|
||||||
{prefix}reminders --clear
|
{prefix}reminders --clear
|
||||||
{prefix}reminders --remove <ids>
|
{prefix}reminders --remove
|
||||||
Description:
|
Description:
|
||||||
Ask LionBot to remind you about important tasks.
|
Ask {ctx.client.user.name} to remind you about important tasks.
|
||||||
Examples``:
|
Examples``:
|
||||||
{prefix}remindme in 2h 20m, Revise chapter 1
|
{prefix}remindme in 2h 20m, Revise chapter 1
|
||||||
{prefix}remindme every hour, Drink water!
|
{prefix}remindme every hour, Drink water!
|
||||||
@@ -58,58 +57,65 @@ async def cmd_remindme(ctx, flags):
|
|||||||
|
|
||||||
live = Reminder.fetch(*(row.reminderid for row in rows))
|
live = Reminder.fetch(*(row.reminderid for row in rows))
|
||||||
|
|
||||||
lines = []
|
if not ctx.args:
|
||||||
num_field = len(str(len(live) - 1))
|
lines = []
|
||||||
for i, reminder in enumerate(live):
|
num_field = len(str(len(live) - 1))
|
||||||
lines.append(
|
for i, reminder in enumerate(live):
|
||||||
"`[{:{}}]` | {}".format(
|
lines.append(
|
||||||
i,
|
"`[{:{}}]` | {}".format(
|
||||||
num_field,
|
i,
|
||||||
reminder.formatted
|
num_field,
|
||||||
|
reminder.formatted
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
description = '\n'.join(lines)
|
||||||
|
description += (
|
||||||
|
"\n\nPlease select the reminders to remove, or type `c` to cancel.\n"
|
||||||
|
"(For example, respond with `1, 2, 3` or `1-3`.)"
|
||||||
|
)
|
||||||
|
embed = discord.Embed(
|
||||||
|
description=description,
|
||||||
|
colour=discord.Colour.orange(),
|
||||||
|
timestamp=datetime.datetime.utcnow()
|
||||||
|
).set_author(
|
||||||
|
name="Reminders for {}".format(ctx.author.display_name),
|
||||||
|
icon_url=ctx.author.avatar_url
|
||||||
)
|
)
|
||||||
|
|
||||||
description = '\n'.join(lines)
|
out_msg = await ctx.reply(embed=embed)
|
||||||
description += (
|
|
||||||
"\n\nPlease select the reminders to remove, or type `c` to cancel.\n"
|
|
||||||
"(For example, respond with `1, 2, 3` or `1-3`.)"
|
|
||||||
)
|
|
||||||
embed = discord.Embed(
|
|
||||||
description=description,
|
|
||||||
colour=discord.Colour.orange(),
|
|
||||||
timestamp=datetime.datetime.utcnow()
|
|
||||||
).set_author(
|
|
||||||
name="Reminders for {}".format(ctx.author.display_name),
|
|
||||||
icon_url=ctx.author.avatar_url
|
|
||||||
)
|
|
||||||
|
|
||||||
out_msg = await ctx.reply(embed=embed)
|
def check(msg):
|
||||||
|
valid = msg.channel == ctx.ch and msg.author == ctx.author
|
||||||
|
valid = valid and (re.search(multiselect_regex, msg.content) or msg.content.lower() == 'c')
|
||||||
|
return valid
|
||||||
|
|
||||||
def check(msg):
|
try:
|
||||||
valid = msg.channel == ctx.ch and msg.author == ctx.author
|
message = await ctx.client.wait_for('message', check=check, timeout=60)
|
||||||
valid = valid and (re.search(multiselect_regex, msg.content) or msg.content.lower() == 'c')
|
except asyncio.TimeoutError:
|
||||||
return valid
|
await out_msg.delete()
|
||||||
|
await ctx.error_reply("Session timed out. No reminders were deleted.")
|
||||||
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
message = await ctx.client.wait_for('message', check=check, timeout=60)
|
await out_msg.delete()
|
||||||
except asyncio.TimeoutError:
|
await message.delete()
|
||||||
await out_msg.delete()
|
except discord.HTTPException:
|
||||||
await ctx.error_reply("Session timed out. No reminders were deleted.")
|
pass
|
||||||
return
|
|
||||||
|
|
||||||
try:
|
if message.content.lower() == 'c':
|
||||||
await out_msg.delete()
|
return
|
||||||
await message.delete()
|
|
||||||
except discord.HTTPException:
|
|
||||||
pass
|
|
||||||
|
|
||||||
if message.content.lower() == 'c':
|
to_delete = [
|
||||||
return
|
live[index].reminderid
|
||||||
|
for index in parse_ranges(message.content) if index < len(live)
|
||||||
|
]
|
||||||
|
else:
|
||||||
|
to_delete = [
|
||||||
|
live[index].reminderid
|
||||||
|
for index in parse_ranges(ctx.args) if index < len(live)
|
||||||
|
]
|
||||||
|
|
||||||
to_delete = [
|
|
||||||
live[index].reminderid
|
|
||||||
for index in parse_ranges(message.content) if index < len(live)
|
|
||||||
]
|
|
||||||
if not to_delete:
|
if not to_delete:
|
||||||
return await ctx.error_reply("Nothing to delete!")
|
return await ctx.error_reply("Nothing to delete!")
|
||||||
|
|
||||||
@@ -247,7 +253,10 @@ async def cmd_remindme(ctx, flags):
|
|||||||
name="{}'s reminders".format(ctx.author.display_name),
|
name="{}'s reminders".format(ctx.author.display_name),
|
||||||
icon_url=ctx.author.avatar_url
|
icon_url=ctx.author.avatar_url
|
||||||
).set_footer(
|
).set_footer(
|
||||||
text="For examples and usage see {}help reminders".format(ctx.best_prefix)
|
text=(
|
||||||
|
"Click a reminder twice to jump to the context!\n"
|
||||||
|
"For more usage and examples see {}help reminders"
|
||||||
|
).format(ctx.best_prefix)
|
||||||
)
|
)
|
||||||
|
|
||||||
await ctx.reply(embed=embed)
|
await ctx.reply(embed=embed)
|
||||||
|
|||||||
@@ -75,7 +75,19 @@ class Reminder:
|
|||||||
trunc_content = content[:50] + '...' * (len(content) > 50)
|
trunc_content = content[:50] + '...' * (len(content) > 50)
|
||||||
|
|
||||||
if self.data.interval:
|
if self.data.interval:
|
||||||
repeat = "(Every `{}`)".format(strfdur(self.data.interval))
|
interval = self.data.interval
|
||||||
|
if interval == 24 * 60 * 60:
|
||||||
|
interval_str = "day"
|
||||||
|
elif interval == 60 * 60:
|
||||||
|
interval_str = "hour"
|
||||||
|
elif interval % (24 * 60 * 60) == 0:
|
||||||
|
interval_str = "`{}` days".format(interval // (24 * 60 * 60))
|
||||||
|
elif interval % 60 * 60 == 0:
|
||||||
|
interval_str = "`{}` hours".format(interval // (60 * 60))
|
||||||
|
else:
|
||||||
|
interval_str = "`{}`".format(strfdur(interval))
|
||||||
|
|
||||||
|
repeat = "(Every {})".format(interval_str)
|
||||||
else:
|
else:
|
||||||
repeat = ""
|
repeat = ""
|
||||||
|
|
||||||
|
|||||||
@@ -253,7 +253,10 @@ def parse_ranges(ranges_str, ignore_errors=False, separator=',', **kwargs):
|
|||||||
integers = [int(item) for item in numbers if item.isdigit()]
|
integers = [int(item) for item in numbers if item.isdigit()]
|
||||||
|
|
||||||
if not ignore_errors and len(integers) != len(numbers):
|
if not ignore_errors and len(integers) != len(numbers):
|
||||||
raise SafeCancellation("Couldn't parse the provided selection!")
|
raise SafeCancellation(
|
||||||
|
"Couldn't parse the provided selection!\n"
|
||||||
|
"Please provide comma separated numbers and ranges, e.g. `1, 5, 6-9`."
|
||||||
|
)
|
||||||
|
|
||||||
return integers
|
return integers
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user