mirror of
https://github.com/RafaelSolVargas/Vulkan.git
synced 2025-10-29 16:57:23 +00:00
Adding remove command and upgrading move command in music module
This commit is contained in:
@@ -11,7 +11,7 @@ class Control(commands.Cog):
|
||||
def __init__(self, bot: Client):
|
||||
self.__bot = bot
|
||||
self.__comandos = {
|
||||
'MUSIC': ['resume', 'pause', 'loop', 'stop', 'skip', 'play', 'queue', 'clear', 'np', 'shuffle', 'move'],
|
||||
'MUSIC': ['resume', 'pause', 'loop', 'stop', 'skip', 'play', 'queue', 'clear', 'np', 'shuffle', 'move', 'remove'],
|
||||
'WARFRAME': ['warframe'],
|
||||
'RANDOM': ['escolha', 'cara', 'random'],
|
||||
'HELP': ['help'],
|
||||
|
||||
@@ -20,8 +20,7 @@ class Music(commands.Cog):
|
||||
self.__vc = ""
|
||||
|
||||
self.YDL_OPTIONS = {'format': 'bestaudio', 'noplaylist': 'True'}
|
||||
self.FFMPEG_OPTIONS = {'executable': config.FFMPEG_PATH,
|
||||
'before_options': '-reconnect 1 -reconnect_streamed 1 -reconnect_delay_max 5',
|
||||
self.FFMPEG_OPTIONS = {'before_options': '-reconnect 1 -reconnect_streamed 1 -reconnect_delay_max 5',
|
||||
'options': '-vn'}
|
||||
|
||||
def __play_next(self, error, ctx):
|
||||
@@ -217,14 +216,25 @@ class Music(commands.Cog):
|
||||
await ctx.send('This command require a number')
|
||||
return
|
||||
|
||||
success, reason = self.__playlist.move_songs(pos1, pos2)
|
||||
result = self.__playlist.move_songs(pos1, pos2)
|
||||
|
||||
if not success:
|
||||
songs = self.__playlist.songs_to_preload
|
||||
await self.__downloader.preload(songs)
|
||||
await ctx.send(reason)
|
||||
else:
|
||||
await ctx.send(reason)
|
||||
songs = self.__playlist.songs_to_preload
|
||||
await self.__downloader.preload(songs)
|
||||
await ctx.send(result)
|
||||
|
||||
@commands.command(name='remove', help=config.HELP_MOVE)
|
||||
async def remove(self, ctx, position):
|
||||
"""Remove a song from the queue in the position"""
|
||||
try:
|
||||
position = int(position)
|
||||
|
||||
except Exception as e:
|
||||
print(e)
|
||||
await ctx.send('This command require a number')
|
||||
return
|
||||
|
||||
result = self.__playlist.remove_song(position)
|
||||
await ctx.send(result)
|
||||
|
||||
async def __send_embed(self, ctx, title='', description='', colour_name='grey'):
|
||||
try:
|
||||
|
||||
@@ -138,14 +138,19 @@ class Playlist(IPlaylist):
|
||||
self.__queue.remove(song)
|
||||
break
|
||||
|
||||
def move_songs(self, pos1, pos2) -> tuple:
|
||||
"""Receive two position and try to chance the songs in those positions
|
||||
def move_songs(self, pos1, pos2) -> str:
|
||||
"""Receive two position and try to change the songs in those positions, -1 is the last
|
||||
|
||||
Positions: First music is 1
|
||||
Return (Error bool, string) with the status of the function, to show to user
|
||||
"""
|
||||
if pos1 == -1:
|
||||
pos1 = len(self.__queue)
|
||||
if pos2 == -1:
|
||||
pos2 = len(self.__queue)
|
||||
|
||||
if pos2 not in range(1, len(self.__queue) + 1) or pos1 not in range(1, len(self.__queue) + 1):
|
||||
return (False, 'Numbers need to be more than 0 and less than the queue length')
|
||||
return 'Numbers must be between 1 and queue length, or -1 for the last song'
|
||||
|
||||
try:
|
||||
song1 = self.__queue[pos1-1]
|
||||
@@ -153,7 +158,22 @@ class Playlist(IPlaylist):
|
||||
|
||||
self.__queue[pos1-1] = song2
|
||||
self.__queue[pos2-1] = song1
|
||||
return (True, 'Songs moved with successfully')
|
||||
|
||||
song1_name = song1.title if song1.title else song1.identifier
|
||||
song2_name = song2.title if song2.title else song2.identifier
|
||||
|
||||
return f'Song `{song1_name}` in position `{pos1}` moved with `{song2_name}` in position `{pos2}` successfully'
|
||||
except Exception as e:
|
||||
print(e)
|
||||
return (False, 'There was a problem with the moving of songs')
|
||||
return 'There was a problem with the moving of songs'
|
||||
|
||||
def remove_song(self, position) -> tuple:
|
||||
if position not in range(1, len(self.__queue) + 1) and position != -1:
|
||||
return 'Numbers must be between 1 and queue length, or -1 for the last song'
|
||||
else:
|
||||
song = self.__queue[position-1]
|
||||
self.__queue.remove(song)
|
||||
|
||||
song_name = song.title if song.title else song.identifier
|
||||
|
||||
return f'Song `{song_name}` removed successfully'
|
||||
|
||||
Reference in New Issue
Block a user