Skip to content

Commit

Permalink
Add FACT command
Browse files Browse the repository at this point in the history
  • Loading branch information
trickeydan committed Sep 12, 2024
1 parent 1024d7a commit d0ff31a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
8 changes: 8 additions & 0 deletions kmibot/modules/ferry/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ class AccusationSchema(BaseModel):
updated_at: datetime


class FactSchema(BaseModel):
link_token: str | None


class FerryAPI:
def __init__(self, api_url: str, api_key: str) -> None:
self._api_url = api_url
Expand Down Expand Up @@ -114,6 +118,10 @@ async def get_person_for_discord_member(
data = await self._request("POST", "v2/people/", json=payload)
return PersonSchema.model_validate(data)

async def get_fact_for_person(self, person_id: UUID) -> FactSchema:
data = await self._request("GET", f"v2/people/{person_id}/fact/")
return FactSchema.model_validate(data)

async def create_accusation(
self, created_by: UUID, suspect: UUID, quote: str
) -> AccusationSchema:
Expand Down
22 changes: 22 additions & 0 deletions kmibot/modules/ferry/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,25 @@ async def scoreboard(self, interaction: discord.Interaction) -> None:
LOGGER.info(f"{interaction.user} used /ferry scoreboard")
leaderboard = await self.get_leaderboard()
await interaction.response.send_message(leaderboard, ephemeral=True)

@command(description="Get a FACT")
async def fact(self, interaction: discord.Interaction) -> None:
LOGGER.info(f"{interaction.user} used /ferry fact")
try:
person = await self.ferry_module.api_client.get_person_for_discord_member( # type: ignore[has-type]
interaction.user
)
fact_data = await self.ferry_module.api_client.get_fact_for_person(person.id) # type: ignore[has-type]
except httpx.HTTPStatusError as exc:
LOGGER.exception(exc)
await interaction.response.send_message("Unable to get FACT", ephemeral=True)
return

if fact_data.link_token is None:
await interaction.response.send_message(
"Sorry, no FACT is currently available.", ephemeral=True
)
else:
await interaction.response.send_message(
f"Your FACT is `{fact_data.link_token}`.", ephemeral=True
)

0 comments on commit d0ff31a

Please sign in to comment.