Adding remove command and upgrading move command in music module

This commit is contained in:
Rafael Vargas 2022-01-05 18:56:53 -04:00
parent fe51f13f13
commit 0b10086d4c
5 changed files with 52 additions and 20 deletions

View File

@ -44,12 +44,13 @@ HELP_PAUSE = 'Pauses the song player'
HELP_SHUFFLE = 'Shuffle the songs playing'
HELP_PLAY = '(title/youtube/spotify) - Plays a song'
HELP_MOVE = '(x, y) - Moves a song from position x to y in queue'
HELP_WARFRAME = f'({BOT_PREFIX}warframe help for more) - Return warframe information'
HELP_REMOVE = '(x, -1) - Remove a song in the position x or -1 for the last song'
HELP_WARFRAME = f'({BOT_PREFIX}warframe help for more)'
HELP_RANDOM = '(x) - Return a random number between 1 and x'
HELP_ESCOLHA = '(x, y, z...) - Choose randomly one item passed in the command'
HELP_ESCOLHA = '(x, y, z...) - Choose randomly one item passed'
HELP_CARA = 'Return cara or coroa'
HELP_DROP = '(user_name) - Try to remove the user from the current voice channel'
HELP_FRASE = "Send a randomly phrase, there's a chance of getting the braba"
HELP_FRASE = "Send a randomly phrase, perhaps you get the braba"
HELP_HELP = 'This command :)'
ABSOLUTE_PATH = ''

View File

@ -1,4 +1,5 @@
discord.py
discord.py[voice]
youtube_dl
spotipy
yt_dlp
spotipy
dotenv

View File

@ -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'],

View File

@ -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:

View File

@ -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'