Skip to content

tux.cogs.utility.remindme

Classes:

Name Description
RemindMe

Classes

RemindMe(bot: Tux)

Bases: Cog

Methods:

Name Description
remindme

Set a reminder for yourself.

Source code in tux/cogs/utility/remindme.py
Python
def __init__(self, bot: Tux) -> None:
    self.bot = bot
    self.db = DatabaseController()
    self.check_reminders.start()
    self.remindme.usage = generate_usage(self.remindme)

Functions

remindme(ctx: commands.Context[Tux], time: str, *, reminder: str) -> None async

Set a reminder for yourself.

The time format is [number][M/w/d/h/m/s] where: - M = months - w = weeks - d = days - h = hours - m = minutes - s = seconds

Example: !remindme 1h30m "Take a break" will remind you in 1 hour and 30 minutes.

Parameters:

Name Type Description Default
ctx Context[Tux]

The context of the command.

required
time str

The time to set the reminder for (e.g. 2d, 1h30m).

required
reminder str

The reminder message.

required
Source code in tux/cogs/utility/remindme.py
Python
@commands.hybrid_command(
    name="remindme",
    description="Set a reminder for yourself",
)
async def remindme(
    self,
    ctx: commands.Context[Tux],
    time: str,
    *,
    reminder: str,
) -> None:
    """
    Set a reminder for yourself.

    The time format is `[number][M/w/d/h/m/s]` where:
    - M = months
    - w = weeks
    - d = days
    - h = hours
    - m = minutes
    - s = seconds

    Example: `!remindme 1h30m "Take a break"` will remind you in 1 hour and 30 minutes.

    Parameters
    ----------
    ctx : commands.Context[Tux]
        The context of the command.
    time : str
        The time to set the reminder for (e.g. 2d, 1h30m).
    reminder : str
        The reminder message.
    """

    seconds = convert_to_seconds(time)

    if seconds == 0:
        await ctx.reply(
            "Invalid time format. Please use the format `[number][M/w/d/h/m/s]`.",
            ephemeral=True,
            delete_after=30,
        )
        return

    expires_at = datetime.datetime.now(datetime.UTC) + datetime.timedelta(seconds=seconds)

    try:
        await self.db.reminder.insert_reminder(
            reminder_user_id=ctx.author.id,
            reminder_content=reminder,
            reminder_expires_at=expires_at,
            reminder_channel_id=ctx.channel.id if ctx.channel else 0,
            guild_id=ctx.guild.id if ctx.guild else 0,
        )

        embed = EmbedCreator.create_embed(
            bot=self.bot,
            embed_type=EmbedCreator.SUCCESS,
            user_name=ctx.author.name,
            user_display_avatar=ctx.author.display_avatar.url,
            title="Reminder Set",
            description=f"Reminder set for <t:{int(expires_at.timestamp())}:f>.",
        )

        embed.add_field(
            name="Note",
            value="- If you have DMs closed, we will attempt to send it in this channel instead.\n"
            "- The reminder may be delayed by up to 120 seconds due to the way Tux works.",
        )

    except Exception as e:
        embed = EmbedCreator.create_embed(
            bot=self.bot,
            embed_type=EmbedCreator.ERROR,
            user_name=ctx.author.name,
            user_display_avatar=ctx.author.display_avatar.url,
            description="There was an error creating the reminder.",
        )

        logger.error(f"Error creating reminder: {e}")

    await ctx.reply(embed=embed, ephemeral=True)

Functions