1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-12-18 07:34:20 +00:00
royalnet/royalpack/commands/queue.py

63 lines
2.7 KiB
Python
Raw Normal View History

2019-11-11 08:56:08 +00:00
import pickle
2019-12-03 00:57:21 +00:00
import base64
2019-11-11 08:56:08 +00:00
import discord
2019-12-03 00:57:21 +00:00
from typing import *
2019-11-11 08:56:08 +00:00
from royalnet.commands import *
2019-12-03 00:57:21 +00:00
from royalnet.utils import *
2019-11-11 08:56:08 +00:00
class QueueCommand(Command):
name: str = "queue"
aliases = ["q"]
description: str = "Visualizza la coda di riproduzione attuale."
2019-11-11 08:56:08 +00:00
async def run(self, args: CommandArgs, data: CommandData) -> None:
2019-12-03 00:57:21 +00:00
if self.interface.name == "discord":
message: discord.Message = data.message
guild: discord.Guild = message.guild
guild_id: Optional[int] = guild.id
2019-11-11 08:56:08 +00:00
else:
2019-12-03 00:57:21 +00:00
guild_id = None
response: Dict[str, Any] = await self.interface.call_herald_event("discord", "discord_queue",
guild_id=guild_id)
queue_type = response["type"]
2019-12-03 18:00:52 +00:00
if queue_type == "RoyalQueue":
2019-12-03 00:57:21 +00:00
next_up = response["next_up"]
now_playing = response["now_playing"]
await data.reply(f" La coda contiene {len(next_up)} file.\n\n")
if now_playing is not None:
reply = f"Attualmente, sta venendo riprodotto:\n"
if self.interface.name == "discord":
await data.reply(reply)
embed = pickle.loads(base64.b64decode(bytes(now_playing["stringified_base64_pickled_discord_embed"],
encoding="ascii")))
# noinspection PyUnboundLocalVariable
await message.channel.send(embed=embed)
else:
reply += f"▶️ {now_playing['title']}\n\n"
await data.reply(reply)
2019-11-11 08:56:08 +00:00
else:
2019-12-03 00:57:21 +00:00
await data.reply("⏹ Attualmente, non sta venendo riprodotto nulla.")
reply = ""
if len(next_up) >= 1:
reply += "I prossimi file in coda sono:\n"
if self.interface.name == "discord":
await data.reply(reply)
for item in next_up[:5]:
embed = pickle.loads(base64.b64decode(bytes(item["stringified_base64_pickled_discord_embed"],
encoding="ascii")))
# noinspection PyUnboundLocalVariable
await message.channel.send(embed=embed)
else:
reply += numberemojiformat([a["title"] for a in next_up[:5]])
await data.reply(reply)
else:
await data.reply(" Non ci sono altri file in coda.")
2019-11-11 08:56:08 +00:00
else:
2019-12-03 00:57:21 +00:00
raise CommandError(f"Non so come visualizzare il contenuto di un [c]{queue_type}[/c].")