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

Support Royalnet 5.4

This commit is contained in:
Steffo 2020-02-03 17:22:44 +01:00
parent ea847631ac
commit f33fb74e6d
3 changed files with 23 additions and 24 deletions

View file

@ -1,16 +1,15 @@
import discord
import pickle
import base64
import datetime import datetime
from typing import * from typing import *
from royalnet.commands import *
from royalnet.serf.discord import * import discord
from royalnet.bard import * import royalnet.commands as rc
from royalnet.backpack.tables.users import User import royalnet.serf.discord as rsd
import royalnet.bard.discord as rbd
from ..utils import RoyalQueue from ..utils import RoyalQueue
class DiscordPlayEvent(Event): class DiscordPlayEvent(rc.Event):
name = "discord_play" name = "discord_play"
async def run(self, async def run(self,
@ -19,16 +18,16 @@ class DiscordPlayEvent(Event):
user: Optional[str] = None, user: Optional[str] = None,
force_color: Optional[int] = None, force_color: Optional[int] = None,
**kwargs) -> dict: **kwargs) -> dict:
if not isinstance(self.serf, DiscordSerf): if not isinstance(self.serf, rsd.DiscordSerf):
raise UnsupportedError() raise rc.UnsupportedError()
serf: DiscordSerf = self.serf serf: rsd.DiscordSerf = self.serf
client: discord.Client = self.serf.client client: discord.Client = self.serf.client
# TODO: fix this in Royalnet sometime # TODO: fix this in Royalnet sometime
candidate_players: List[VoicePlayer] = [] candidate_players: List[rsd.VoicePlayer] = []
for player in serf.voice_players: for player in serf.voice_players:
player: VoicePlayer player: rsd.VoicePlayer
if not player.voice_client.is_connected(): if not player.voice_client.is_connected():
continue continue
if guild_id is not None: if guild_id is not None:
@ -38,17 +37,17 @@ class DiscordPlayEvent(Event):
candidate_players.append(player) candidate_players.append(player)
if len(candidate_players) == 0: 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]!")
elif len(candidate_players) == 1: elif len(candidate_players) == 1:
voice_player = candidate_players[0] voice_player = candidate_players[0]
else: 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!") "Invia il comando su Discord, per favore!")
ytds = await YtdlDiscord.from_url(url) ytds = await rbd.YtdlDiscord.from_url(url)
added: List[YtdlDiscord] = [] added: List[rbd.YtdlDiscord] = []
too_long: List[YtdlDiscord] = [] too_long: List[rbd.YtdlDiscord] = []
if isinstance(voice_player.playing, RoyalQueue): if isinstance(voice_player.playing, RoyalQueue):
for index, ytd in enumerate(ytds): for index, ytd in enumerate(ytds):
if ytd.info.duration >= datetime.timedelta(seconds=self.config["Play"]["max_song_duration"]): 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(): if not voice_player.voice_client.is_playing():
await voice_player.start() await voice_player.start()
else: 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"]) main_channel: discord.TextChannel = client.get_channel(self.config["Discord"]["main_channel_id"])
if len(added) > 0: if len(added) > 0:
if user: 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: 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:")) f" coda:"))
for ytd in added: for ytd in added:
embed: discord.Embed = ytd.embed() embed: discord.Embed = ytd.embed()
@ -78,7 +77,7 @@ class DiscordPlayEvent(Event):
if len(too_long) > 0: if len(too_long) > 0:
if user: 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"{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" 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'}" f" perchè durava{'' if len(too_long) == 1 else 'no'}"

View file

@ -1,6 +1,6 @@
import logging import logging
from typing import Optional, List, AsyncGenerator, Tuple, Any, Dict 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 from royalnet.serf.discord import Playable
import discord import discord

View file

@ -1 +1 @@
semantic = "5.3.6" semantic = "5.4"