From f33fb74e6d1c9d2f093a32c1e765ab44b525e7d2 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Mon, 3 Feb 2020 17:22:44 +0100 Subject: [PATCH] Support Royalnet 5.4 --- royalpack/events/discord_play.py | 43 ++++++++++++++++---------------- royalpack/utils/royalqueue.py | 2 +- royalpack/version.py | 2 +- 3 files changed, 23 insertions(+), 24 deletions(-) diff --git a/royalpack/events/discord_play.py b/royalpack/events/discord_play.py index a2f444bd..9af8e8a7 100644 --- a/royalpack/events/discord_play.py +++ b/royalpack/events/discord_play.py @@ -1,16 +1,15 @@ -import discord -import pickle -import base64 import datetime from typing import * -from royalnet.commands import * -from royalnet.serf.discord import * -from royalnet.bard import * -from royalnet.backpack.tables.users import User + +import discord +import royalnet.commands as rc +import royalnet.serf.discord as rsd +import royalnet.bard.discord as rbd + from ..utils import RoyalQueue -class DiscordPlayEvent(Event): +class DiscordPlayEvent(rc.Event): name = "discord_play" async def run(self, @@ -19,16 +18,16 @@ class DiscordPlayEvent(Event): user: Optional[str] = None, force_color: Optional[int] = None, **kwargs) -> dict: - if not isinstance(self.serf, DiscordSerf): - raise UnsupportedError() + if not isinstance(self.serf, rsd.DiscordSerf): + raise rc.UnsupportedError() - serf: DiscordSerf = self.serf + serf: rsd.DiscordSerf = self.serf client: discord.Client = self.serf.client # TODO: fix this in Royalnet sometime - candidate_players: List[VoicePlayer] = [] + candidate_players: List[rsd.VoicePlayer] = [] for player in serf.voice_players: - player: VoicePlayer + player: rsd.VoicePlayer if not player.voice_client.is_connected(): continue if guild_id is not None: @@ -38,17 +37,17 @@ class DiscordPlayEvent(Event): candidate_players.append(player) 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]!") elif len(candidate_players) == 1: voice_player = candidate_players[0] else: - raise CommandError("Non so in che Server riprodurre questo file...\n" + raise rc.CommandError("Non so in che Server riprodurre questo file...\n" "Invia il comando su Discord, per favore!") - ytds = await YtdlDiscord.from_url(url) - added: List[YtdlDiscord] = [] - too_long: List[YtdlDiscord] = [] + ytds = await rbd.YtdlDiscord.from_url(url) + added: List[rbd.YtdlDiscord] = [] + too_long: List[rbd.YtdlDiscord] = [] if isinstance(voice_player.playing, RoyalQueue): for index, ytd in enumerate(ytds): if ytd.info.duration >= datetime.timedelta(seconds=self.config["Play"]["max_song_duration"]): @@ -60,15 +59,15 @@ class DiscordPlayEvent(Event): if not voice_player.voice_client.is_playing(): await voice_player.start() else: - raise CommandError(f"Non so come aggiungere musica a [c]{voice_player.playing.__class__.__qualname__}[/c]!") + raise rc.CommandError(f"Non so come aggiungere musica a [c]{voice_player.playing.__class__.__qualname__}[/c]!") main_channel: discord.TextChannel = client.get_channel(self.config["Discord"]["main_channel_id"]) if len(added) > 0: if user: - await main_channel.send(escape(f"▶️ {user} ha aggiunto {len(added)} file alla coda:")) + await main_channel.send(rsd.escape(f"▶️ {user} ha aggiunto {len(added)} file alla coda:")) else: - await main_channel.send(escape(f"▶️ Aggiunt{'o' if len(added) == 1 else 'i'} {len(added)} file alla" + await main_channel.send(rsd.escape(f"▶️ Aggiunt{'o' if len(added) == 1 else 'i'} {len(added)} file alla" f" coda:")) for ytd in added: embed: discord.Embed = ytd.embed() @@ -78,7 +77,7 @@ class DiscordPlayEvent(Event): if len(too_long) > 0: if user: - await main_channel.send(escape( + await main_channel.send(rsd.escape( f"⚠ {len(too_long)} file non {'è' if len(too_long) == 1 else 'sono'}" f" stat{'o' if len(too_long) == 1 else 'i'} scaricat{'o' if len(too_long) == 1 else 'i'}" f" perchè durava{'' if len(too_long) == 1 else 'no'}" diff --git a/royalpack/utils/royalqueue.py b/royalpack/utils/royalqueue.py index a70aa04a..373c7c37 100644 --- a/royalpack/utils/royalqueue.py +++ b/royalpack/utils/royalqueue.py @@ -1,6 +1,6 @@ import logging from typing import Optional, List, AsyncGenerator, Tuple, Any, Dict -from royalnet.bard import YtdlDiscord +from royalnet.bard.discord import YtdlDiscord from royalnet.serf.discord import Playable import discord diff --git a/royalpack/version.py b/royalpack/version.py index d4ff852a..03217183 100644 --- a/royalpack/version.py +++ b/royalpack/version.py @@ -1 +1 @@ -semantic = "5.3.6" +semantic = "5.4"