[Add] - Position Report | [Fix] - Own Error creation | [Modify] - Move command logic

This commit is contained in:
Rafael Vargas
2022-01-14 22:02:37 -04:00
parent cbd8ed45f9
commit 63d86e23f9
4 changed files with 35 additions and 24 deletions

View File

@@ -104,6 +104,7 @@ class Player(commands.Cog):
if songs_quant == 1:
song = self.__down.download_one(song)
pos = len(self.__playlist)
if song == None:
embed = discord.Embed(
@@ -119,7 +120,7 @@ class Player(commands.Cog):
colour=config.COLOURS['blue'])
await ctx.send(embed=embed)
else:
embed = self.__format_embed(song.info, config.SONG_ADDED_TWO)
embed = self.__format_embed(song.info, config.SONG_ADDED_TWO, pos)
await ctx.send(embed=embed)
else:
embed = discord.Embed(
@@ -271,7 +272,7 @@ class Player(commands.Cog):
elif args == 'off':
description = self.__playlist.loop_off()
else:
raise commands.CommandInvokeError('Invalid Arguments in Command')
raise commands.UserInputError(config.MY_ERROR_BAD_COMMAND)
return description
@@ -338,7 +339,7 @@ class Player(commands.Cog):
result = self.__playlist.remove_song(position)
return result
def __format_embed(self, info=dict, title='') -> discord.Embed:
def __format_embed(self, info=dict, title='', position='Playing Now') -> discord.Embed:
"""Configure the embed to show the song information"""
embedvc = discord.Embed(
title=title,
@@ -348,7 +349,7 @@ class Player(commands.Cog):
embedvc.add_field(name=config.SONGINFO_UPLOADER,
value=info['uploader'],
inline=True)
inline=False)
embedvc.add_field(name=config.SONGINFO_REQUESTER,
value=info['requester'],
@@ -367,6 +368,10 @@ class Player(commands.Cog):
value=config.SONGINFO_UNKNOWN_DURATION,
inline=True)
embedvc.add_field(name=config.SONGINFO_POSITION,
value=position,
inline=True)
return embedvc
async def __timeout_handler(self) -> None:

View File

@@ -147,10 +147,10 @@ class Playlist(IPlaylist):
break
def move_songs(self, pos1, pos2) -> str:
"""Receive two position and try to change the songs in those positions, -1 is the last
"""Try to move the song in pos1 to pos2, -1 is the last
Positions: First music is 1
Return (Error bool, string) with the status of the function, to show to user
Return: String with the status of the function, to show to user
"""
if pos1 == -1:
pos1 = len(self.__queue)
@@ -161,16 +161,13 @@ class Playlist(IPlaylist):
return config.LENGTH_ERROR
try:
song1 = self.__queue[pos1-1]
song2 = self.__queue[pos2-1]
song = self.__queue[pos1-1]
self.__queue.remove(song)
self.__queue.insert(pos2-1, song)
self.__queue[pos1-1] = song2
self.__queue[pos2-1] = song1
song1_name = song.title if song.title else song.identifier
song1_name = song1.title if song1.title else song1.identifier
song2_name = song2.title if song2.title else song2.identifier
return config.SONG_MOVED_SUCCESSFULLY.format(song1_name, pos1, song2_name, pos2)
return config.SONG_MOVED_SUCCESSFULLY.format(song1_name, pos1, pos2)
except:
return config.ERROR_MOVING