Skip to content

Commit

Permalink
Revert "remove debug thing for daily"
Browse files Browse the repository at this point in the history
This reverts commit dd67307.
  • Loading branch information
danydudiot committed Aug 27, 2024
1 parent dd67307 commit 60b8ee0
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 0 deletions.
Empty file added debug.txt
Empty file.
7 changes: 7 additions & 0 deletions src/MySlashCommand.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down
12 changes: 12 additions & 0 deletions src/MyTask.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 8 additions & 0 deletions src/Tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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")


Expand Down

0 comments on commit 60b8ee0

Please sign in to comment.