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
49 changes: 31 additions & 18 deletions bot/cogs/commands/useful.py
Original file line number Diff line number Diff line change
Expand Up @@ -636,9 +636,31 @@ 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
)

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 +693,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
6 changes: 5 additions & 1 deletion bot/data/text/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1707,7 +1707,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 {}remindme",
"unauthorized": "{0}, that is not your reminder.",
"authorized": "{0}, succesfully deleted your reminder."
},
"credits": {
"credits": "Villager Bot wouldn't be possible without...",
Expand Down
6 changes: 5 additions & 1 deletion bot/data/text/es.json
Original file line number Diff line number Diff line change
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 {}remindme",
"unauthorized": "{0}, ese no es tu recordatorio.",
"authorized": "{0}, recordatorio eliminado con éxito."
},
"credits": {
"credits": "Villager Bot no sería posible sin...",
Expand Down
6 changes: 5 additions & 1 deletion bot/data/text/fr.json
Original file line number Diff line number Diff line change
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 {}remindme",
"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
6 changes: 5 additions & 1 deletion bot/data/text/pt.json
Original file line number Diff line number Diff line change
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 {}remindme",
"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