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_SHUFFLE = 'Shuffle the songs playing'
HELP_PLAY = '(title/youtube/spotify) - Plays a song' HELP_PLAY = '(title/youtube/spotify) - Plays a song'
HELP_MOVE = '(x, y) - Moves a song from position x to y in queue' 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_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_CARA = 'Return cara or coroa'
HELP_DROP = '(user_name) - Try to remove the user from the current voice channel' 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 :)' HELP_HELP = 'This command :)'
ABSOLUTE_PATH = '' ABSOLUTE_PATH = ''

View File

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

View File

@ -11,7 +11,7 @@ class Control(commands.Cog):
def __init__(self, bot: Client): def __init__(self, bot: Client):
self.__bot = bot self.__bot = bot
self.__comandos = { 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'], 'WARFRAME': ['warframe'],
'RANDOM': ['escolha', 'cara', 'random'], 'RANDOM': ['escolha', 'cara', 'random'],
'HELP': ['help'], 'HELP': ['help'],

View File

@ -20,8 +20,7 @@ class Music(commands.Cog):
self.__vc = "" self.__vc = ""
self.YDL_OPTIONS = {'format': 'bestaudio', 'noplaylist': 'True'} self.YDL_OPTIONS = {'format': 'bestaudio', 'noplaylist': 'True'}
self.FFMPEG_OPTIONS = {'executable': config.FFMPEG_PATH, self.FFMPEG_OPTIONS = {'before_options': '-reconnect 1 -reconnect_streamed 1 -reconnect_delay_max 5',
'before_options': '-reconnect 1 -reconnect_streamed 1 -reconnect_delay_max 5',
'options': '-vn'} 'options': '-vn'}
def __play_next(self, error, ctx): def __play_next(self, error, ctx):
@ -217,14 +216,25 @@ class Music(commands.Cog):
await ctx.send('This command require a number') await ctx.send('This command require a number')
return 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
songs = self.__playlist.songs_to_preload await self.__downloader.preload(songs)
await self.__downloader.preload(songs) await ctx.send(result)
await ctx.send(reason)
else: @commands.command(name='remove', help=config.HELP_MOVE)
await ctx.send(reason) 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'): async def __send_embed(self, ctx, title='', description='', colour_name='grey'):
try: try:

View File

@ -138,14 +138,19 @@ class Playlist(IPlaylist):
self.__queue.remove(song) self.__queue.remove(song)
break break
def move_songs(self, pos1, pos2) -> tuple: def move_songs(self, pos1, pos2) -> str:
"""Receive two position and try to chance the songs in those positions """Receive two position and try to change the songs in those positions, -1 is the last
Positions: First music is 1 Positions: First music is 1
Return (Error bool, string) with the status of the function, to show to user 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): 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: try:
song1 = self.__queue[pos1-1] song1 = self.__queue[pos1-1]
@ -153,7 +158,22 @@ class Playlist(IPlaylist):
self.__queue[pos1-1] = song2 self.__queue[pos1-1] = song2
self.__queue[pos2-1] = song1 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: except Exception as e:
print(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'