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 import discord
from typing import * from typing import *
from royalnet.commands import * import royalnet.commands as rc
from royalnet.serf.discord import * from royalnet.serf.discord import *
class DiscordPauseEvent(Event): class DiscordPauseEvent(rc.Event):
name = "discord_pause" name = "discord_pause"
async def run(self, async def run(self,
guild_id: Optional[int] = None, guild_id: Optional[int] = None,
**kwargs) -> dict: **kwargs) -> dict:
if not isinstance(self.serf, DiscordSerf): if not isinstance(self.serf, DiscordSerf):
raise UnsupportedError() raise rc.UnsupportedError()
client: discord.Client = self.serf.client client: discord.Client = self.serf.client
if len(self.serf.voice_players) == 1: if len(self.serf.voice_players) == 1:
voice_player: VoicePlayer = self.serf.voice_players[0] voice_player: VoicePlayer = self.serf.voice_players[0]
else: else:
if guild_id is None: if guild_id is None:
# TODO: trovare un modo per riprodurre canzoni su più server da Telegram # 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!") "Invia il comando su Discord, per favore!")
guild: discord.Guild = client.get_guild(guild_id) guild: discord.Guild = client.get_guild(guild_id)
if guild is None: if guild is None:
raise InvalidInputError("Impossibile trovare il Server specificato.") raise rc.InvalidInputError("Impossibile trovare il Server specificato.")
voice_players = self.serf.find_voice_players(guild) candidate_players = self.serf.find_voice_players(guild)
if len(voice_players): if len(candidate_players) == 0:
raise UserError("Il bot non è in nessun canale vocale.\n" raise rc.UserError("Il bot non è in nessun canale vocale.\n"
"Evocalo prima con [c]summon[/c]!") "Evocalo prima con [c]summon[/c]!")
voice_player = voice_players[0] 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(): if voice_player.voice_client.is_paused():
voice_player.voice_client.resume() voice_player.voice_client.resume()

View file

@ -2,35 +2,39 @@ import discord
import pickle import pickle
import base64 import base64
from typing import * from typing import *
from royalnet.commands import * import royalnet.commands as rc
from royalnet.serf.discord import * from royalnet.serf.discord import *
from ..utils import RoyalQueue from ..utils import RoyalQueue
class DiscordQueueEvent(Event): class DiscordQueueEvent(rc.Event):
name = "discord_queue" name = "discord_queue"
async def run(self, async def run(self,
guild_id: Optional[int] = None, guild_id: Optional[int] = None,
**kwargs) -> dict: **kwargs) -> dict:
if not isinstance(self.serf, DiscordSerf): if not isinstance(self.serf, DiscordSerf):
raise UnsupportedError() raise rc.UnsupportedError()
client: discord.Client = self.serf.client client: discord.Client = self.serf.client
if len(self.serf.voice_players) == 1: if len(self.serf.voice_players) == 1:
voice_player: VoicePlayer = self.serf.voice_players[0] voice_player: VoicePlayer = self.serf.voice_players[0]
else: else:
if guild_id is None: if guild_id is None:
# TODO: trovare un modo per riprodurre canzoni su più server da Telegram # 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!") "Invia il comando su Discord, per favore!")
guild: discord.Guild = client.get_guild(guild_id) guild: discord.Guild = client.get_guild(guild_id)
if guild is None: if guild is None:
raise InvalidInputError("Impossibile trovare il Server specificato.") raise rc.InvalidInputError("Impossibile trovare il Server specificato.")
voice_players = self.serf.find_voice_players(guild) candidate_players = self.serf.find_voice_players(guild)
if len(voice_players): if len(candidate_players) == 0:
raise UserError("Il bot non è in nessun canale vocale.\n" raise rc.UserError("Il bot non è in nessun canale vocale.\n"
"Evocalo prima con [c]summon[/c]!") "Evocalo prima con [c]summon[/c]!")
voice_player = voice_players[0] 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): if isinstance(voice_player.playing, RoyalQueue):
now_playing = voice_player.playing.now_playing now_playing = voice_player.playing.now_playing
return { return {
@ -47,5 +51,5 @@ class DiscordQueueEvent(Event):
} for ytd in voice_player.playing.contents] } for ytd in voice_player.playing.contents]
} }
else: 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].") f"[c]{voice_player.playing.__class__.__qualname__}[/c].")

View file

@ -1,33 +1,37 @@
import discord import discord
from typing import * from typing import *
from royalnet.commands import * import royalnet.commands as rc
from royalnet.serf.discord import * from royalnet.serf.discord import *
class DiscordSkipEvent(Event): class DiscordSkipEvent(rc.Event):
name = "discord_skip" name = "discord_skip"
async def run(self, async def run(self,
guild_id: Optional[int] = None, guild_id: Optional[int] = None,
**kwargs) -> dict: **kwargs) -> dict:
if not isinstance(self.serf, DiscordSerf): if not isinstance(self.serf, DiscordSerf):
raise UnsupportedError() raise rc.UnsupportedError()
client: discord.Client = self.serf.client client: discord.Client = self.serf.client
if len(self.serf.voice_players) == 1: if len(self.serf.voice_players) == 1:
voice_player: VoicePlayer = self.serf.voice_players[0] voice_player: VoicePlayer = self.serf.voice_players[0]
else: else:
if guild_id is None: if guild_id is None:
# TODO: trovare un modo per riprodurre canzoni su più server da Telegram # 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!") "Invia il comando su Discord, per favore!")
guild: discord.Guild = client.get_guild(guild_id) guild: discord.Guild = client.get_guild(guild_id)
if guild is None: if guild is None:
raise InvalidInputError("Impossibile trovare il Server specificato.") raise rc.InvalidInputError("Impossibile trovare il Server specificato.")
voice_players = self.serf.find_voice_players(guild) candidate_players = self.serf.find_voice_players(guild)
if len(voice_players): if len(candidate_players) == 0:
raise UserError("Il bot non è in nessun canale vocale.\n" raise rc.UserError("Il bot non è in nessun canale vocale.\n"
"Evocalo prima con [c]summon[/c]!") "Evocalo prima con [c]summon[/c]!")
voice_player = voice_players[0] 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 # Stop the playback of the current song
voice_player.voice_client.stop() voice_player.voice_client.stop()
# Done! # Done!