From da5991bd85aa546ad4828172a06d306a58cdf69d Mon Sep 17 00:00:00 2001 From: Infernum1 <81740112+infernum1@noreply.github.com> Date: Sat, 27 May 2023 00:32:05 +0530 Subject: [PATCH 01/14] enhance reminders system --- bot/cogs/commands/useful.py | 47 +++++++++++++++++++++++-------------- bot/cogs/core/database.py | 9 +++++++ bot/data/text/en.json | 7 +++++- bot/models/translation.py | 4 ++++ 4 files changed, 48 insertions(+), 19 deletions(-) diff --git a/bot/cogs/commands/useful.py b/bot/cogs/commands/useful.py index 6da43767..db354c17 100644 --- a/bot/cogs/commands/useful.py +++ b/bot/cogs/commands/useful.py @@ -636,9 +636,29 @@ 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="reminder", aliases=["remind"]) @commands.cooldown(1, 2, commands.BucketType.user) - async def remind_me(self, ctx: Ctx, duration_str: str, *, reminder: str): + async def reminder_parent(self, ctx: Ctx): + if not ctx.invoked_subcommand: + 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 + ) + + 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) + + @reminder_parent.command(name="add", aliases=["create"]) + @commands.cooldown(1, 2, commands.BucketType.user) + async def reminder_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 +691,15 @@ async def remind_me(self, ctx: Ctx, duration_str: str, *, reminder: str): ) ) - @commands.command(name="reminders") + @reminder_parent.command(name="delete", aliases=["remove"]) @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 reminder_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..728e8f1f 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..d5666fe3 100644 --- a/bot/data/text/en.json +++ b/bot/data/text/en.json @@ -1707,7 +1707,12 @@ "stupid_1": "You used invalid formatting, example: `{0}remindme 1w2d3h4m this is an example` will remind you in one week, two days, three hours, and four minutes.", "time_max": "You cannot set a reminder more than eight weeks in advance.", "remind": "{0} reminding you {1}.", - "reminder": "{0}, you wanted me to remind you: *{1}*" + "reminder": "{0}, you wanted me to remind you: *{1}*", + "none": "*You have no reminders...*", + "add": "You can add reminders with {}remindme", + "unauthorized": "{0}, that is not your reminder.", + "authorized": "{0}, succesfully deleted your reminder." + }, "credits": { "credits": "Villager Bot wouldn't be possible without...", diff --git a/bot/models/translation.py b/bot/models/translation.py index 36fed0ad..b2d7297d 100644 --- a/bot/models/translation.py +++ b/bot/models/translation.py @@ -432,6 +432,10 @@ class Useful_Remind(ImmutableBaseModel): time_max: str remind: str reminder: str + none: str + add: str + unauthorized: str + authorized: str class Useful_Credits(ImmutableBaseModel): From 73448e41064f1857ca2b422c3cb4552f8a2ba510 Mon Sep 17 00:00:00 2001 From: Infernum1 <81740112+infernum1@noreply.github.com> Date: Sat, 27 May 2023 00:32:23 +0530 Subject: [PATCH 02/14] add vscode to gitignore --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index d282b961..01992f60 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,8 @@ __pycache__/ .vscode/ .idea/ +.vscode/ + .mypy_cache/ .ruff_cache/ From 09694cdbb52671b3700959683bb428ea313e2a43 Mon Sep 17 00:00:00 2001 From: Infernum1 <81740112+infernum1@noreply.github.com> Date: Sun, 28 May 2023 00:39:09 +0530 Subject: [PATCH 03/14] revert "add vscode to gitignore" --- .gitignore | 2 -- 1 file changed, 2 deletions(-) diff --git a/.gitignore b/.gitignore index 01992f60..d282b961 100644 --- a/.gitignore +++ b/.gitignore @@ -3,8 +3,6 @@ __pycache__/ .vscode/ .idea/ -.vscode/ - .mypy_cache/ .ruff_cache/ From bc943e5f331701a41618f567d35f5fea9e2e3ca7 Mon Sep 17 00:00:00 2001 From: Infernum1 <81740112+infernum1@noreply.github.com> Date: Sun, 28 May 2023 00:45:11 +0530 Subject: [PATCH 04/14] add translations for reminders --- bot/data/text/en.json | 1 - bot/data/text/es.json | 4 +++- bot/data/text/fr.json | 4 +++- bot/data/text/pt.json | 4 +++- 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/bot/data/text/en.json b/bot/data/text/en.json index d5666fe3..1218d60a 100644 --- a/bot/data/text/en.json +++ b/bot/data/text/en.json @@ -1712,7 +1712,6 @@ "add": "You can add reminders with {}remindme", "unauthorized": "{0}, that is not your reminder.", "authorized": "{0}, succesfully deleted your reminder." - }, "credits": { "credits": "Villager Bot wouldn't be possible without...", diff --git a/bot/data/text/es.json b/bot/data/text/es.json index c66511b5..63cb32d2 100644 --- a/bot/data/text/es.json +++ b/bot/data/text/es.json @@ -1707,7 +1707,9 @@ "stupid_1": "Has usado un formato invalido, ejemplo: `{0}remindme 1w2d3h4m esto es un ejemplo` te recordará en una semana, dos días, tres horas y cuatro minutos.", "time_max": "No puedes poner un recordatorio para mas de ocho semanas.", "remind": "{0} recordatorio {1}.", - "reminder": "{0}, querías que te recuerde: *{1}*" + "reminder": "{0}, querías que te recuerde: *{1}*", + "unauthorized": "{0}, ese no es tu recordatorio.", + "authorized": "{0}, recordatorio eliminado con éxito." }, "credits": { "credits": "Villager Bot no sería posible sin...", diff --git a/bot/data/text/fr.json b/bot/data/text/fr.json index 501d9a5c..afb97b13 100644 --- a/bot/data/text/fr.json +++ b/bot/data/text/fr.json @@ -1707,7 +1707,9 @@ "stupid_1": "Tu as utilisé un format invalide, exemple : `{0}remindme 1w2d3h4m ceci est un exemple` te fera un rappel dans une semaine, deux jours, trois heures, et quatre minutes.", "time_max": "Tu ne peux pas créer un rappel plus de huit semaines en avance.", "remind": "{0} rappel {1}.", - "reminder": "{0}, tu voulais que je te rappelle : *{1}*" + "reminder": "{0}, tu voulais que je te rappelle : *{1}*", + "unauthorized": "{0}, ce rappel ne t’appartient pas.", + "authorized": "{0}, suppression du rappel réussie." }, "credits": { "credits": "Villager Bot n'aurait pas été possible sans ...", diff --git a/bot/data/text/pt.json b/bot/data/text/pt.json index 895972f6..85a47714 100644 --- a/bot/data/text/pt.json +++ b/bot/data/text/pt.json @@ -1707,7 +1707,9 @@ "stupid_1": "Você usou uma formatação inválida, exemplo: `{0}remindme 1w2d3h4m isso é um exemplo` irá lembrá-lo em uma semana, dois dias, três horas e quatro minutos.", "time_max": "Você não pode definir um lembrete com mais de oito semanas de antecedência.", "remind": "{0} será lembrado em {1}.", - "reminder": "{0}, você queria que eu te lembrasse: *{1}*" + "reminder": "{0}, você queria que eu te lembrasse: *{1}*", + "unauthorized": "{0}, esse lembrete não pertence a você.", + "authorized": "{0}, excluiu seu lembrete com sucesso." }, "credits": { "credits": "O Villager Bot não seria possível sem...", From edf7c2ca8dc6f413092b62ae6c02f999d9d25bda Mon Sep 17 00:00:00 2001 From: Infernum1 <81740112+infernum1@noreply.github.com> Date: Sun, 28 May 2023 00:47:49 +0530 Subject: [PATCH 05/14] run black --- bot/cogs/core/database.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bot/cogs/core/database.py b/bot/cogs/core/database.py index 728e8f1f..33794a7d 100644 --- a/bot/cogs/core/database.py +++ b/bot/cogs/core/database.py @@ -65,7 +65,7 @@ async def delete_user_reminder(self, user_id, reminder_id: int) -> bool: ) 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} From 25c563f9e0a78c681d47755d9096542e282eb1ab Mon Sep 17 00:00:00 2001 From: Infernum1 <81740112+infernum1@noreply.github.com> Date: Sun, 28 May 2023 20:10:49 +0530 Subject: [PATCH 06/14] add missing translations --- bot/data/text/es.json | 2 ++ bot/data/text/fr.json | 2 ++ bot/data/text/pt.json | 2 ++ 3 files changed, 6 insertions(+) diff --git a/bot/data/text/es.json b/bot/data/text/es.json index 63cb32d2..6dfcdcbd 100644 --- a/bot/data/text/es.json +++ b/bot/data/text/es.json @@ -1708,6 +1708,8 @@ "time_max": "No puedes poner un recordatorio para mas de ocho semanas.", "remind": "{0} recordatorio {1}.", "reminder": "{0}, querías que te recuerde: *{1}*", + "none": "*No tienes recordatorios...*", + "add": "Puedes añadir recordatorios con {}remindme", "unauthorized": "{0}, ese no es tu recordatorio.", "authorized": "{0}, recordatorio eliminado con éxito." }, diff --git a/bot/data/text/fr.json b/bot/data/text/fr.json index afb97b13..37d462c7 100644 --- a/bot/data/text/fr.json +++ b/bot/data/text/fr.json @@ -1708,6 +1708,8 @@ "time_max": "Tu ne peux pas créer un rappel plus de huit semaines en avance.", "remind": "{0} rappel {1}.", "reminder": "{0}, tu voulais que je te rappelle : *{1}*", + "none": "Tu n’a aucun rappels...", + "add": "Tu peux ajouter des rappels avec {}remindme", "unauthorized": "{0}, ce rappel ne t’appartient pas.", "authorized": "{0}, suppression du rappel réussie." }, diff --git a/bot/data/text/pt.json b/bot/data/text/pt.json index 85a47714..cf2de97a 100644 --- a/bot/data/text/pt.json +++ b/bot/data/text/pt.json @@ -1708,6 +1708,8 @@ "time_max": "Você não pode definir um lembrete com mais de oito semanas de antecedência.", "remind": "{0} será lembrado em {1}.", "reminder": "{0}, você queria que eu te lembrasse: *{1}*", + "none": "*Você não tem lembretes...*", + "add": "Você pode adicionar lembretes com {}remindme", "unauthorized": "{0}, esse lembrete não pertence a você.", "authorized": "{0}, excluiu seu lembrete com sucesso." }, From 1c1b2257f93b36758f63d3aa4374c14ef75e0a96 Mon Sep 17 00:00:00 2001 From: Infernum1 <81740112+infernum1@noreply.github.com> Date: Sun, 28 May 2023 20:49:03 +0530 Subject: [PATCH 07/14] minor convenience changes --- bot/cogs/commands/useful.py | 44 +++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/bot/cogs/commands/useful.py b/bot/cogs/commands/useful.py index db354c17..b1da46c0 100644 --- a/bot/cogs/commands/useful.py +++ b/bot/cogs/commands/useful.py @@ -636,29 +636,31 @@ async def image_search(self, ctx: Ctx, *, query): await ctx.reply_embed(ctx.l.useful.search.nope) return - @commands.group(name="reminder", aliases=["remind"]) + @commands.group(name="reminders", aliases=["reminder", "remind"]) @commands.cooldown(1, 2, commands.BucketType.user) - async def reminder_parent(self, ctx: Ctx): - if not ctx.invoked_subcommand: - 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(self, ctx: Ctx): + if ctx.invoked_subcommand: + 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) + 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 + ) + + 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) - @reminder_parent.command(name="add", aliases=["create"]) + @reminders.command(name="add", aliases=["create"]) @commands.cooldown(1, 2, commands.BucketType.user) - async def reminder_add(self, ctx: Ctx, duration_str: str, *, reminder: str): + 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: @@ -691,9 +693,9 @@ async def reminder_add(self, ctx: Ctx, duration_str: str, *, reminder: str): ) ) - @reminder_parent.command(name="delete", aliases=["remove"]) + @reminders.command(name="delete", aliases=["remove"]) @commands.cooldown(1, 2, commands.BucketType.user) - async def reminder_remove(self, ctx: Ctx, reminder_id: int): + 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)) From 10a8ee0088831965d2bd590cb17bac4c36234d07 Mon Sep 17 00:00:00 2001 From: Infernum11 <81740112+Infernum1@users.noreply.github.com> Date: Mon, 29 May 2023 00:46:01 +0530 Subject: [PATCH 08/14] add aliases to `reminder_delete` Co-authored-by: Milo Weinberg <38477514+Iapetus-11@users.noreply.github.com> --- bot/cogs/commands/useful.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bot/cogs/commands/useful.py b/bot/cogs/commands/useful.py index b1da46c0..ba7707e1 100644 --- a/bot/cogs/commands/useful.py +++ b/bot/cogs/commands/useful.py @@ -693,7 +693,7 @@ async def reminders_add(self, ctx: Ctx, duration_str: str, *, reminder: str): ) ) - @reminders.command(name="delete", aliases=["remove"]) + @reminders.command(name="delete", aliases=["remove", "rm", "del"]) @commands.cooldown(1, 2, commands.BucketType.user) async def reminders_remove(self, ctx: Ctx, reminder_id: int): deleted = await self.db.delete_user_reminder(ctx.author.id, reminder_id) From 6cd13010f55230c9667b36b306c61bb75c35f180 Mon Sep 17 00:00:00 2001 From: Infernum1 <81740112+infernum1@noreply.github.com> Date: Mon, 29 May 2023 22:42:38 +0530 Subject: [PATCH 09/14] add help text for reminders command --- bot/data/text/en.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/bot/data/text/en.json b/bot/data/text/en.json index 1218d60a..45a8f300 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