Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance reminders system #265

Merged
merged 14 commits into from
Jun 18, 2023
53 changes: 35 additions & 18 deletions bot/cogs/commands/useful.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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):
Expand Down
9 changes: 9 additions & 0 deletions bot/cogs/core/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
9 changes: 6 additions & 3 deletions bot/data/text/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,13 @@
"youtube": "`{0}youtube <search>` *searches on youtube for your query*",
"image": "`{0}image <search>` *searches google images for your query*",
"math": "`{0}math <problem>` *solves a math problem",
"remindme": "`{0}remindme <time> <reminder>` *reminds you in a specified time*",
"credits": "`{0}credits` *shows who helped make Villager Bot*",
"snipe": "`{0}snipe` *shows the latest deleted message in the current channel*",
"redditdl": "`{0}redditdl <reddit post url>` *downloads the specified media from Reddit*",
"exif": "`{0}exif` *extracts EXIF data from the specified image*",
"imagetopng": "`{0}imagetopng *converts the uploaded/specified image to a png*",
"translate": "`{0}translate <target> [text]` *translates the given text or message to the specified target language*",
"reminders": "`{0}reminders` *shows you all your current reminders*"
"reminders": "`{0}reminders` `add` *or* `remove` *to add or remove a reminder respectively*"
Iapetus-11 marked this conversation as resolved.
Show resolved Hide resolved
},
"fun": {
"cursed": "`{0}cursed` *sends a random cursed Minecraft image*",
Expand Down Expand Up @@ -1707,7 +1706,11 @@
"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 {}reminder add <duration> <text>",
"unauthorized": "{0} that is not your reminder.",
"authorized": "{0} succesfully deleted your reminder."
},
"credits": {
"credits": "Villager Bot wouldn't be possible without...",
Expand Down
8 changes: 6 additions & 2 deletions bot/data/text/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@
"exif": "`{0}exif` *Extrae datos EXIF de la imagen especificada*",
"imagetopng": "`{0}imagetopng *convierte la imagen subida/especificada en png*",
"translate": "`{0}translate <target> [text]` *Traduce el texto enviado al idioma especificado*",
"reminders": "`{0}reminders`*muestra todos tus recordatorios activos*"
"reminders": "`{0}reminders` `add` *o* `remove` *para añadir o eliminar un recordatorio, respectivamente*"
},
"fun": {
"cursed": "`{0}cursed` *envía una imagen Minecraft maldita al azar*",
Expand Down Expand Up @@ -1707,7 +1707,11 @@
"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}*",
"none": "*No tienes recordatorios...*",
"add": "Puedes añadir recordatorios con {}reminder add <duración> <texto>",
"unauthorized": "{0} ese no es tu recordatorio.",
"authorized": "{0} recordatorio eliminado con éxito."
},
"credits": {
"credits": "Villager Bot no sería posible sin...",
Expand Down
8 changes: 6 additions & 2 deletions bot/data/text/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@
"exif": "`{0}exif` *extrait les données EXIF de l'image spécifiée*",
"imagetopng": "`{0}imagetopng *convertis l'image installée/spécifiée en png*",
"translate": "`{0}translate <target> [text]` *traduit le texte donné ou le message vers la langue de la cible spécifiée*",
"reminders": "`{0}reminders` *montre tout tes rappels actuels*"
"reminders": "`{0}reminders` `add` *ou* `remove` *ajouter ou supprimer un rappel respectivement*"
},
"fun": {
"cursed": "`{0}cursed` *envoie une image cursed de Minecraft*",
Expand Down Expand Up @@ -1707,7 +1707,11 @@
"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}*",
"none": "Tu n’a aucun rappels...",
"add": "Tu peux ajouter des rappels avec {}reminder add <durée> <texte>",
"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 ...",
Expand Down
8 changes: 6 additions & 2 deletions bot/data/text/pt.json
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@
"exif": "`{0}exif` *extrai dados EXIF da imagem especificada*",
"imagetopng": "`{0}imagetopng *converte a imagem enviada/especificada para um png*",
"translate": "`{0}translate <alvo> [texto]` *traduz o texto ou a mensagem fornecida para o idioma de destino especificado*",
"reminders": "`{0}reminders` *mostra todos os seus lembretes atuais*"
"reminders": "`{0}reminders` `add` *ou* `remove` *para adicionar ou remover um lembrete, respectivamente*"
},
"fun": {
"cursed": "`{0}cursed` *envia uma imagem aleatória maldita do Minecraft*",
Expand Down Expand Up @@ -1707,7 +1707,11 @@
"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}*",
"none": "*Você não tem lembretes...*",
"add": "Você pode adicionar lembretes com {}reminder add <duração> <texto>",
"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...",
Expand Down
4 changes: 4 additions & 0 deletions bot/models/translation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down