Merge pull request #9 from RafaelSolVargas/creating_player

Removing error handler and prints from the code
This commit is contained in:
Rafael Vargas 2022-01-06 17:58:00 -04:00 committed by GitHub
commit 9c327b8dbf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 36 additions and 33 deletions

View File

@ -3,7 +3,6 @@ import discord
from config import config
from discord.ext import commands
from vulkanbot.ErrorHandler import ErrorHandler
intents = discord.Intents.default()
@ -22,8 +21,6 @@ if __name__ == '__main__':
print("Error: No bot token!")
exit()
bot.log_error = ErrorHandler('errors')
for extension in config.INITIAL_EXTENSIONS:
try:
bot.load_extension(extension)

View File

@ -3,6 +3,7 @@ import discord
from discord.ext import commands
from config import config
class Random(commands.Cog):
"""Deal with returning random things"""

View File

@ -16,11 +16,10 @@ class Warframe(commands.Cog):
@commands.command(name='warframe', help=config.HELP_WARFRAME)
async def warframe(self, ctx, arg) -> Embed:
if arg in self.__open_functions:
# Get the required function
function = getattr(Warframe, f'_Warframe__{arg}')
embed = await function(self) # Execute the function passing self
embed = await function(self)
await ctx.send(embed=embed) # Return the result
await ctx.send(embed=embed)
else:
info = f'Warframe commands: {self.__open_functions}'
@ -82,8 +81,7 @@ class Warframe(commands.Cog):
info = f'**Active:** {data["active"]}\n**Time Left:** {data["timeLeft"]}'
return info
except Exception as e:
print(e)
except:
continue
async def __fissures(self) -> Embed:
@ -113,7 +111,6 @@ class Warframe(commands.Cog):
return info
except Exception as e:
print(e)
continue

View File

@ -23,8 +23,7 @@ class Downloader():
def download_one(self, song: Song) -> Song:
"""Receives a song object, finish his download and return it"""
if song.identifier == None:
print('Invalid song identifier type')
return
return None
if is_url(song.identifier): # Youtube URL
song_info = self.__download_url(song.identifier)
@ -63,7 +62,6 @@ class Downloader():
return songs_identifiers # Return a list
except (ExtractorError, DownloadError) as e:
print(e)
return None
else:
print('Invalid type of playlist URL')
@ -89,7 +87,7 @@ class Downloader():
return result
except (ExtractorError, DownloadError) as e: # Any type of error in download
print(e)
return None
async def __download_songs(self, song: Song) -> None:
"""Download a music object asynchronously"""
@ -122,8 +120,7 @@ class Downloader():
Return: A dict containing the song information
"""
if type(title) != str:
print('Invalid music identifier type')
return
return None
config = self.__YDL_OPTIONS
config['extract_flat'] = False
@ -134,9 +131,9 @@ class Downloader():
result = ydl.extract_info(search, download=False)
if result == None:
return
return None
# Return a dict with the full info of first music
return result['entries'][0]
except Exception as e:
print(e)
return None

View File

@ -161,8 +161,7 @@ class Music(commands.Cog):
embed = message.embeds[0]
if embed.title == 'Song Playing Now' or embed.title == 'Song Looping Now':
await message.delete()
except Exception as e:
print(e)
except:
continue
def __get_player(self, ctx):

View File

@ -59,22 +59,29 @@ class Player(commands.Cog):
if self.__guild.voice_client == None:
voice_channel = ctx.author.voice.channel
await voice_channel.connect()
except Exception as e:
print(e)
return config.NO_CHANNEL
except:
embed = discord.Embed(
description=config.NO_CHANNEL, colour=config.COLOURS['red'])
await ctx.send(embed=embed)
else:
songs_quant = 0
musics_identifiers, provider = self.__searcher.search(user_input)
try:
musics_identifiers, provider = self.__searcher.search(
user_input)
except:
return config.INVALID_INPUT
if provider == Provider.Unknown:
return config.INVALID_INPUT
if provider == Provider.YouTube:
try:
musics_identifiers = self.__downloader.extract_youtube_link(
musics_identifiers[0])
except:
await ctx.send('Problema com o download do Youtube')
for identifier in musics_identifiers: # Creating songs
print('Creating Song')
last_song = self.__playlist.add_song(identifier)
songs_quant += 1
@ -253,8 +260,7 @@ class Player(commands.Cog):
try:
position = int(position)
except Exception as e:
print(e)
except:
return 'This command require a number'
result = self.__playlist.remove_song(position)

View File

@ -8,7 +8,6 @@ class Searcher():
def __init__(self) -> None:
self.__Spotify = SpotifySearch()
print(f'Spotify Connected: {self.__Spotify.connect()}')
def search(self, music: str) -> list:
"""Return a list with the song names or an URL
@ -22,8 +21,11 @@ class Searcher():
return [music], Provider.YouTube
elif url_type == Provider.Spotify:
if self.__Spotify.connected == True:
musics = self.__Spotify.search(music)
return musics, Provider.Name
else:
return [], Provider.Unknown
elif url_type == Provider.Name:
return [music], Provider.Name

View File

@ -22,7 +22,6 @@ class Song(ISong):
try:
self.__info[key] = info[key]
except Exception as e:
print(e)
raise e
@property

View File

@ -8,8 +8,13 @@ class SpotifySearch():
def __init__(self) -> None:
self.__connected = False
self.__connect()
def connect(self) -> bool:
@property
def connected(self):
return self.__connected
def __connect(self) -> bool:
try:
# Initialize the connection with Spotify API
self.__api = spotipy.Spotify(auth_manager=SpotifyClientCredentials(