Skip to content

Commit

Permalink
Handle not being able to remove attendee
Browse files Browse the repository at this point in the history
  • Loading branch information
trickeydan committed Oct 15, 2024
1 parent ff4e2a4 commit aeca29e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
12 changes: 9 additions & 3 deletions kmibot/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 = {
Expand Down
14 changes: 12 additions & 2 deletions kmibot/modules/pub/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit aeca29e

Please sign in to comment.