Fix bug in remindme if used in DMs

This commit is contained in:
Zeva Rose 2022-12-14 16:08:17 +00:00
parent 8471580517
commit 622b003246

View file

@ -55,6 +55,8 @@ class RemindmeCog(Extension):
) -> None:
if private is None and ctx.guild:
private = ctx.guild.member_count >= 5000
elif private is None and not ctx.guild:
private = False
modal = Modal(
title="Set your reminder!",
components=[
@ -94,9 +96,7 @@ class RemindmeCog(Extension):
await response.send("Hey, you should probably make this readable", ephemeral=True)
return
elif len(message) == 0:
await response.send(
"Hey, you should probably add content to your reminder", ephemeral=True
)
await response.send("Hey, you should probably add content to your reminder", ephemeral=True)
return
base_settings = {
@ -105,9 +105,7 @@ class RemindmeCog(Extension):
"RETURN_AS_TIMEZONE_AWARE": True,
}
rt_settings = base_settings.copy()
rt_settings["PARSERS"] = [
x for x in default_parsers if x not in ["absolute-time", "timestamp"]
]
rt_settings["PARSERS"] = [x for x in default_parsers if x not in ["absolute-time", "timestamp"]]
rt_remind_at = parse(delay, settings=rt_settings)
@ -121,15 +119,11 @@ class RemindmeCog(Extension):
remind_at = at_remind_at
else:
self.logger.debug(f"Failed to parse delay: {delay}")
await response.send(
f"`{delay}` is not a parsable date, please try again", ephemeral=True
)
await response.send(f"`{delay}` is not a parsable date, please try again", ephemeral=True)
return
if remind_at < datetime.now(tz=timezone.utc):
await response.send(
f"`{delay}` is in the past. Past reminders aren't allowed", ephemeral=True
)
await response.send(f"`{delay}` is in the past. Past reminders aren't allowed", ephemeral=True)
return
elif remind_at < datetime.now(tz=timezone.utc):
@ -165,18 +159,16 @@ class RemindmeCog(Extension):
icon_url=ctx.author.display_avatar.url,
)
embed.set_thumbnail(url=ctx.author.display_avatar.url)
delete_button = Button(
style=ButtonStyles.DANGER, emoji="🗑️", custom_id=f"delete|{ctx.author.id}"
)
delete_button = Button(style=ButtonStyles.DANGER, emoji="🗑️", custom_id=f"delete|{ctx.author.id}")
components = [delete_button]
if not r.guild == ctx.author.id:
copy_button = Button(style=ButtonStyles.GREEN, emoji="📋", custom_id=f"copy|rme|{r.id}")
components = [ActionRow(delete_button, copy_button)]
components.append(copy_button)
private = private if private is not None else False
components = [ActionRow(*components)]
await response.send(embeds=embed, components=components, ephemeral=private)
async def get_reminders_embed(
self, ctx: InteractionContext, reminders: List[Reminder]
) -> Embed:
async def get_reminders_embed(self, ctx: InteractionContext, reminders: List[Reminder]) -> Embed:
"""Build embed for paginator."""
fields = []
for reminder in reminders:
@ -219,9 +211,7 @@ class RemindmeCog(Extension):
return
embed = await self.get_reminders_embed(ctx, reminders)
components = Button(
style=ButtonStyles.DANGER, emoji="🗑️", custom_id=f"delete|{ctx.author.id}"
)
components = Button(style=ButtonStyles.DANGER, emoji="🗑️", custom_id=f"delete|{ctx.author.id}")
await ctx.send(embeds=embed, components=components)
@reminders.subcommand(sub_cmd_name="delete", sub_cmd_description="Delete a reminder")
@ -254,9 +244,7 @@ class RemindmeCog(Extension):
)
embed.set_thumbnail(url=ctx.author.display_avatar.url)
components = Button(
style=ButtonStyles.DANGER, emoji="🗑️", custom_id=f"delete|{ctx.author.id}"
)
components = Button(style=ButtonStyles.DANGER, emoji="🗑️", custom_id=f"delete|{ctx.author.id}")
try:
await reminder.delete()
except Exception:
@ -288,18 +276,14 @@ class RemindmeCog(Extension):
EmbedField(name="Created At", value=f"<t:{cts}:F> (<t:{cts}:R>)"),
]
embed = build_embed(
title="You have a reminder!", description=reminder.message, fields=fields
)
embed = build_embed(title="You have a reminder!", description=reminder.message, fields=fields)
embed.set_author(
name=ctx.author.display_name + "#" + ctx.author.discriminator,
icon_url=ctx.author.display_avatar.url,
)
embed.set_thumbnail(url=ctx.author.display_avatar.url)
components = Button(
style=ButtonStyles.DANGER, emoji="🗑️", custom_id=f"delete|{ctx.author.id}"
)
components = Button(style=ButtonStyles.DANGER, emoji="🗑️", custom_id=f"delete|{ctx.author.id}")
await ctx.send(embeds=embed, ephemeral=reminder.private, components=components)
if reminder.remind_at <= datetime.now(tz=timezone.utc) and not reminder.active:
try: