Skip to content

Commit

Permalink
Stability update
Browse files Browse the repository at this point in the history
  • Loading branch information
RafaelSolVargas committed Jul 25, 2022
1 parent f27dc1d commit 140c164
Show file tree
Hide file tree
Showing 16 changed files with 41 additions and 20 deletions.
1 change: 1 addition & 0 deletions Config/Messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ def __init__(self) -> None:
self.PLAYER_NOT_PLAYING = f'❌ No song playing. Use {configs.BOT_PREFIX}play to start the player'
self.IMPOSSIBLE_MOVE = 'That is impossible :('
self.ERROR_TITLE = 'Error :-('
self.COMMAND_NOT_FOUND_TITLE = 'This is strange :-('
self.NO_CHANNEL = 'To play some music, connect to any voice channel first.'
self.NO_GUILD = f'This server does not has a Player, try {configs.BOT_PREFIX}reset'
self.INVALID_INPUT = f'This URL was too strange, try something better or type {configs.BOT_PREFIX}help play'
Expand Down
6 changes: 3 additions & 3 deletions DiscordCogs/ControlCog.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ async def help_msg(self, ctx, command_help=''):
return

embedhelp = Embed(
title='Command Help',
description=f'Command {command_help} Not Found',
colour=self.__colors.RED
title='Help',
description=f'Command {command_help} do not exists, type {self.__config.BOT_PREFIX}help to see all commands',
colour=self.__colors.BLACK
)

await ctx.send(embed=embedhelp)
Expand Down
2 changes: 1 addition & 1 deletion DiscordCogs/MusicCog.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ async def resume(self, ctx: Context) -> None:
except Exception as e:
print(f'[ERROR IN COG] -> {e}')

@commands.command(name='prev', help=helper.HELP_PREV, description=helper.HELP_PREV_LONG, aliases=['anterior', 'return', 'previous'])
@commands.command(name='prev', help=helper.HELP_PREV, description=helper.HELP_PREV_LONG, aliases=['anterior', 'return', 'previous', 'back'])
async def prev(self, ctx: Context) -> None:
try:
controller = PrevHandler(ctx, self.__bot)
Expand Down
2 changes: 1 addition & 1 deletion Handlers/ClearHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ async def run(self) -> HandlerResponse:
playlist.clear()
processLock.release()
processLock.release()
return HandlerResponse(self.ctx)
else:
processManager.resetProcess(self.guild, self.ctx)
embed = self.embeds.PLAYER_RESTARTED()
return HandlerResponse(self.ctx, embed)
return HandlerResponse(self.ctx)
3 changes: 2 additions & 1 deletion Handlers/LoopHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ async def run(self, args: str) -> HandlerResponse:
if args == '' or args is None:
playlist.loop_all()
embed = self.embeds.LOOP_ALL_ACTIVATED()
processLock.release()
return HandlerResponse(self.ctx, embed)

args = args.lower()
Expand All @@ -50,7 +51,7 @@ async def run(self, args: str) -> HandlerResponse:
embed = self.embeds.BAD_LOOP_USE()

processLock.release()
return HandlerResponse(self.ctx, embed)
return HandlerResponse(self.ctx, embed, error)
else:
processManager.resetProcess(self.guild, self.ctx)
embed = self.embeds.PLAYER_RESTARTED()
Expand Down
5 changes: 4 additions & 1 deletion Handlers/PauseHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,7 @@ async def run(self) -> HandlerResponse:
queue = processInfo.getQueue()
queue.put(command)

