From aeca29ead5b02504cd08a1fc5369781c63db417c Mon Sep 17 00:00:00 2001 From: Dan Trickey Date: Tue, 15 Oct 2024 19:48:41 +0100 Subject: [PATCH] Handle not being able to remove attendee --- kmibot/api.py | 12 +++++++++--- kmibot/modules/pub/__init__.py | 14 ++++++++++++-- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/kmibot/api.py b/kmibot/api.py index da6ab48..7a43b4a 100644 --- a/kmibot/api.py +++ b/kmibot/api.py @@ -33,10 +33,12 @@ class PersonWithScoreSchema(PersonSchema): class PersonLinkSchema(BaseModel): id: UUID display_name: str - + + class PersonLinkWithDiscordSchema(PersonLinkSchema): discord_id: int | None + class ConsequenceLinkSchema(BaseModel): id: UUID content: str @@ -267,16 +269,20 @@ async def add_attendee_to_pub_event(self, pub_event_id: UUID, person_id: UUID) - except httpx.HTTPStatusError as exc: LOGGER.exception(exc) - async def remove_attendee_from_pub_event(self, pub_event_id: UUID, person_id: UUID) -> None: + async def remove_attendee_from_pub_event( + self, pub_event_id: UUID, person_id: UUID + ) -> PubEventSchema | None: payload = { "person": str(person_id), } try: - await self._request( + data = await self._request( "POST", f"v2/pub/events/{pub_event_id}/attendees/remove/", json=payload ) + return PubEventSchema.model_validate(data) except httpx.HTTPStatusError as exc: LOGGER.exception(exc) + return None async def update_table_for_pub_event(self, pub_event_id: UUID, table_number: int) -> None: payload = { diff --git a/kmibot/modules/pub/__init__.py b/kmibot/modules/pub/__init__.py index f36f82c..3e86086 100644 --- a/kmibot/modules/pub/__init__.py +++ b/kmibot/modules/pub/__init__.py @@ -74,8 +74,18 @@ async def on_scheduled_event_user_remove( pub_event = await self.api_client.get_pub_event_by_discord_id(event.id) if pub_event: person = await self.api_client.get_person_for_discord_member(user) - await self.api_client.remove_attendee_from_pub_event(pub_event.id, person.id) - LOGGER.info(f"Removed {person.display_name} from {pub_event}") + pub_event = await self.api_client.remove_attendee_from_pub_event( + pub_event.id, person.id + ) + + if pub_event: + attendee_ids = {a.id for a in pub_event.attendees} + if person.id in attendee_ids: + await user.send( + f"You have removed your interest from the pub on {pub_event.timestamp}, but you are still registered on the pub system. Please log in and RSVP." + ) + else: + LOGGER.info(f"Removed {person.display_name} from {pub_event}") async def handle_pub_event_change( self,