From 60b8ee0fe4190b1e5a8cedd2865c1ec64c7f8930 Mon Sep 17 00:00:00 2001 From: Dany Date: Tue, 27 Aug 2024 11:00:21 +0200 Subject: [PATCH] Revert "remove debug thing for daily" This reverts commit dd673072ca9966f2be44d4f0d03255652b8334b7. --- debug.txt | 0 src/MySlashCommand.py | 7 +++++++ src/MyTask.py | 12 ++++++++++++ src/Tool.py | 8 ++++++++ 4 files changed, 27 insertions(+) create mode 100644 debug.txt diff --git a/debug.txt b/debug.txt new file mode 100644 index 0000000..e69de29 diff --git a/src/MySlashCommand.py b/src/MySlashCommand.py index c3dad48..3e9f3ad 100644 --- a/src/MySlashCommand.py +++ b/src/MySlashCommand.py @@ -98,6 +98,13 @@ async def bd(self, ctx: SlashContext) -> None: """Permet de scanner tous les membres du serveur et de mettre à jour la BD.""" await ctx.send("Voici la BD.", file="data/UserBase.pkl", ephemeral=False) + @slash_command(name="debug", description="Permet d'obtenir' BD.", + default_member_permissions=Permissions.ADMINISTRATOR) + @contexts(guild=True, bot_dm=False) + async def debug(self, ctx: SlashContext) -> None: + """Permet de scanner tous les membres du serveur et de mettre à jour la BD.""" + await ctx.send("Voici le debug.", file="debug.txt", ephemeral=False) + @slash_command(name="help", description="Affiche la page d'Aide.") async def help(self, ctx: SlashContext) -> None: """Affiche le Contenu de HELP.md.""" diff --git a/src/MyTask.py b/src/MyTask.py index fe2eb82..d710a95 100644 --- a/src/MyTask.py +++ b/src/MyTask.py @@ -70,12 +70,24 @@ async def update_calendar(self) -> None: @Task.create(TimeTrigger(hour=6, minute=0, seconds=0, utc=False)) async def daily_morning_update(self) -> None: """Permet d'envoyer les EDT automatiquement.""" + with open("debug.txt", "a", encoding="UTF-8") as f: + f.write(f"début de la task {datetime.now()}\n\n") user_base = get_user_base() # Pour l'envoi hebdomadaire. if datetime.today().weekday() == 0: for id in user_base.weekly_subscribed_users: + with open("debug.txt", "a", encoding="UTF-8") as f: + f.write(f"début for {id}\n") await self.tool.send_weekly_update(self.bot.get_user(id)) + with open("debug.txt", "a", encoding="UTF-8") as f: + f.write(f"fin for {id}\n") + await asyncio.sleep(1) # Sinon ça fait une pile d'envoi et ça envoie un message plusieurs fois # Pour l'envoi quotidien. if datetime.today().weekday() <= 4: # Si on est le week end for id in user_base.daily_subscribed_users: + with open("debug.txt", "a", encoding="UTF-8") as f: + f.write(f"début for {id}\n") await self.tool.send_daily_update(self.bot.get_user(id)) + with open("debug.txt", "a", encoding="UTF-8") as f: + f.write(f"fin for {id}\n") + await asyncio.sleep(1) # Sinon ça fait une pile d'envoi et ça envoie un message plusieurs fois diff --git a/src/Tool.py b/src/Tool.py index 6ea0a8d..7dfd235 100644 --- a/src/Tool.py +++ b/src/Tool.py @@ -214,7 +214,11 @@ async def send_daily_update(self, user: User): embeds = get_embeds(events, user, date.today()) filename = str(user.id) ics_file = get_ics(events, filename=filename) + with open("debug.txt", "a", encoding="UTF-8") as f: + f.write(f"avant envoi pour {user.id}\n") await user.send(":warning: : Le calendrier n'est pas mis a jour dynamiquement", embeds=embeds, files=[f"{filename}.ics"], ephemeral=False) + with open("debug.txt", "a", encoding="UTF-8") as f: + f.write(f"après envoi pour {user.id}\n") os.remove(f"{filename}.ics") async def send_weekly_update(self, user: User): @@ -226,7 +230,11 @@ async def send_weekly_update(self, user: User): events = filter_events (get_calendar().get_events(), [TimeFilter(monday_date, Timing.AFTER), TimeFilter(sunday_date, Timing.BEFORE), self.get_filiere(user), self.get_groupes(user)]) ics_file = get_ics(events, filename=filename) + with open("debug.txt", "a", encoding="UTF-8") as f: + f.write(f"avant envoi pour {user.id}\n") await user.send(":warning: : Le calendrier n'est pas mis a jour dynamiquement", embeds=get_embeds(events, user, monday_date, sunday_date), files=[f"{filename}.ics"], ephemeral=False) + with open("debug.txt", "a", encoding="UTF-8") as f: + f.write(f"après envoi pour {user.id}\n") os.remove(f"{filename}.ics")