From e6d304fe0109a91d13f92c6b16c90f2ac8b17515 Mon Sep 17 00:00:00 2001 From: thegamecracks <61257169+thegamecracks@users.noreply.github.com> Date: Tue, 10 Dec 2024 18:13:24 -0500 Subject: [PATCH] refactor: add ServerState.get_messages(limit=) parameter --- src/dumdum/server/state.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/dumdum/server/state.py b/src/dumdum/server/state.py index ccd52cb..7b5bb48 100644 --- a/src/dumdum/server/state.py +++ b/src/dumdum/server/state.py @@ -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) @@ -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]) @@ -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]