From 7f6135801d951ed68c9241dd6458f5885105ccc6 Mon Sep 17 00:00:00 2001 From: Choco <94597336+ChocoMeow@users.noreply.github.com> Date: Sun, 5 Oct 2025 22:39:07 +0800 Subject: [PATCH] Add items property to Pagination and refactor QueueView Introduced an 'items' property to the Pagination class for direct access to the underlying items list. Refactored QueueView to use this new property, improving code clarity and consistency. --- voicelink/views/queue.py | 16 +++++++--------- voicelink/views/utils/pagination.py | 12 +++++++++++- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/voicelink/views/queue.py b/voicelink/views/queue.py index 5a8dc23..69e1521 100644 --- a/voicelink/views/queue.py +++ b/voicelink/views/queue.py @@ -52,12 +52,6 @@ class QueueView(PaginationView): """ def __init__(self, player: "Player", author: discord.Member, is_queue: bool = True) -> None: - - self.player: Player = player - self.is_queue: bool = is_queue - self.total_duration = self.calculate_total_duration() - self.response: discord.Message = None - super().__init__( Pagination["Track"]( items=player.queue.tracks() if is_queue else list(reversed(player.queue.history())), @@ -66,18 +60,22 @@ class QueueView(PaginationView): author ) + self.player: Player = player + self.is_queue: bool = is_queue + self.total_duration = self.calculate_total_duration() + self.response: discord.Message = None + def calculate_total_duration(self) -> str: """Calculate the total duration of the tracks.""" try: - return format_ms(sum(track.length for track in self.pagination._items)) + return format_ms(sum(track.length for track in self.pagination.items)) except Exception: return "∞" def format_description(self, tracks: list["Track"], texts: list[str]) -> str: """Format the description for the embed based on current tracks.""" now_playing = ( - texts[1].format(self.player.current.uri, - f"```{self.player.current.title}```") + texts[1].format(self.player.current.uri, f"```{self.player.current.title}```") if self.player.current else texts[2].format("None") ) diff --git a/voicelink/views/utils/pagination.py b/voicelink/views/utils/pagination.py index 3a48070..339dab3 100644 --- a/voicelink/views/utils/pagination.py +++ b/voicelink/views/utils/pagination.py @@ -165,4 +165,14 @@ class Pagination(Generic[T]): Returns: int: The total number of items across all pages. """ - return len(self._items) \ No newline at end of file + return len(self._items) + + @property + def items(self) -> List[T]: + """ + Gets the list of all items in the pagination. + + Returns: + List[T]: The list of all items. + """ + return self._items \ No newline at end of file