diff --git a/main.py b/main.py index 0bc38d5..124ed15 100644 --- a/main.py +++ b/main.py @@ -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) diff --git a/vulkanbot/commands/Random.py b/vulkanbot/commands/Random.py index 0e7858d..546fefa 100644 --- a/vulkanbot/commands/Random.py +++ b/vulkanbot/commands/Random.py @@ -3,6 +3,7 @@ import discord from discord.ext import commands from config import config + class Random(commands.Cog): """Deal with returning random things""" diff --git a/vulkanbot/commands/Warframe.py b/vulkanbot/commands/Warframe.py index 5f88d3b..197777a 100644 --- a/vulkanbot/commands/Warframe.py +++ b/vulkanbot/commands/Warframe.py @@ -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 diff --git a/vulkanbot/music/Downloader.py b/vulkanbot/music/Downloader.py index 9679a66..fa02f0a 100644 --- a/vulkanbot/music/Downloader.py +++ b/vulkanbot/music/Downloader.py @@ -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 diff --git a/vulkanbot/music/Music.py b/vulkanbot/music/Music.py index 58cf907..931d86e 100644 --- a/vulkanbot/music/Music.py +++ b/vulkanbot/music/Music.py @@ -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): diff --git a/vulkanbot/music/Player.py b/vulkanbot/music/Player.py index ccc0bb5..11fb6ee 100644 --- a/vulkanbot/music/Player.py +++ b/vulkanbot/music/Player.py @@ -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: - musics_identifiers = self.__downloader.extract_youtube_link( - musics_identifiers[0]) + 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) diff --git a/vulkanbot/music/Searcher.py b/vulkanbot/music/Searcher.py index 928b4db..b39aa42 100644 --- a/vulkanbot/music/Searcher.py +++ b/vulkanbot/music/Searcher.py @@ -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: - musics = self.__Spotify.search(music) - return musics, Provider.Name + 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 diff --git a/vulkanbot/music/Song.py b/vulkanbot/music/Song.py index bb8094a..3729c83 100644 --- a/vulkanbot/music/Song.py +++ b/vulkanbot/music/Song.py @@ -22,7 +22,6 @@ class Song(ISong): try: self.__info[key] = info[key] except Exception as e: - print(e) raise e @property diff --git a/vulkanbot/music/Spotify.py b/vulkanbot/music/Spotify.py index 68f1376..0ac7a61 100644 --- a/vulkanbot/music/Spotify.py +++ b/vulkanbot/music/Spotify.py @@ -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(