"Fix" remind list when you have more than 25 reminders
This commit is contained in:
@ -130,20 +130,13 @@ async def command_modify(ctx: SlashContext, time_or_message: str):
|
||||
# TODO: Reduce complexity.
|
||||
|
||||
# Only make a list with normal reminders.
|
||||
list_embed, jobs_dict = make_list(ctx, skip_cron_or_interval=True)
|
||||
jobs_dict = await send_list(ctx, skip_cron_or_interval=True)
|
||||
|
||||
if time_or_message == "date":
|
||||
date_or_message = "the date"
|
||||
else:
|
||||
date_or_message = "the message"
|
||||
|
||||
# The empty embed has 76 characters
|
||||
# TODO: This is a hack. Fix it.
|
||||
# TODO: Move this to a function.
|
||||
if len(list_embed) <= 76:
|
||||
await ctx.send(f"{ctx.guild.name} has no reminders.")
|
||||
else:
|
||||
await ctx.send(embed=list_embed)
|
||||
await ctx.channel.send(
|
||||
"Type the corresponding number to the reminder were you wish to"
|
||||
f" change {date_or_message}. Does not work with cron or interval."
|
||||
@ -247,13 +240,8 @@ async def remind_remove(ctx: SlashContext):
|
||||
"""Select reminder from list that you want to remove."""
|
||||
# TODO: Reduce complexity
|
||||
|
||||
list_embed, jobs_dict = make_list(ctx)
|
||||
jobs_dict = await send_list(ctx)
|
||||
|
||||
# The empty embed has 76 characters
|
||||
if len(list_embed) <= 76:
|
||||
await ctx.send(f"{ctx.guild.name} has no reminders.")
|
||||
else:
|
||||
await ctx.send(embed=list_embed)
|
||||
await ctx.channel.send(
|
||||
"Type the corresponding number to the reminder you wish to remove."
|
||||
" Type Exit to exit."
|
||||
@ -273,9 +261,7 @@ async def remind_remove(ctx: SlashContext):
|
||||
if int(response_message.clean_content) == num:
|
||||
job = scheduler.get_job(job_from_dict)
|
||||
if job is None:
|
||||
await ctx.channel.send(
|
||||
f"No reminder with that ID ({job_from_dict})."
|
||||
)
|
||||
await ctx.channel.send(f"No reminder with that ID ({job_from_dict}).")
|
||||
return
|
||||
|
||||
channel_id = job.kwargs.get("channel_id")
|
||||
@ -305,7 +291,7 @@ async def remind_remove(ctx: SlashContext):
|
||||
await ctx.channel.send(msg)
|
||||
|
||||
|
||||
def make_list(ctx, skip_datetriggers=False, skip_cron_or_interval=False):
|
||||
async def send_list(ctx, skip_datetriggers=False, skip_cron_or_interval=False):
|
||||
"""Create a list of reminders.
|
||||
|
||||
Args:
|
||||
@ -313,11 +299,11 @@ def make_list(ctx, skip_datetriggers=False, skip_cron_or_interval=False):
|
||||
skip_cron_or_interval (bool, optional): Only show normal reminders.
|
||||
|
||||
Returns:
|
||||
embed: Embed is the list of reminders that we send to Discord.
|
||||
jobs_dict: Dictionary that contains placement in list and job id.
|
||||
"""
|
||||
jobs_dict = {}
|
||||
job_number = 0
|
||||
|
||||
embed = discord.Embed(
|
||||
colour=discord.Colour.random(),
|
||||
title="discord-reminder-bot by TheLovinator#9276",
|
||||
@ -325,19 +311,17 @@ def make_list(ctx, skip_datetriggers=False, skip_cron_or_interval=False):
|
||||
url="https://github.com/TheLovinator1/discord-reminder-bot",
|
||||
)
|
||||
jobs = scheduler.get_jobs()
|
||||
|
||||
for job in jobs:
|
||||
channel_id = job.kwargs.get("channel_id")
|
||||
channel_name = bot.get_channel(int(channel_id))
|
||||
|
||||
# Only add reminders from channels in server we run "/reminder
|
||||
# list" in
|
||||
# Only add reminders from channels in server we run
|
||||
# "/reminder list" in
|
||||
|
||||
# Check if channel is in server
|
||||
for channel in ctx.guild.channels:
|
||||
if channel.id == channel_id:
|
||||
job_number += 1
|
||||
jobs_dict[job_number] = job.id
|
||||
message = job.kwargs.get("message")
|
||||
|
||||
if type(job.trigger) is DateTrigger:
|
||||
# Get trigger time for normal reminders
|
||||
trigger_time = job.trigger.run_date
|
||||
@ -359,6 +343,10 @@ def make_list(ctx, skip_datetriggers=False, skip_cron_or_interval=False):
|
||||
else:
|
||||
trigger_value = f'{trigger_time.strftime("%Y-%m-%d %H:%M")} (in {calc_countdown(job)})'
|
||||
|
||||
job_number += 1
|
||||
jobs_dict[job_number] = job.id
|
||||
message = job.kwargs.get("message")
|
||||
|
||||
# Truncate message if it's too long
|
||||
field_name = f"{job_number}) {message} in #{channel_name}"
|
||||
field_name = field_name[:253] + (field_name[253:] and "...")
|
||||
@ -368,7 +356,20 @@ def make_list(ctx, skip_datetriggers=False, skip_cron_or_interval=False):
|
||||
value=trigger_value,
|
||||
inline=False,
|
||||
)
|
||||
return embed, jobs_dict
|
||||
|
||||
if job_number == 24:
|
||||
await ctx.send(
|
||||
"I haven't added support for showing more than 25 reminders yet 🙃"
|
||||
)
|
||||
break
|
||||
|
||||
# The empty embed has 76 characters
|
||||
if len(embed) <= 76:
|
||||
await ctx.send(f"{ctx.guild.name} has no reminders.")
|
||||
else:
|
||||
await ctx.send(embed=embed)
|
||||
|
||||
return jobs_dict
|
||||
|
||||
|
||||
@slash.subcommand(
|
||||
@ -378,15 +379,7 @@ def make_list(ctx, skip_datetriggers=False, skip_cron_or_interval=False):
|
||||
)
|
||||
async def remind_list(ctx: SlashContext):
|
||||
"""Send a list of reminders to Discord."""
|
||||
list_embed, _ = make_list(ctx)
|
||||
|
||||
# The empty embed has 76 characters
|
||||
# TODO: This is a hack. Fix it.
|
||||
# TODO: Move this to a function.
|
||||
if len(list_embed) <= 76:
|
||||
await ctx.send(f"{ctx.guild.name} has no reminders.")
|
||||
else:
|
||||
await ctx.send(embed=list_embed)
|
||||
await send_list(ctx)
|
||||
|
||||
|
||||
@slash.subcommand(
|
||||
@ -396,22 +389,14 @@ async def remind_list(ctx: SlashContext):
|
||||
)
|
||||
async def remind_pause(ctx: SlashContext):
|
||||
"""Get a list of reminders that you can pause."""
|
||||
list_embed, jobs_dict = make_list(ctx, skip_datetriggers=True)
|
||||
jobs_dict = await send_list(ctx, skip_datetriggers=True)
|
||||
|
||||
# The empty embed has 76 characters
|
||||
# TODO: This is a hack. Fix it.
|
||||
# TODO: Move this to a function.
|
||||
if len(list_embed) <= 76:
|
||||
await ctx.send(f"{ctx.guild.name} has no reminders.")
|
||||
else:
|
||||
await ctx.send(embed=list_embed)
|
||||
await ctx.channel.send(
|
||||
"Type the corresponding number to the reminder you wish to pause."
|
||||
" Type Exit to exit."
|
||||
)
|
||||
|
||||
# Only check for response from the original user and in the
|
||||
# correct channel
|
||||
# Only check for response from the original user and in the correct channel
|
||||
def check(m):
|
||||
return m.author == ctx.author and m.channel == ctx.channel
|
||||
|
||||
@ -442,7 +427,9 @@ async def remind_pause(ctx: SlashContext):
|
||||
f"{message} in #{channel_name} is already paused."
|
||||
)
|
||||
|
||||
trigger_value = f'{trigger_time.strftime("%Y-%m-%d %H:%M")} (in {calc_countdown(job)})'
|
||||
trigger_value = (
|
||||
f'{trigger_time.strftime("%Y-%m-%d %H:%M")} (in {calc_countdown(job)})'
|
||||
)
|
||||
|
||||
msg = (
|
||||
f"**Paused** {message} in #{channel_name}.\n"
|
||||
@ -462,22 +449,14 @@ async def remind_pause(ctx: SlashContext):
|
||||
async def remind_resume(ctx: SlashContext):
|
||||
"""Send a list of reminders to pause to Discord."""
|
||||
# TODO: Reduce the complexity of this function
|
||||
list_embed, jobs_dict = make_list(ctx, skip_datetriggers=True)
|
||||
jobs_dict = await send_list(ctx, skip_datetriggers=True)
|
||||
|
||||
# The empty embed has 76 characters
|
||||
# TODO: This is a hack. Fix it.
|
||||
# TODO: Move this to a function.
|
||||
if len(list_embed) <= 76:
|
||||
await ctx.send(f"{ctx.guild.name} has no reminders.")
|
||||
else:
|
||||
await ctx.send(embed=list_embed)
|
||||
await ctx.channel.send(
|
||||
"Type the corresponding number to the reminder you wish to pause."
|
||||
" Type Exit to exit."
|
||||
)
|
||||
|
||||
# Only check for response from the original user and in the
|
||||
# correct channel
|
||||
# Only check for response from the original user and in the correct channel
|
||||
def check(m):
|
||||
return m.author == ctx.author and m.channel == ctx.channel
|
||||
|
||||
@ -567,7 +546,6 @@ async def remind_add(
|
||||
f"{message_date}",
|
||||
settings={
|
||||
"PREFER_DATES_FROM": "future",
|
||||
# TODO: Is timezones even working? Timezones confuse me.
|
||||
"TO_TIMEZONE": f"{config_timezone}",
|
||||
},
|
||||
)
|
||||
|
Reference in New Issue
Block a user