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.
This commit is contained in:
@@ -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")
|
||||
)
|
||||
|
||||
|
||||
@@ -165,4 +165,14 @@ class Pagination(Generic[T]):
|
||||
Returns:
|
||||
int: The total number of items across all pages.
|
||||
"""
|
||||
return len(self._items)
|
||||
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
|
||||
Reference in New Issue
Block a user