mirror of
https://github.com/RafaelSolVargas/Vulkan.git
synced 2025-10-29 16:57:23 +00:00
Subclassing Button class for each button, changing context interface for handlers
This commit is contained in:
24
UI/Buttons/BackButton.py
Normal file
24
UI/Buttons/BackButton.py
Normal file
@@ -0,0 +1,24 @@
|
||||
from discord import ButtonStyle, Interaction
|
||||
from discord.ui import Button
|
||||
from Config.Emojis import VEmojis
|
||||
from Handlers.PrevHandler import PrevHandler
|
||||
from Music.VulkanBot import VulkanBot
|
||||
|
||||
|
||||
class BackButton(Button):
|
||||
def __init__(self, bot: VulkanBot):
|
||||
super().__init__(label="Back", style=ButtonStyle.secondary, emoji=VEmojis().BACK)
|
||||
self.__bot = bot
|
||||
|
||||
async def callback(self, interaction: Interaction) -> None:
|
||||
await interaction.response.defer()
|
||||
|
||||
handler = PrevHandler(interaction, self.__bot)
|
||||
response = await handler.run()
|
||||
print(response)
|
||||
print(response.success)
|
||||
print(response.error)
|
||||
print(response.error)
|
||||
print(response.embed)
|
||||
if response.embed:
|
||||
await interaction.followup.send(embed=response.embed)
|
||||
11
UI/Buttons/LoopAllButton.py
Normal file
11
UI/Buttons/LoopAllButton.py
Normal file
@@ -0,0 +1,11 @@
|
||||
from discord import ButtonStyle, Interaction
|
||||
from discord.ui import Button
|
||||
from Config.Emojis import VEmojis
|
||||
|
||||
|
||||
class LoopAllButton(Button):
|
||||
def __init__(self):
|
||||
super().__init__(label="Loop All", style=ButtonStyle.secondary, emoji=VEmojis().LOOP_ALL)
|
||||
|
||||
async def callback(self, interaction: Interaction) -> None:
|
||||
pass
|
||||
11
UI/Buttons/LoopOffButton.py
Normal file
11
UI/Buttons/LoopOffButton.py
Normal file
@@ -0,0 +1,11 @@
|
||||
from discord import ButtonStyle, Interaction
|
||||
from discord.ui import Button
|
||||
from Config.Emojis import VEmojis
|
||||
|
||||
|
||||
class LoopOffButton(Button):
|
||||
def __init__(self):
|
||||
super().__init__(label="Loop Off", style=ButtonStyle.secondary, emoji=VEmojis().LOOP_OFF)
|
||||
|
||||
async def callback(self, interaction: Interaction) -> None:
|
||||
pass
|
||||
11
UI/Buttons/LoopOneButton.py
Normal file
11
UI/Buttons/LoopOneButton.py
Normal file
@@ -0,0 +1,11 @@
|
||||
from discord import ButtonStyle, Interaction
|
||||
from discord.ui import Button
|
||||
from Config.Emojis import VEmojis
|
||||
|
||||
|
||||
class LoopOneButton(Button):
|
||||
def __init__(self):
|
||||
super().__init__(label="Loop One", style=ButtonStyle.secondary, emoji=VEmojis().LOOP_ONE)
|
||||
|
||||
async def callback(self, interaction: Interaction) -> None:
|
||||
pass
|
||||
11
UI/Buttons/PauseButton.py
Normal file
11
UI/Buttons/PauseButton.py
Normal file
@@ -0,0 +1,11 @@
|
||||
from discord import ButtonStyle, Interaction
|
||||
from discord.ui import Button
|
||||
from Config.Emojis import VEmojis
|
||||
|
||||
|
||||
class PauseButton(Button):
|
||||
def __init__(self):
|
||||
super().__init__(label="Pause", style=ButtonStyle.secondary, emoji=VEmojis().PAUSE)
|
||||
|
||||
async def callback(self, interaction: Interaction) -> None:
|
||||
pass
|
||||
11
UI/Buttons/PlayButton.py
Normal file
11
UI/Buttons/PlayButton.py
Normal file
@@ -0,0 +1,11 @@
|
||||
from discord import ButtonStyle, Interaction
|
||||
from discord.ui import Button
|
||||
from Config.Emojis import VEmojis
|
||||
|
||||
|
||||
class PlayButton(Button):
|
||||
def __init__(self):
|
||||
super().__init__(label="Play", style=ButtonStyle.secondary, emoji=VEmojis().PLAY)
|
||||
|
||||
async def callback(self, interaction: Interaction) -> None:
|
||||
pass
|
||||
11
UI/Buttons/SkipButton.py
Normal file
11
UI/Buttons/SkipButton.py
Normal file
@@ -0,0 +1,11 @@
|
||||
from discord import ButtonStyle, Interaction
|
||||
from discord.ui import Button
|
||||
from Config.Emojis import VEmojis
|
||||
|
||||
|
||||
class SkipButton(Button):
|
||||
def __init__(self):
|
||||
super().__init__(label="Skip", style=ButtonStyle.secondary, emoji=VEmojis().SKIP)
|
||||
|
||||
async def callback(self, interaction: Interaction) -> None:
|
||||
pass
|
||||
11
UI/Buttons/SongsButton.py
Normal file
11
UI/Buttons/SongsButton.py
Normal file
@@ -0,0 +1,11 @@
|
||||
from discord import ButtonStyle, Interaction
|
||||
from discord.ui import Button
|
||||
from Config.Emojis import VEmojis
|
||||
|
||||
|
||||
class SongsButton(Button):
|
||||
def __init__(self):
|
||||
super().__init__(label="Songs", style=ButtonStyle.secondary, emoji=VEmojis().QUEUE)
|
||||
|
||||
async def callback(self, interaction: Interaction) -> None:
|
||||
pass
|
||||
11
UI/Buttons/StopButton.py
Normal file
11
UI/Buttons/StopButton.py
Normal file
@@ -0,0 +1,11 @@
|
||||
from discord import ButtonStyle, Interaction
|
||||
from discord.ui import Button
|
||||
from Config.Emojis import VEmojis
|
||||
|
||||
|
||||
class StopButton(Button):
|
||||
def __init__(self):
|
||||
super().__init__(label="Stop", style=ButtonStyle.secondary, emoji=VEmojis().STOP)
|
||||
|
||||
async def callback(self, interaction: Interaction) -> None:
|
||||
pass
|
||||
33
UI/Responses/AbstractCogResponse.py
Normal file
33
UI/Responses/AbstractCogResponse.py
Normal file
@@ -0,0 +1,33 @@
|
||||
from abc import ABC, abstractmethod
|
||||
from Handlers.HandlerResponse import HandlerResponse
|
||||
from discord.ext.commands import Context
|
||||
from discord import Message
|
||||
from Music.VulkanBot import VulkanBot
|
||||
|
||||
|
||||
class AbstractCommandResponse(ABC):
|
||||
def __init__(self, response: HandlerResponse) -> None:
|
||||
self.__response: HandlerResponse = response
|
||||
self.__context: Context = response.ctx
|
||||
self.__message: Message = response.ctx.message
|
||||
self.__bot: VulkanBot = response.ctx.bot
|
||||
|
||||
@property
|
||||
def response(self) -> HandlerResponse:
|
||||
return self.__response
|
||||
|
||||
@property
|
||||
def bot(self) -> VulkanBot:
|
||||
return self.__bot
|
||||
|
||||
@property
|
||||
def message(self) -> Message:
|
||||
return self.__message
|
||||
|
||||
@property
|
||||
def context(self) -> Context:
|
||||
return self.__context
|
||||
|
||||
@abstractmethod
|
||||
async def run(self) -> None:
|
||||
pass
|
||||
11
UI/Responses/EmbedCogResponse.py
Normal file
11
UI/Responses/EmbedCogResponse.py
Normal file
@@ -0,0 +1,11 @@
|
||||
from UI.Responses.AbstractCogResponse import AbstractCommandResponse
|
||||
from Handlers.HandlerResponse import HandlerResponse
|
||||
|
||||
|
||||
class EmbedCommandResponse(AbstractCommandResponse):
|
||||
def __init__(self, response: HandlerResponse) -> None:
|
||||
super().__init__(response)
|
||||
|
||||
async def run(self) -> None:
|
||||
if self.response.embed:
|
||||
await self.context.send(embed=self.response.embed)
|
||||
16
UI/Responses/EmoteCogResponse.py
Normal file
16
UI/Responses/EmoteCogResponse.py
Normal file
@@ -0,0 +1,16 @@
|
||||
from Config.Emojis import VEmojis
|
||||
from UI.Responses.AbstractCogResponse import AbstractCommandResponse
|
||||
from Handlers.HandlerResponse import HandlerResponse
|
||||
|
||||
|
||||
class EmoteCommandResponse(AbstractCommandResponse):
|
||||
|
||||
def __init__(self, response: HandlerResponse) -> None:
|
||||
super().__init__(response)
|
||||
self.__emojis = VEmojis()
|
||||
|
||||
async def run(self) -> None:
|
||||
if self.response.success:
|
||||
await self.message.add_reaction(self.__emojis.SUCCESS)
|
||||
else:
|
||||
await self.message.add_reaction(self.__emojis.ERROR)
|
||||
30
UI/Views/PlayerView.py
Normal file
30
UI/Views/PlayerView.py
Normal file
@@ -0,0 +1,30 @@
|
||||
from typing import Optional
|
||||
from discord.ui import View
|
||||
from Config.Emojis import VEmojis
|
||||
from UI.Buttons.PauseButton import PauseButton
|
||||
from UI.Buttons.BackButton import BackButton
|
||||
from UI.Buttons.SkipButton import SkipButton
|
||||
from UI.Buttons.StopButton import StopButton
|
||||
from UI.Buttons.SongsButton import SongsButton
|
||||
from UI.Buttons.PlayButton import PlayButton
|
||||
from UI.Buttons.LoopAllButton import LoopAllButton
|
||||
from UI.Buttons.LoopOneButton import LoopOneButton
|
||||
from UI.Buttons.LoopOffButton import LoopOffButton
|
||||
from Music.VulkanBot import VulkanBot
|
||||
|
||||
emojis = VEmojis()
|
||||
|
||||
|
||||
class PlayerView(View):
|
||||
def __init__(self, bot: VulkanBot, timeout: float = 180):
|
||||
super().__init__(timeout=timeout)
|
||||
self.__bot = bot
|
||||
self.add_item(BackButton(self.__bot))
|
||||
self.add_item(PauseButton())
|
||||
self.add_item(PlayButton())
|
||||
self.add_item(StopButton())
|
||||
self.add_item(SkipButton())
|
||||
self.add_item(SongsButton())
|
||||
self.add_item(LoopOneButton())
|
||||
self.add_item(LoopOffButton())
|
||||
self.add_item(LoopAllButton())
|
||||
Reference in New Issue
Block a user