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:
@@ -4,7 +4,7 @@ from Config.Config import Configs
|
||||
from yt_dlp import YoutubeDL
|
||||
from concurrent.futures import ThreadPoolExecutor
|
||||
from Music.Song import Song
|
||||
from Music.utils import is_url, run_async
|
||||
from Utils.Utils import is_url, run_async
|
||||
|
||||
|
||||
class Downloader():
|
||||
|
||||
@@ -8,7 +8,7 @@ from Music.Playlist import Playlist
|
||||
from Music.Searcher import Searcher
|
||||
from Music.Song import Song
|
||||
from Music.Types import Provider
|
||||
from Music.utils import *
|
||||
from Utils.Utils import *
|
||||
|
||||
|
||||
class Player(commands.Cog):
|
||||
@@ -28,6 +28,10 @@ class Player(commands.Cog):
|
||||
self.FFMPEG_OPTIONS = {'before_options': '-reconnect 1 -reconnect_streamed 1 -reconnect_delay_max 5',
|
||||
'options': '-vn'}
|
||||
|
||||
@property
|
||||
def playing(self) -> bool:
|
||||
return self.__playing
|
||||
|
||||
@property
|
||||
def playlist(self) -> Playlist:
|
||||
return self.__playlist
|
||||
@@ -212,6 +216,7 @@ class Player(commands.Cog):
|
||||
|
||||
def history(self) -> Embed:
|
||||
history = self.__playlist.songs_history
|
||||
print(f'Player -> {history}')
|
||||
|
||||
if len(history) == 0:
|
||||
text = self.__config.HISTORY_EMPTY
|
||||
|
||||
@@ -7,7 +7,6 @@ import random
|
||||
|
||||
|
||||
class Playlist(IPlaylist):
|
||||
"""Class to manage and control the songs to play and played"""
|
||||
|
||||
def __init__(self) -> None:
|
||||
self.__config = Configs()
|
||||
@@ -43,7 +42,6 @@ class Playlist(IPlaylist):
|
||||
return len(self.__queue)
|
||||
|
||||
def next_song(self) -> Song:
|
||||
"""Return the next song to play in a normal playlist flow"""
|
||||
if self.__current == None and len(self.__queue) == 0:
|
||||
return None
|
||||
|
||||
@@ -72,7 +70,6 @@ class Playlist(IPlaylist):
|
||||
return self.__current
|
||||
|
||||
def prev_song(self) -> Song:
|
||||
"""If playing return it to queue and return the previous song to play"""
|
||||
if len(self.__songs_history) == 0:
|
||||
return None
|
||||
else:
|
||||
@@ -84,74 +81,38 @@ class Playlist(IPlaylist):
|
||||
return self.__current # return the song
|
||||
|
||||
def add_song(self, identifier: str, requester: str) -> Song:
|
||||
"""Create a song object, add to queue and return it"""
|
||||
song = Song(identifier=identifier, playlist=self, requester=requester)
|
||||
self.__queue.append(song)
|
||||
return song
|
||||
|
||||
def shuffle(self) -> None:
|
||||
"""Shuffle the order of the songs to play"""
|
||||
random.shuffle(self.__queue)
|
||||
|
||||
def revert(self) -> None:
|
||||
"""Revert the order of the songs to play"""
|
||||
self.__queue.reverse()
|
||||
|
||||
def clear(self) -> None:
|
||||
"""Clear the songs to play song history"""
|
||||
self.__queue.clear()
|
||||
|
||||
def loop_one(self) -> str:
|
||||
"""Try to start the loop of the current song
|
||||
def loop_one(self) -> None:
|
||||
self.__looping_one = True
|
||||
self.__looping_all = False
|
||||
|
||||
Return: Embed descrition to show to user
|
||||
"""
|
||||
if self.__looping_all == True:
|
||||
return self.__config.LOOP_ALL_ON
|
||||
|
||||
elif self.__looping_one == True:
|
||||
return self.__config.LOOP_ONE_ALREADY_ON
|
||||
else:
|
||||
self.__looping_one = True
|
||||
return self.__config.LOOP_ONE_ACTIVATE
|
||||
|
||||
def loop_all(self) -> str:
|
||||
"""Try to start the loop of all songs
|
||||
|
||||
Return: Embed descrition to show to user
|
||||
"""
|
||||
if self.__looping_one == True:
|
||||
return self.__config.LOOP_ONE_ON
|
||||
|
||||
elif self.__looping_all == True:
|
||||
return self.__config.LOOP_ALL_ALREADY_ON
|
||||
|
||||
else:
|
||||
self.__looping_all = True
|
||||
return self.__config.LOOP_ALL_ACTIVATE
|
||||
def loop_all(self) -> None:
|
||||
self.__looping_all = True
|
||||
self.__looping_one = False
|
||||
|
||||
def loop_off(self) -> str:
|
||||
"""Disable both types of loop"""
|
||||
if self.__looping_all == False and self.__looping_one == False:
|
||||
return self.__config.LOOP_ALREADY_DISABLE
|
||||
|
||||
self.__looping_all = False
|
||||
self.__looping_one = False
|
||||
return self.__config.LOOP_DISABLE
|
||||
|
||||
def destroy_song(self, song_destroy: Song) -> None:
|
||||
"""Destroy a song object from the queue"""
|
||||
for song in self.__queue:
|
||||
if song == song_destroy:
|
||||
self.__queue.remove(song)
|
||||
break
|
||||
|
||||
def move_songs(self, pos1, pos2) -> str:
|
||||
"""Try to move the song in pos1 to pos2, -1 is the last
|
||||
|
||||
Positions: First music is 1
|
||||
Return: String with the status of the function, to show to user
|
||||
"""
|
||||
if pos1 == -1:
|
||||
pos1 = len(self.__queue)
|
||||
if pos2 == -1:
|
||||
@@ -186,7 +147,6 @@ class Playlist(IPlaylist):
|
||||
return self.__config.SONG_REMOVED_SUCCESSFULLY.format(song_name)
|
||||
|
||||
def history(self) -> list:
|
||||
"""Return a list with the song title of all played songs"""
|
||||
titles = []
|
||||
for song in self.__songs_history:
|
||||
title = song.title if song.title else 'Unknown'
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
from Music.Types import Provider
|
||||
from Music.Spotify import SpotifySearch
|
||||
from Music.utils import is_url
|
||||
from Utils.Utils import is_url
|
||||
|
||||
|
||||
class Searcher():
|
||||
|
||||
@@ -1,67 +0,0 @@
|
||||
import re
|
||||
import asyncio
|
||||
from Config.Config import Configs
|
||||
from functools import wraps, partial
|
||||
config = Configs()
|
||||
|
||||
|
||||
def is_connected(ctx):
|
||||
try:
|
||||
voice_channel = ctx.guild.voice_client.channel
|
||||
|
||||
if not ctx.guild.voice_client.is_connected():
|
||||
return None
|
||||
else:
|
||||
return voice_channel
|
||||
except:
|
||||
return None
|
||||
|
||||
|
||||
def format_time(duration) -> str:
|
||||
if not duration:
|
||||
return "00:00"
|
||||
|
||||
hours = duration // 60 // 60
|
||||
minutes = duration // 60 % 60
|
||||
seconds = duration % 60
|
||||
|
||||
return "{}{}{:02d}:{:02d}".format(
|
||||
hours if hours else "",
|
||||
":" if hours else "",
|
||||
minutes,
|
||||
seconds
|
||||
)
|
||||
|
||||
|
||||
def is_url(string) -> bool:
|
||||
"""Verify if a string is a url"""
|
||||
regex = re.compile(
|
||||
"http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+")
|
||||
|
||||
if re.search(regex, string):
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
|
||||
class Timer:
|
||||
def __init__(self, callback):
|
||||
self.__callback = callback
|
||||
self.__task = asyncio.create_task(self.__executor())
|
||||
|
||||
async def __executor(self):
|
||||
await asyncio.sleep(config.VC_TIMEOUT)
|
||||
await self.__callback()
|
||||
|
||||
def cancel(self):
|
||||
self.__task.cancel()
|
||||
|
||||
|
||||
def run_async(func):
|
||||
@wraps(func)
|
||||
async def run(*args, loop=None, executor=None, **kwargs):
|
||||
if loop is None:
|
||||
loop = asyncio.get_event_loop()
|
||||
partial_func = partial(func, *args, **kwargs)
|
||||
return await loop.run_in_executor(executor, partial_func)
|
||||
return run
|
||||
Reference in New Issue
Block a user