Skip to content

Commit

Permalink
refactor: add ServerState.get_messages(limit=) parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
thegamecracks committed Dec 10, 2024
1 parent c80d976 commit e6d304f
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/dumdum/server/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,14 @@ def get_messages(
*,
before: int | None = None,
after: int | None = None,
limit: int = 100,
) -> Sequence[Message]:
return self.message_cache.get_messages(channel_name, before=before, after=after)
return self.message_cache.get_messages(
channel_name,
before=before,
after=after,
limit=limit,
)

def add_message(self, message: Message) -> None:
return self.message_cache.add_message(message)
Expand Down Expand Up @@ -92,6 +98,7 @@ def get_messages(
*,
before: int | None = None,
after: int | None = None,
limit: int = 100,
) -> Sequence[Message]:
messages = list(self._channel_messages[channel_name])

Expand All @@ -103,7 +110,7 @@ def get_messages(
i = bisect.bisect_right(messages, after, key=lambda m: m.id)
messages = messages[:i]

return messages[-100:]
return messages[-limit:]

def remove_message(self, channel_name: str, id: int) -> Message | None:
messages = self._channel_messages[channel_name]
Expand Down

0 comments on commit e6d304f

Please sign in to comment.