mirror of
https://github.com/RafaelSolVargas/Vulkan.git
synced 2025-10-29 16:57:23 +00:00
Merge pull request #9 from RafaelSolVargas/creating_player
Removing error handler and prints from the code
This commit is contained in:
commit
9c327b8dbf
3
main.py
3
main.py
@ -3,7 +3,6 @@ import discord
|
|||||||
|
|
||||||
from config import config
|
from config import config
|
||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
from vulkanbot.ErrorHandler import ErrorHandler
|
|
||||||
|
|
||||||
|
|
||||||
intents = discord.Intents.default()
|
intents = discord.Intents.default()
|
||||||
@ -22,8 +21,6 @@ if __name__ == '__main__':
|
|||||||
print("Error: No bot token!")
|
print("Error: No bot token!")
|
||||||
exit()
|
exit()
|
||||||
|
|
||||||
bot.log_error = ErrorHandler('errors')
|
|
||||||
|
|
||||||
for extension in config.INITIAL_EXTENSIONS:
|
for extension in config.INITIAL_EXTENSIONS:
|
||||||
try:
|
try:
|
||||||
bot.load_extension(extension)
|
bot.load_extension(extension)
|
||||||
|
|||||||
@ -3,6 +3,7 @@ import discord
|
|||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
from config import config
|
from config import config
|
||||||
|
|
||||||
|
|
||||||
class Random(commands.Cog):
|
class Random(commands.Cog):
|
||||||
"""Deal with returning random things"""
|
"""Deal with returning random things"""
|
||||||
|
|
||||||
|
|||||||
@ -16,11 +16,10 @@ class Warframe(commands.Cog):
|
|||||||
@commands.command(name='warframe', help=config.HELP_WARFRAME)
|
@commands.command(name='warframe', help=config.HELP_WARFRAME)
|
||||||
async def warframe(self, ctx, arg) -> Embed:
|
async def warframe(self, ctx, arg) -> Embed:
|
||||||
if arg in self.__open_functions:
|
if arg in self.__open_functions:
|
||||||
# Get the required function
|
|
||||||
function = getattr(Warframe, f'_Warframe__{arg}')
|
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:
|
else:
|
||||||
info = f'Warframe commands: {self.__open_functions}'
|
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"]}'
|
info = f'**Active:** {data["active"]}\n**Time Left:** {data["timeLeft"]}'
|
||||||
|
|
||||||
return info
|
return info
|
||||||
except Exception as e:
|
except:
|
||||||
print(e)
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
async def __fissures(self) -> Embed:
|
async def __fissures(self) -> Embed:
|
||||||
@ -113,7 +111,6 @@ class Warframe(commands.Cog):
|
|||||||
|
|
||||||
return info
|
return info
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -23,8 +23,7 @@ class Downloader():
|
|||||||
def download_one(self, song: Song) -> Song:
|
def download_one(self, song: Song) -> Song:
|
||||||
"""Receives a song object, finish his download and return it"""
|
"""Receives a song object, finish his download and return it"""
|
||||||
if song.identifier == None:
|
if song.identifier == None:
|
||||||
print('Invalid song identifier type')
|
return None
|
||||||
return
|
|
||||||
|
|
||||||
if is_url(song.identifier): # Youtube URL
|
if is_url(song.identifier): # Youtube URL
|
||||||
song_info = self.__download_url(song.identifier)
|
song_info = self.__download_url(song.identifier)
|
||||||
@ -63,7 +62,6 @@ class Downloader():
|
|||||||
|
|
||||||
return songs_identifiers # Return a list
|
return songs_identifiers # Return a list
|
||||||
except (ExtractorError, DownloadError) as e:
|
except (ExtractorError, DownloadError) as e:
|
||||||
print(e)
|
|
||||||
return None
|
return None
|
||||||
else:
|
else:
|
||||||
print('Invalid type of playlist URL')
|
print('Invalid type of playlist URL')
|
||||||
@ -89,7 +87,7 @@ class Downloader():
|
|||||||
|
|
||||||
return result
|
return result
|
||||||
except (ExtractorError, DownloadError) as e: # Any type of error in download
|
except (ExtractorError, DownloadError) as e: # Any type of error in download
|
||||||
print(e)
|
return None
|
||||||
|
|
||||||
async def __download_songs(self, song: Song) -> None:
|
async def __download_songs(self, song: Song) -> None:
|
||||||
"""Download a music object asynchronously"""
|
"""Download a music object asynchronously"""
|
||||||
@ -122,8 +120,7 @@ class Downloader():
|
|||||||
Return: A dict containing the song information
|
Return: A dict containing the song information
|
||||||
"""
|
"""
|
||||||
if type(title) != str:
|
if type(title) != str:
|
||||||
print('Invalid music identifier type')
|
return None
|
||||||
return
|
|
||||||
|
|
||||||
config = self.__YDL_OPTIONS
|
config = self.__YDL_OPTIONS
|
||||||
config['extract_flat'] = False
|
config['extract_flat'] = False
|
||||||
@ -134,9 +131,9 @@ class Downloader():
|
|||||||
result = ydl.extract_info(search, download=False)
|
result = ydl.extract_info(search, download=False)
|
||||||
|
|
||||||
if result == None:
|
if result == None:
|
||||||
return
|
return None
|
||||||
|
|
||||||
# Return a dict with the full info of first music
|
# Return a dict with the full info of first music
|
||||||
return result['entries'][0]
|
return result['entries'][0]
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
return None
|
||||||
|
|||||||
@ -161,8 +161,7 @@ class Music(commands.Cog):
|
|||||||
embed = message.embeds[0]
|
embed = message.embeds[0]
|
||||||
if embed.title == 'Song Playing Now' or embed.title == 'Song Looping Now':
|
if embed.title == 'Song Playing Now' or embed.title == 'Song Looping Now':
|
||||||
await message.delete()
|
await message.delete()
|
||||||
except Exception as e:
|
except:
|
||||||
print(e)
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
def __get_player(self, ctx):
|
def __get_player(self, ctx):
|
||||||
|
|||||||
@ -59,22 +59,29 @@ class Player(commands.Cog):
|
|||||||
if self.__guild.voice_client == None:
|
if self.__guild.voice_client == None:
|
||||||
voice_channel = ctx.author.voice.channel
|
voice_channel = ctx.author.voice.channel
|
||||||
await voice_channel.connect()
|
await voice_channel.connect()
|
||||||
except Exception as e:
|
except:
|
||||||
print(e)
|
embed = discord.Embed(
|
||||||
return config.NO_CHANNEL
|
description=config.NO_CHANNEL, colour=config.COLOURS['red'])
|
||||||
|
await ctx.send(embed=embed)
|
||||||
else:
|
else:
|
||||||
songs_quant = 0
|
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:
|
if provider == Provider.Unknown:
|
||||||
return config.INVALID_INPUT
|
return config.INVALID_INPUT
|
||||||
|
|
||||||
if provider == Provider.YouTube:
|
if provider == Provider.YouTube:
|
||||||
|
try:
|
||||||
musics_identifiers = self.__downloader.extract_youtube_link(
|
musics_identifiers = self.__downloader.extract_youtube_link(
|
||||||
musics_identifiers[0])
|
musics_identifiers[0])
|
||||||
|
except:
|
||||||
|
await ctx.send('Problema com o download do Youtube')
|
||||||
|
|
||||||
for identifier in musics_identifiers: # Creating songs
|
for identifier in musics_identifiers: # Creating songs
|
||||||
print('Creating Song')
|
|
||||||
last_song = self.__playlist.add_song(identifier)
|
last_song = self.__playlist.add_song(identifier)
|
||||||
songs_quant += 1
|
songs_quant += 1
|
||||||
|
|
||||||
@ -253,8 +260,7 @@ class Player(commands.Cog):
|
|||||||
try:
|
try:
|
||||||
position = int(position)
|
position = int(position)
|
||||||
|
|
||||||
except Exception as e:
|
except:
|
||||||
print(e)
|
|
||||||
return 'This command require a number'
|
return 'This command require a number'
|
||||||
|
|
||||||
result = self.__playlist.remove_song(position)
|
result = self.__playlist.remove_song(position)
|
||||||
|
|||||||
@ -8,7 +8,6 @@ class Searcher():
|
|||||||
|
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
self.__Spotify = SpotifySearch()
|
self.__Spotify = SpotifySearch()
|
||||||
print(f'Spotify Connected: {self.__Spotify.connect()}')
|
|
||||||
|
|
||||||
def search(self, music: str) -> list:
|
def search(self, music: str) -> list:
|
||||||
"""Return a list with the song names or an URL
|
"""Return a list with the song names or an URL
|
||||||
@ -22,8 +21,11 @@ class Searcher():
|
|||||||
return [music], Provider.YouTube
|
return [music], Provider.YouTube
|
||||||
|
|
||||||
elif url_type == Provider.Spotify:
|
elif url_type == Provider.Spotify:
|
||||||
|
if self.__Spotify.connected == True:
|
||||||
musics = self.__Spotify.search(music)
|
musics = self.__Spotify.search(music)
|
||||||
return musics, Provider.Name
|
return musics, Provider.Name
|
||||||
|
else:
|
||||||
|
return [], Provider.Unknown
|
||||||
|
|
||||||
elif url_type == Provider.Name:
|
elif url_type == Provider.Name:
|
||||||
return [music], Provider.Name
|
return [music], Provider.Name
|
||||||
|
|||||||
@ -22,7 +22,6 @@ class Song(ISong):
|
|||||||
try:
|
try:
|
||||||
self.__info[key] = info[key]
|
self.__info[key] = info[key]
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
|
||||||
raise e
|
raise e
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
|||||||
@ -8,8 +8,13 @@ class SpotifySearch():
|
|||||||
|
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
self.__connected = False
|
self.__connected = False
|
||||||
|
self.__connect()
|
||||||
|
|
||||||
def connect(self) -> bool:
|
@property
|
||||||
|
def connected(self):
|
||||||
|
return self.__connected
|
||||||
|
|
||||||
|
def __connect(self) -> bool:
|
||||||
try:
|
try:
|
||||||
# Initialize the connection with Spotify API
|
# Initialize the connection with Spotify API
|
||||||
self.__api = spotipy.Spotify(auth_manager=SpotifyClientCredentials(
|
self.__api = spotipy.Spotify(auth_manager=SpotifyClientCredentials(
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user