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
|
|
|
|
|
|
|
async def run(self, args: CommandArgs, data: CommandData) -> None:
|
2019-12-01 22:53:47 +00:00
|
|
|
url = args.joined()
|
|
|
|
# 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
|
|
|
|
guild_id: Optional[int] = guild.id
|
|
|
|
else:
|
|
|
|
guild_id = None
|
|
|
|
response: Dict[str, Any] = await self.interface.call_herald_event("discord", "discord_play",
|
|
|
|
url=url, guild_id=guild_id)
|
|
|
|
|
|
|
|
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)
|