return HandlerResponse(self.ctx)
return HandlerResponse(self.ctx)
else:
embed = self.embeds.NOT_PLAYING()
return HandlerResponse(self.ctx, embed)
9 changes: 8 additions & 1 deletion Handlers/PlayHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,20 @@ async def __downloadSongsAndStore(self, songs: List[Song], processInfo: ProcessI
tasks.append(task)

# In the original order, await for the task and then if successfully downloaded add in the playlist
processManager = ProcessManager()
for index, task in enumerate(tasks):
await task
song = songs[index]
if not song.problematic: # If downloaded add to the playlist and send play command
with processInfo.getLock():
processInfo = processManager.getPlayerInfo(self.guild, self.ctx)
processLock = processInfo.getLock()
acquired = processLock.acquire(timeout=self.config.ACQUIRE_LOCK_TIMEOUT)
if acquired:
playlist.add_song(song)
queue.put(playCommand)
processLock.release()
else:
processManager.resetProcess(self.guild, self.ctx)

def __isUserConnected(self) -> bool:
if self.ctx.author.voice:
Expand Down
1 change: 1 addition & 0 deletions Handlers/PrevHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ async def run(self) -> HandlerResponse:
prevCommand = VCommands(VCommandsType.PREV, self.ctx.author.voice.channel.id)
queue = processInfo.getQueue()
queue.put(prevCommand)
return HandlerResponse(self.ctx)

def __user_connected(self) -> bool:
if self.ctx.author.voice:
Expand Down
5 changes: 2 additions & 3 deletions Handlers/QueueHandler.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import asyncio
from discord.ext.commands import Context
from discord import Client
from Handlers.AbstractHandler import AbstractHandler
Expand Down Expand Up @@ -30,16 +29,16 @@ async def run(self) -> HandlerResponse:
if playlist.isLoopingOne():
song = playlist.getCurrentSong()
embed = self.embeds.ONE_SONG_LOOPING(song.info)
processLock.release() # Release the Lock
return HandlerResponse(self.ctx, embed)

songs_preload = playlist.getSongsToPreload()
allSongs = playlist.getSongs()
if len(songs_preload) == 0:
embed = self.embeds.EMPTY_QUEUE()
processLock.release() # Release the Lock
return HandlerResponse(self.ctx, embed)

asyncio.create_task(self.__down.preload(songs_preload))

if playlist.isLoopingAll():
title = self.messages.ALL_SONGS_LOOPING
else:
Expand Down
5 changes: 4 additions & 1 deletion Handlers/ResetHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,7 @@ async def run(self) -> HandlerResponse:
queue = processInfo.getQueue()
queue.put(command)

return HandlerResponse(self.ctx)
return HandlerResponse(self.ctx)
else:
embed = self.embeds.NOT_PLAYING()
return HandlerResponse(self.ctx, embed)
5 changes: 4 additions & 1 deletion Handlers/ResumeHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,7 @@ async def run(self) -> HandlerResponse:
queue = processInfo.getQueue()
queue.put(command)

return HandlerResponse(self.ctx)
return HandlerResponse(self.ctx)
else:
embed = self.embeds.NOT_PLAYING()
return HandlerResponse(self.ctx, embed)
6 changes: 5 additions & 1 deletion Handlers/SkipHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,8 @@ async def run(self) -> HandlerResponse:
command = VCommands(VCommandsType.SKIP, None)
queue = processInfo.getQueue()
queue.put(command)
return HandlerResponse(self.ctx)

return HandlerResponse(self.ctx)
else:
embed = self.embeds.NOT_PLAYING()
return HandlerResponse(self.ctx, embed)
3 changes: 3 additions & 0 deletions Handlers/StopHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,6 @@ async def run(self) -> HandlerResponse:
queue.put(command)

return HandlerResponse(self.ctx)
else:
embed = self.embeds.NOT_PLAYING()
return HandlerResponse(self.ctx, embed)
4 changes: 0 additions & 4 deletions Music/Downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,6 @@ def finish_one_song(self, song: Song) -> Song:
except DownloadError:
raise DownloadingError()

async def preload(self, songs: List[Song]) -> None:
for song in songs:
asyncio.ensure_future(self.download_song(song))

@run_async
def extract_info(self, url: str) -> List[dict]:
if url == '':
Expand Down
2 changes: 1 addition & 1 deletion Parallelism/PlayerProcess.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ def __skip(self) -> None:
# Lock to work with Player
with self.__playerLock:
if self.__guild.voice_client is not None and self.__playing:
self.__playing = None
self.__playing = False
self.__guild.voice_client.stop()

async def __forceStop(self) -> None:
Expand Down
2 changes: 1 addition & 1 deletion Views/Embeds.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def COMMAND_ERROR(self):

def COMMAND_NOT_FOUND(self) -> Embed:
embed = Embed(
title=self.__messages.ERROR_TITLE,
title=self.__messages.COMMAND_NOT_FOUND_TITLE,
description=self.__messages.COMMAND_NOT_FOUND,
colour=self.__colors.BLACK
)
Expand Down

0 comments on commit 140c164

Please sign in to comment.