premier fix pour le discord bot qui envoie des reminders sur des versions de matchs qui n'existent plus
CI - Security, Lint & Tests / validate (push) Failing after 1m5s

This commit is contained in:
cedrick2711
2026-09-06 13:49:07 -04:00
parent e4a271cfd8
commit e2e2b1b07e
9 changed files with 114 additions and 163 deletions
+50 -3
View File
@@ -492,6 +492,19 @@ class TeamTryoutsBot(commands.Bot):
await self._send_schedule_notification(**item['data'])
elif kind == 'one_on_one_response':
await self._send_one_on_one_response_dm(**item['data'])
elif kind == 'purge_pending':
participant_ids = item.get('data', {}).get('participant_ids', [])
if participant_ids:
changed = False
for msg_id, record in list(self.pending_requests.items()):
if (
record.get('type') == 'schedule_addition'
and record.get('id') in participant_ids
):
del self.pending_requests[msg_id]
changed = True
if changed:
self._save_pending()
else:
logger.error('Unknown queue item type %r; the notification was dropped', kind)
@@ -992,6 +1005,12 @@ class TeamTryoutsBot(commands.Bot):
player.id,
reference_id,
)
else:
# The row no longer exists (e.g. match was edited, participant
# was deleted). Silently drop the stale pending entry so the
# reaction is not answerable again. No user-facing reply.
self._forget_pending(message_id)
return
except SQLAlchemyError:
db.session.rollback()
logger.exception(
@@ -1040,6 +1059,11 @@ class TeamTryoutsBot(commands.Bot):
db.session.delete(row)
else:
row.status = 'no_show'
else:
# The row no longer exists. Silently drop the stale pending
# entry so the reaction is not answerable again.
self._forget_pending(message_id)
return
except SQLAlchemyError:
db.session.rollback()
logger.exception(
@@ -1222,10 +1246,11 @@ class TeamTryoutsBot(commands.Bot):
async def send_match_reminder(self, player, match):
"""Send match reminder to player. True if it was delivered."""
date_str = match.date.strftime('%A, %B %d, %Y') if match.date else 'TBD'
message = (
"🔔 **Match Reminder**\n\n"
f"Your match **{match.title}** is scheduled for tomorrow:\n"
f"**Date:** {match.date.strftime('%A, %B %d, %Y')}\n"
f"**Date:** {date_str}\n"
f"**Time:** {match.start_time.strftime('%I:%M %p') if match.start_time else 'TBD'} - "
f"{match.end_time.strftime('%I:%M %p') if match.end_time else 'TBD'}\n"
f"**Location:** {match.location or 'TBD'}\n\n"
@@ -1241,10 +1266,11 @@ class TeamTryoutsBot(commands.Bot):
async def send_tryout_reminder(self, player, tryout):
"""Send tryout reminder to player. True if it was delivered."""
date_str = tryout.date.strftime('%A, %B %d, %Y') if tryout.date else 'TBD'
message = (
"🔔 **Tryout Reminder**\n\n"
f"Your tryout **{tryout.title}** is scheduled for tomorrow:\n"
f"**Date:** {tryout.date.strftime('%A, %B %d, %Y')}\n"
f"**Date:** {date_str}\n"
f"**Location:** {tryout.location or 'TBD'}\n\n"
"Please confirm your attendance in the app."
)
@@ -1314,10 +1340,11 @@ class TeamTryoutsBot(commands.Bot):
async def send_one_on_one_reminder(self, player, session):
"""Send One on One reminder to player. True if it was delivered."""
date_str = session.date.strftime('%A, %B %d, %Y') if session.date else 'TBD'
message = (
"🔔 **One on One Reminder**\n\n"
f"Your One on One session with **{session.coach.full_name}** is scheduled for tomorrow:\n"
f"**Date:** {session.date.strftime('%A, %B %d, %Y')}\n"
f"**Date:** {date_str}\n"
f"**Time:** {session.start_time.strftime('%I:%M %p')} - {session.end_time.strftime('%I:%M %p')}\n"
f"**Discussion Points:** {session.points or 'No specific points provided'}\n\n"
"Please prepare for your session!"
@@ -1433,6 +1460,26 @@ def send_schedule_notification(
)
def purge_pending_for_participants(participant_ids):
"""Queue a purge of pending Discord entries for stale participant rows.
Called after a match edit deletes participants. The bot thread removes
matching ``schedule_addition`` pending entries so that a reaction on an
old message cannot produce a false confirmation.
Args:
participant_ids: list[int] of MatchParticipant primary keys that no
longer exist.
"""
if not participant_ids:
return None
return _enqueue(
'purge_pending',
{'participant_ids': participant_ids},
description=f'purge of {len(participant_ids)} stale participant records',
)
def send_one_on_one_response(
player_discord_id: str,
player_full_name: str,