From 4a9087197e350d2de1e0f17e6274c8e1c6a3a015 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Thu, 9 Apr 2020 20:44:04 +0200 Subject: [PATCH] Fix skip, queue and pause not working --- royalpack/events/discord_pause.py | 26 +++++++++++++++----------- royalpack/events/discord_queue.py | 26 +++++++++++++++----------- royalpack/events/discord_skip.py | 24 ++++++++++++++---------- 3 files changed, 44 insertions(+), 32 deletions(-) diff --git a/royalpack/events/discord_pause.py b/royalpack/events/discord_pause.py index 501510c6..b5131f9f 100644 --- a/royalpack/events/discord_pause.py +++ b/royalpack/events/discord_pause.py @@ -1,33 +1,37 @@ import discord from typing import * -from royalnet.commands import * +import royalnet.commands as rc from royalnet.serf.discord import * -class DiscordPauseEvent(Event): +class DiscordPauseEvent(rc.Event): name = "discord_pause" async def run(self, guild_id: Optional[int] = None, **kwargs) -> dict: if not isinstance(self.serf, DiscordSerf): - raise UnsupportedError() + raise rc.UnsupportedError() client: discord.Client = self.serf.client if len(self.serf.voice_players) == 1: voice_player: VoicePlayer = self.serf.voice_players[0] else: if guild_id is None: # TODO: trovare un modo per riprodurre canzoni su più server da Telegram - raise InvalidInputError("Non so in che Server riprodurre questo file...\n" - "Invia il comando su Discord, per favore!") + raise rc.InvalidInputError("Non so in che Server riprodurre questo file...\n" + "Invia il comando su Discord, per favore!") guild: discord.Guild = client.get_guild(guild_id) if guild is None: - raise InvalidInputError("Impossibile trovare il Server specificato.") - voice_players = self.serf.find_voice_players(guild) - if len(voice_players): - raise UserError("Il bot non è in nessun canale vocale.\n" - "Evocalo prima con [c]summon[/c]!") - voice_player = voice_players[0] + raise rc.InvalidInputError("Impossibile trovare il Server specificato.") + candidate_players = self.serf.find_voice_players(guild) + if len(candidate_players) == 0: + raise rc.UserError("Il bot non è in nessun canale vocale.\n" + "Evocalo prima con [c]summon[/c]!") + elif len(candidate_players) == 1: + voice_player = candidate_players[0] + else: + raise rc.CommandError("Non so su che Server saltare canzone...\n" + "Invia il comando su Discord, per favore!") if voice_player.voice_client.is_paused(): voice_player.voice_client.resume() diff --git a/royalpack/events/discord_queue.py b/royalpack/events/discord_queue.py index 3345e8dc..63a0c59e 100644 --- a/royalpack/events/discord_queue.py +++ b/royalpack/events/discord_queue.py @@ -2,35 +2,39 @@ import discord import pickle import base64 from typing import * -from royalnet.commands import * +import royalnet.commands as rc from royalnet.serf.discord import * from ..utils import RoyalQueue -class DiscordQueueEvent(Event): +class DiscordQueueEvent(rc.Event): name = "discord_queue" async def run(self, guild_id: Optional[int] = None, **kwargs) -> dict: if not isinstance(self.serf, DiscordSerf): - raise UnsupportedError() + raise rc.UnsupportedError() client: discord.Client = self.serf.client if len(self.serf.voice_players) == 1: voice_player: VoicePlayer = self.serf.voice_players[0] else: if guild_id is None: # TODO: trovare un modo per riprodurre canzoni su più server da Telegram - raise InvalidInputError("Non so in che Server riprodurre questo file...\n" + raise rc.InvalidInputError("Non so in che Server riprodurre questo file...\n" "Invia il comando su Discord, per favore!") guild: discord.Guild = client.get_guild(guild_id) if guild is None: - raise InvalidInputError("Impossibile trovare il Server specificato.") - voice_players = self.serf.find_voice_players(guild) - if len(voice_players): - raise UserError("Il bot non è in nessun canale vocale.\n" - "Evocalo prima con [c]summon[/c]!") - voice_player = voice_players[0] + raise rc.InvalidInputError("Impossibile trovare il Server specificato.") + candidate_players = self.serf.find_voice_players(guild) + if len(candidate_players) == 0: + raise rc.UserError("Il bot non è in nessun canale vocale.\n" + "Evocalo prima con [c]summon[/c]!") + elif len(candidate_players) == 1: + voice_player = candidate_players[0] + else: + raise rc.CommandError("Non so di che Server visualizzare la coda...\n" + "Invia il comando su Discord, per favore!") if isinstance(voice_player.playing, RoyalQueue): now_playing = voice_player.playing.now_playing return { @@ -47,5 +51,5 @@ class DiscordQueueEvent(Event): } for ytd in voice_player.playing.contents] } else: - raise CommandError(f"Non so come visualizzare il contenuto di un " + raise rc.CommandError(f"Non so come visualizzare il contenuto di un " f"[c]{voice_player.playing.__class__.__qualname__}[/c].") diff --git a/royalpack/events/discord_skip.py b/royalpack/events/discord_skip.py index e6537d86..69ff7714 100644 --- a/royalpack/events/discord_skip.py +++ b/royalpack/events/discord_skip.py @@ -1,33 +1,37 @@ import discord from typing import * -from royalnet.commands import * +import royalnet.commands as rc from royalnet.serf.discord import * -class DiscordSkipEvent(Event): +class DiscordSkipEvent(rc.Event): name = "discord_skip" async def run(self, guild_id: Optional[int] = None, **kwargs) -> dict: if not isinstance(self.serf, DiscordSerf): - raise UnsupportedError() + raise rc.UnsupportedError() client: discord.Client = self.serf.client if len(self.serf.voice_players) == 1: voice_player: VoicePlayer = self.serf.voice_players[0] else: if guild_id is None: # TODO: trovare un modo per riprodurre canzoni su più server da Telegram - raise InvalidInputError("Non so in che Server riprodurre questo file...\n" + raise rc.InvalidInputError("Non so in che Server riprodurre questo file...\n" "Invia il comando su Discord, per favore!") guild: discord.Guild = client.get_guild(guild_id) if guild is None: - raise InvalidInputError("Impossibile trovare il Server specificato.") - voice_players = self.serf.find_voice_players(guild) - if len(voice_players): - raise UserError("Il bot non è in nessun canale vocale.\n" - "Evocalo prima con [c]summon[/c]!") - voice_player = voice_players[0] + raise rc.InvalidInputError("Impossibile trovare il Server specificato.") + candidate_players = self.serf.find_voice_players(guild) + if len(candidate_players) == 0: + raise rc.UserError("Il bot non è in nessun canale vocale.\n" + "Evocalo prima con [c]summon[/c]!") + elif len(candidate_players) == 1: + voice_player = candidate_players[0] + else: + raise rc.CommandError("Non so su che Server saltare canzone...\n" + "Invia il comando su Discord, per favore!") # Stop the playback of the current song voice_player.voice_client.stop() # Done!