[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

@@ -1,6 +1,6 @@
import discord
from discord import Client
from discord.ext.commands.errors import CommandNotFound, MissingRequiredArgument, CommandInvokeError
from discord.ext.commands.errors import CommandNotFound, MissingRequiredArgument, UserInputError
from discord.ext import commands
from config import config
from config import help
@@ -43,14 +43,21 @@ class Control(commands.Cog):
colour=config.COLOURS['black']
)
await ctx.send(embed=embed)
elif isinstance(error, CommandInvokeError):
embed = discord.Embed(
title=config.BAD_COMMAND_TITLE,
description=config.BAD_COMMAND,
colour=config.COLOURS['black']
)
await ctx.send(embed=embed)
elif isinstance(error, UserInputError):
my_error = False
if len(error.args) > 0:
for arg in error.args:
if arg == config.MY_ERROR_BAD_COMMAND:
embed = discord.Embed(
title=config.BAD_COMMAND_TITLE,
description=config.BAD_COMMAND,
colour=config.COLOURS['black']
)
await ctx.send(embed=embed)
my_error = True
break
if not my_error:
raise error
else:
print(error)
embed = discord.Embed(

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