diff --git a/bot/cogs/commands/useful.py b/bot/cogs/commands/useful.py index 6da43767..9d15931c 100644 --- a/bot/cogs/commands/useful.py +++ b/bot/cogs/commands/useful.py @@ -636,9 +636,35 @@ async def image_search(self, ctx: Ctx, *, query): await ctx.reply_embed(ctx.l.useful.search.nope) return - @commands.command(name="remindme", aliases=["remind"]) + @commands.group(name="reminders", aliases=["reminder", "remind"]) @commands.cooldown(1, 2, commands.BucketType.user) - async def remind_me(self, ctx: Ctx, duration_str: str, *, reminder: str): + async def reminders(self, ctx: Ctx): + if ctx.invoked_subcommand: + return + + user_reminders = await self.db.fetch_user_reminders(ctx.author.id) + embed = discord.Embed(color=self.bot.embed_color) + embed.set_author( + name=f"{ctx.author.display_name}'s reminders", icon_url=ctx.author.avatar.url + ) + embed.set_footer(text=ctx.l.useful.remind.add.format(ctx.prefix)) + + if len(user_reminders) == 0: + embed.description = ctx.l.useful.remind.none + + for reminder in user_reminders: + unix_timestamp = format_dt(reminder["at"], style="R") + reminder["reminder"] = shorten_text(reminder["reminder"], 75) + embed.add_field( + name=f"`#{reminder['id']}` - {unix_timestamp}", + value=reminder["reminder"], + inline=False, + ) + await ctx.send(embed=embed) + + @reminders.command(name="add", aliases=["create"]) + @commands.cooldown(1, 2, commands.BucketType.user) + async def reminders_add(self, ctx: Ctx, duration_str: str, *, reminder: str): user_reminder_count = await self.db.fetch_user_reminder_count(ctx.author.id) if user_reminder_count > 10: @@ -671,24 +697,15 @@ async def remind_me(self, ctx: Ctx, duration_str: str, *, reminder: str): ) ) - @commands.command(name="reminders") + @reminders.command(name="delete", aliases=["remove", "rm", "del"]) @commands.cooldown(1, 2, commands.BucketType.user) - async def reminders_list(self, ctx: Ctx): - user_reminders = await self.db.fetch_user_reminders(ctx.author.id) - embed = discord.Embed(color=self.bot.embed_color) - embed.set_author( - name=f"{ctx.author.display_name}'s reminders", icon_url=ctx.author.avatar.url - ) + async def reminders_remove(self, ctx: Ctx, reminder_id: int): + deleted = await self.db.delete_user_reminder(ctx.author.id, reminder_id) + if deleted: + await ctx.reply_embed(ctx.l.useful.remind.authorized.format(self.bot.d.emojis.yes)) + return - for reminder in user_reminders: - unix_timestamp = format_dt(reminder["at"], style="R") - reminder["reminder"] = shorten_text(reminder["reminder"], 75) - embed.add_field( - name=f"`#{reminder['id']}` - {unix_timestamp}", - value=reminder["reminder"], - inline=False, - ) - await ctx.send(embed=embed) + await ctx.reply_embed(ctx.l.useful.remind.unauthorized.format(self.bot.d.emojis.no)) @commands.command(name="snipe") async def snipe_message(self, ctx: Ctx): diff --git a/bot/cogs/core/database.py b/bot/cogs/core/database.py index 62d0e4f1..33794a7d 100644 --- a/bot/cogs/core/database.py +++ b/bot/cogs/core/database.py @@ -57,6 +57,15 @@ async def add_reminder( at, ) + async def delete_user_reminder(self, user_id, reminder_id: int) -> bool: + count = await self.db.fetchval( + "WITH deleted AS (DELETE FROM reminders WHERE user_id = $1 AND id = $2 RETURNING *) SELECT COUNT(*) FROM deleted;", + user_id, + reminder_id, + ) + + return bool(count) + async def fetch_all_botbans(self) -> set[int]: botban_records = await self.db.fetch("SELECT user_id FROM users WHERE bot_banned = true") return {r["user_id"] for r in botban_records} diff --git a/bot/data/text/en.json b/bot/data/text/en.json index 2622a3d1..f8268786 100644 --- a/bot/data/text/en.json +++ b/bot/data/text/en.json @@ -121,14 +121,13 @@ "youtube": "`{0}youtube ` *searches on youtube for your query*", "image": "`{0}image ` *searches google images for your query*", "math": "`{0}math ` *solves a math problem", - "remindme": "`{0}remindme