1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-23 19:44:20 +00:00

Fix skip, queue and pause not working

This commit is contained in:
Steffo 2020-04-09 20:44:04 +02:00
parent e634ab86ad
commit 4a9087197e
3 changed files with 44 additions and 32 deletions

View file

@ -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()

View file

@ -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].")

View file

@ -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!