mirror of
https://github.com/RafaelSolVargas/Vulkan.git
synced 2025-10-29 16:57:23 +00:00
Adding new controllers
This commit is contained in:
13
Controllers/ClearController.py
Normal file
13
Controllers/ClearController.py
Normal file
@@ -0,0 +1,13 @@
|
||||
from discord.ext.commands import Context
|
||||
from discord import Client
|
||||
from Controllers.AbstractController import AbstractController
|
||||
from Controllers.ControllerResponse import ControllerResponse
|
||||
|
||||
|
||||
class ClearController(AbstractController):
|
||||
def __init__(self, ctx: Context, bot: Client) -> None:
|
||||
super().__init__(ctx, bot)
|
||||
|
||||
async def run(self) -> ControllerResponse:
|
||||
self.player.playlist.clear()
|
||||
return ControllerResponse(self.ctx)
|
||||
24
Controllers/HistoryController.py
Normal file
24
Controllers/HistoryController.py
Normal file
@@ -0,0 +1,24 @@
|
||||
from discord.ext.commands import Context
|
||||
from discord import Client
|
||||
from Controllers.AbstractController import AbstractController
|
||||
from Controllers.ControllerResponse import ControllerResponse
|
||||
from Utils.Utils import format_time
|
||||
|
||||
|
||||
class HistoryController(AbstractController):
|
||||
def __init__(self, ctx: Context, bot: Client) -> None:
|
||||
super().__init__(ctx, bot)
|
||||
|
||||
async def run(self) -> ControllerResponse:
|
||||
history = self.player.playlist.songs_history
|
||||
|
||||
if len(history) == 0:
|
||||
text = self.config.HISTORY_EMPTY
|
||||
|
||||
else:
|
||||
text = f'\n📜 History Length: {len(history)} | Max: {self.config.MAX_SONGS_HISTORY}\n'
|
||||
for pos, song in enumerate(history, start=1):
|
||||
text += f"**`{pos}` - ** {song.title} - `{format_time(song.duration)}`\n"
|
||||
|
||||
embed = self.embeds.HISTORY(text)
|
||||
return ControllerResponse(self.ctx, embed)
|
||||
40
Controllers/LoopController.py
Normal file
40
Controllers/LoopController.py
Normal file
@@ -0,0 +1,40 @@
|
||||
from discord.ext.commands import Context
|
||||
from discord import Client
|
||||
from Controllers.AbstractController import AbstractController
|
||||
from Controllers.ControllerResponse import ControllerResponse
|
||||
from Exceptions.Exceptions import BadCommandUsage
|
||||
|
||||
|
||||
class LoopController(AbstractController):
|
||||
def __init__(self, ctx: Context, bot: Client) -> None:
|
||||
super().__init__(ctx, bot)
|
||||
|
||||
async def run(self, args: str) -> ControllerResponse:
|
||||
if args == '' or args == None:
|
||||
self.player.playlist.loop_all()
|
||||
embed = self.embeds.LOOP_ALL_ACTIVATED()
|
||||
return ControllerResponse(self.ctx, embed)
|
||||
|
||||
args = args.lower()
|
||||
if self.player.playlist.current is None:
|
||||
embed = self.embeds.NOT_PLAYING()
|
||||
error = BadCommandUsage()
|
||||
return ControllerResponse(self.ctx, embed, error)
|
||||
|
||||
if args == 'one':
|
||||
self.player.playlist.loop_one()
|
||||
embed = self.embeds.LOOP_ONE_ACTIVATED()
|
||||
return ControllerResponse(self.ctx, embed)
|
||||
elif args == 'all':
|
||||
self.player.playlist.loop_all()
|
||||
embed = self.embeds.LOOP_ALL_ACTIVATED()
|
||||
return ControllerResponse(self.ctx, embed)
|
||||
elif args == 'off':
|
||||
self.player.playlist.loop_all()
|
||||
embed = self.embeds.LOOP_DISABLE()
|
||||
return ControllerResponse(self.ctx, embed)
|
||||
else:
|
||||
self.player.playlist.loop_all()
|
||||
error = BadCommandUsage()
|
||||
embed = self.embeds.BAD_LOOP_USE()
|
||||
return ControllerResponse(self.ctx, embed, error)
|
||||
23
Controllers/NowPlayingController.py
Normal file
23
Controllers/NowPlayingController.py
Normal file
@@ -0,0 +1,23 @@
|
||||
from discord.ext.commands import Context
|
||||
from discord import Client
|
||||
from Controllers.AbstractController import AbstractController
|
||||
from Controllers.ControllerResponse import ControllerResponse
|
||||
|
||||
|
||||
class NowPlayingController(AbstractController):
|
||||
def __init__(self, ctx: Context, bot: Client) -> None:
|
||||
super().__init__(ctx, bot)
|
||||
|
||||
async def run(self) -> ControllerResponse:
|
||||
if not self.player.playing:
|
||||
embed = self.embeds.NOT_PLAYING()
|
||||
return ControllerResponse(self.ctx, embed)
|
||||
|
||||
if self.player.playlist.looping_one:
|
||||
title = self.config.ONE_SONG_LOOPING
|
||||
else:
|
||||
title = self.config.SONG_PLAYING
|
||||
|
||||
info = self.player.playlist.current.info
|
||||
embed = self.embeds.SONG_INFO(info, title)
|
||||
return ControllerResponse(self.ctx, embed)
|
||||
16
Controllers/PauseController.py
Normal file
16
Controllers/PauseController.py
Normal file
@@ -0,0 +1,16 @@
|
||||
from discord.ext.commands import Context
|
||||
from discord import Client
|
||||
from Controllers.AbstractController import AbstractController
|
||||
from Controllers.ControllerResponse import ControllerResponse
|
||||
|
||||
|
||||
class PauseController(AbstractController):
|
||||
def __init__(self, ctx: Context, bot: Client) -> None:
|
||||
super().__init__(ctx, bot)
|
||||
|
||||
async def run(self) -> ControllerResponse:
|
||||
if self.guild.voice_client is not None:
|
||||
if self.guild.voice_client.is_playing():
|
||||
self.guild.voice_client.pause()
|
||||
|
||||
return ControllerResponse(self.ctx)
|
||||
@@ -40,5 +40,6 @@ class PlayersController(Singleton):
|
||||
for guild in list_guilds:
|
||||
player = Player(self.__bot, guild)
|
||||
players[guild] = player
|
||||
print(f'Player for guild {guild.name} created')
|
||||
|
||||
return players
|
||||
|
||||
44
Controllers/QueueController.py
Normal file
44
Controllers/QueueController.py
Normal file
@@ -0,0 +1,44 @@
|
||||
from discord.ext.commands import Context
|
||||
from discord import Client
|
||||
from Controllers.AbstractController import AbstractController
|
||||
from Controllers.ControllerResponse import ControllerResponse
|
||||
from Music.Downloader import Downloader
|
||||
from Utils.Utils import format_time
|
||||
|
||||
|
||||
class QueueController(AbstractController):
|
||||
def __init__(self, ctx: Context, bot: Client) -> None:
|
||||
super().__init__(ctx, bot)
|
||||
self.__down = Downloader()
|
||||
|
||||
async def run(self) -> ControllerResponse:
|
||||
if self.player.playlist.looping_one:
|
||||
info = self.player.playlist.current
|
||||
embed = self.embeds.ONE_SONG_LOOPING(info)
|
||||
return ControllerResponse(self.ctx, embed)
|
||||
|
||||
songs_preload = self.player.playlist.songs_to_preload
|
||||
if len(songs_preload) == 0:
|
||||
embed = self.embeds.EMPTY_QUEUE
|
||||
return ControllerResponse(self.ctx, embed)
|
||||
|
||||
await self.__down.preload(songs_preload)
|
||||
|
||||
if self.player.playlist.looping_all:
|
||||
title = self.__config.ALL_SONGS_LOOPING
|
||||
else:
|
||||
title = self.__config.QUEUE_TITLE
|
||||
|
||||
title = self.config.QUEUE_TITLE
|
||||
total_time = format_time(sum([int(song.duration if song.duration else 0)
|
||||
for song in songs_preload]))
|
||||
total_songs = len(self.player.playlist)
|
||||
|
||||
text = f'📜 Queue length: {total_songs} | ⌛ Duration: `{total_time}` downloaded \n\n'
|
||||
|
||||
for pos, song in enumerate(songs_preload, start=1):
|
||||
song_name = song.title if song.title else self.config.SONG_DOWNLOADING
|
||||
text += f"**`{pos}` - ** {song_name} - `{format_time(song.duration)}`\n"
|
||||
|
||||
embed = self.embeds.QUEUE(title, text)
|
||||
return ControllerResponse(self.ctx, embed)
|
||||
16
Controllers/ResumeController.py
Normal file
16
Controllers/ResumeController.py
Normal file
@@ -0,0 +1,16 @@
|
||||
from discord.ext.commands import Context
|
||||
from discord import Client
|
||||
from Controllers.AbstractController import AbstractController
|
||||
from Controllers.ControllerResponse import ControllerResponse
|
||||
|
||||
|
||||
class ResumeController(AbstractController):
|
||||
def __init__(self, ctx: Context, bot: Client) -> None:
|
||||
super().__init__(ctx, bot)
|
||||
|
||||
async def run(self) -> ControllerResponse:
|
||||
if self.guild.voice_client is not None:
|
||||
if self.guild.voice_client.is_paused():
|
||||
self.guild.voice_client.resume()
|
||||
|
||||
return ControllerResponse(self.ctx)
|
||||
@@ -11,16 +11,13 @@ class SkipController(AbstractController):
|
||||
|
||||
async def run(self) -> ControllerResponse:
|
||||
if self.player.playlist.looping_one:
|
||||
embed = self.__embeds.FAIL_DUE_TO_LOOP_ON
|
||||
error = BadCommandUsage('', '')
|
||||
response = ControllerResponse(self.ctx, embed, error)
|
||||
return response
|
||||
embed = self.embeds.ERROR_DUE_LOOP_ONE_ON()
|
||||
error = BadCommandUsage()
|
||||
return ControllerResponse(self.ctx, embed, error)
|
||||
|
||||
voice = self.controller.get_guild_voice(self.guild)
|
||||
if voice is None:
|
||||
response = ControllerResponse(self.ctx)
|
||||
return response
|
||||
return ControllerResponse(self.ctx)
|
||||
else:
|
||||
voice.stop()
|
||||
response = ControllerResponse(self.ctx)
|
||||
return response
|
||||
return ControllerResponse(self.ctx)
|
||||
|
||||
23
Controllers/StopController.py
Normal file
23
Controllers/StopController.py
Normal file
@@ -0,0 +1,23 @@
|
||||
from discord.ext.commands import Context
|
||||
from discord import Client
|
||||
from Controllers.AbstractController import AbstractController
|
||||
from Controllers.ControllerResponse import ControllerResponse
|
||||
|
||||
|
||||
class StopController(AbstractController):
|
||||
def __init__(self, ctx: Context, bot: Client) -> None:
|
||||
super().__init__(ctx, bot)
|
||||
|
||||
async def run(self) -> ControllerResponse:
|
||||
if self.guild.voice_client is None:
|
||||
return ControllerResponse(self.ctx)
|
||||
|
||||
if self.guild.voice_client.is_connected():
|
||||
self.player.playlist.clear()
|
||||
self.player.playlist.loop_off()
|
||||
self.guild.voice_client.stop()
|
||||
await self.guild.voice_client.disconnect()
|
||||
return ControllerResponse(self.ctx)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user