From 073291aa2896a48c59b314737655fc5dfa3abed1 Mon Sep 17 00:00:00 2001 From: Choco <94597336+ChocoMeow@users.noreply.github.com> Date: Tue, 20 Feb 2024 11:34:40 +0800 Subject: [PATCH] Removed chapter view --- views/__init__.py | 1 - views/chapter.py | 89 ----------------------------------------------- 2 files changed, 90 deletions(-) delete mode 100644 views/chapter.py diff --git a/views/__init__.py b/views/__init__.py index 8b1a82b..f060dd4 100644 --- a/views/__init__.py +++ b/views/__init__.py @@ -9,7 +9,6 @@ from .search import SearchView from .help import HelpView from .list import ListView from .lyrics import LyricsView -from .chapter import ChapterView from .playlist import PlaylistView from .inbox import InboxView from .link import LinkView diff --git a/views/chapter.py b/views/chapter.py deleted file mode 100644 index ad67d16..0000000 --- a/views/chapter.py +++ /dev/null @@ -1,89 +0,0 @@ -"""MIT License - -Copyright (c) 2023 - present Vocard Development - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -""" -from __future__ import annotations - -import discord - -from function import formatTime -from typing import TYPE_CHECKING -if TYPE_CHECKING: - from voicelink import Player - -class Dropdown(discord.ui.Select): - def __init__(self, player: Player, chapters): - self.view: ChapterView - - self.player: Player = player - self.chapters: list[str] = chapters - self.current: str = player.current.uri - - super().__init__( - placeholder=self.player.get_msg('chaptersDropdown'), - min_values=1, max_values=1, - options=[ - discord.SelectOption(label=f"{index}. {title[:30]}", description=time) - for index, (time, title) in enumerate(self.chapters, start=1) - ][:25] - ) - - async def callback(self, interaction: discord.Interaction): - position = formatTime(self.chapters[int(self.values[0].split(". ")[0]) - 1][0]) - if position is None: - return - if not self.player.current or self.current != self.player.current.uri: - return await self.view.stop_view() - - await self.player.seek(position) - await interaction.response.send_message(self.player.get_msg('seek').format(formatTime(position))) - -class ChapterView(discord.ui.View): - def __init__( - self, - player: Player, - chapters: list[str], - author: discord.Member - ) -> None: - super().__init__(timeout=180) - - self.player: Player = player - self.chapters: list[str] = chapters - self.author: discord.Member = author - self.response: discord.Message = None - self.add_item(Dropdown(player, chapters)) - - async def on_error(self, error: Exception, item, interaction) -> None: - return - - async def stop_view(self) -> None: - for child in self.children: - child.disabled = True - try: - await self.response.edit(view=self) - except: - pass - - async def on_timeout(self) -> None: - await self.stop_view() - - async def interaction_check(self, interaction: discord.Interaction): - return interaction.user == self.author \ No newline at end of file