Skip to content

Commit

Permalink
Use ferry sequence from API
Browse files Browse the repository at this point in the history
  • Loading branch information
trickeydan committed Dec 4, 2024
1 parent c288f25 commit dbbfcb6
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 20 deletions.
1 change: 1 addition & 0 deletions kmibot/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def get_display_for_message(self) -> str:

class PersonWithScoreSchema(PersonSchema):
current_score: float
ferry_sequence: str


class PersonLinkSchema(BaseModel):
Expand Down
22 changes: 2 additions & 20 deletions kmibot/modules/ferry/commands.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
from __future__ import annotations

import math
import random
from logging import getLogger
from typing import TYPE_CHECKING, Any
from typing import TYPE_CHECKING

import discord
from discord.app_commands import Group, command, describe
Expand All @@ -19,21 +17,6 @@
if TYPE_CHECKING:
from . import FerryModule

FERRY = "⛴️"
TRAIN = "🚂"

FRONT_OF_TRAIN = [":bullettrain_front:", ":bullettrain_side:", ":steam_locomotive:", ":light_rail:"]
TRAIN_PARTS = [":train:", ":railway_car:"]


def ferrify(count: int, seed: Any | None = None) -> str:
if count == 0:
return ""

ra = random.Random(x=seed)
train = [ra.choice(FRONT_OF_TRAIN)] + ra.choices(TRAIN_PARTS, k=count - 1)
return "".join(train)


class FerryCommand(Group):
def __init__(self, config: BotConfig, module: FerryModule) -> None:
Expand All @@ -44,8 +27,7 @@ def __init__(self, config: BotConfig, module: FerryModule) -> None:
async def get_leaderboard(self) -> str:
people = await self.ferry_module.api_client.get_leaderboard() # type: ignore[has-type]
content = [
f"{person.get_display_for_message()} {ferrify(math.ceil(person.current_score), person.id.int)}"
for person in people
f"{person.get_display_for_message()} {person.ferry_sequence}" for person in people
]
return "\n".join(["Bad people:"] + content)

Expand Down

0 comments on commit dbbfcb6

Please sign in to comment.