2019-11-11 08:56:08 +00:00
|
|
|
import pickle
|
2019-12-01 22:53:47 +00:00
|
|
|
import base64
|
2019-11-11 08:56:08 +00:00
|
|
|
import discord
|
2019-12-01 22:53:47 +00:00
|
|
|
from typing import *
|
2019-11-11 08:56:08 +00:00
|
|
|
from royalnet.commands import *
|
2019-12-01 22:53:47 +00:00
|
|
|
from royalnet.utils import *
|
2019-11-11 08:56:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
class PlayCommand(Command):
|
|
|
|
name: str = "play"
|
|
|
|
|
|
|
|
aliases = ["p"]
|
|
|
|
|
|
|
|
description: str = "Aggiunge un url alla coda della chat vocale."
|
|
|
|
|
2019-12-01 22:53:47 +00:00
|
|
|
syntax = "{url}"
|
2019-11-11 08:56:08 +00:00
|
|
|
|
2019-12-17 19:11:05 +00:00
|
|
|
async def get_url(self, args: CommandArgs):
|
|
|
|
return args.joined()
|
2019-12-02 20:25:56 +00:00
|
|
|
|
2019-11-11 08:56:08 +00:00
|
|
|
async def run(self, args: CommandArgs, data: CommandData) -> None:
|
2019-12-01 22:53:47 +00:00
|
|
|
# if not (url.startswith("http://") or url.startswith("https://")):
|
|
|
|
# raise CommandError(f"Il comando [c]{self.interface.prefix}play[/c] funziona solo per riprodurre file da"
|
|
|
|
# f" un URL.\n"
|
|
|
|
# f"Se vuoi cercare un video, come misura temporanea puoi usare "
|
|
|
|
# f"[c]ytsearch:nomevideo[/c] o [c]scsearch:nomevideo[/c] come url.")
|
|
|
|
if self.interface.name == "discord":
|
|
|
|
message: discord.Message = data.message
|
|
|
|
guild: discord.Guild = message.guild
|
2019-12-17 19:11:05 +00:00
|
|
|
if guild is None:
|
|
|
|
guild_id = None
|
|
|
|
else:
|
|
|
|
guild_id: Optional[int] = guild.id
|
2019-12-01 22:53:47 +00:00
|
|
|
else:
|
|
|
|
guild_id = None
|
|
|
|
response: Dict[str, Any] = await self.interface.call_herald_event("discord", "discord_play",
|
2019-12-17 19:11:05 +00:00
|
|
|
url=await self.get_url(args),
|
2019-12-02 20:25:56 +00:00
|
|
|
guild_id=guild_id)
|
2019-12-01 22:53:47 +00:00
|
|
|
|
|
|
|
too_long: List[Dict[str, Any]] = response["too_long"]
|
|
|
|
if len(too_long) > 0:
|
|
|
|
await data.reply(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'}"
|
|
|
|
f" più di [c]{self.config['Play']['max_song_duration']}[/c] secondi.")
|
|
|
|
|
|
|
|
added: List[Dict[str, Any]] = response["added"]
|
|
|
|
if len(added) > 0:
|
|
|
|
reply = f"▶️ Aggiunt{'o' if len(added) == 1 else 'i'} {len(added)} file alla coda:\n"
|
2019-11-11 08:56:08 +00:00
|
|
|
if self.interface.name == "discord":
|
2019-12-01 22:53:47 +00:00
|
|
|
await data.reply(reply)
|
|
|
|
for item in added:
|
|
|
|
embed = pickle.loads(base64.b64decode(bytes(item["stringified_base64_pickled_discord_embed"],
|
|
|
|
encoding="ascii")))
|
|
|
|
# noinspection PyUnboundLocalVariable
|
|
|
|
await message.channel.send(embed=embed)
|
2019-11-11 08:56:08 +00:00
|
|
|
else:
|
2019-12-01 22:53:47 +00:00
|
|
|
reply += numberemojiformat([a["title"] for a in added])
|
|
|
|
await data.reply(reply)
|
2019-12-02 20:25:56 +00:00
|
|
|
|
|
|
|
if len(added) + len(too_long) == 0:
|
2019-12-17 19:11:05 +00:00
|
|
|
raise ExternalError("Nessun video trovato.")
|