1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-30 15:04:18 +00:00
royalnet/royalpack/commands/play.py

55 lines
2 KiB
Python
Raw Normal View History

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 *
2020-01-13 13:51:06 +00:00
from royalnet.backpack.tables import User, Discord
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 get_url(self, args: CommandArgs):
2020-01-13 13:51:06 +00:00
return args.joined(require_at_least=1)
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
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
2020-01-13 13:51:06 +00:00
user: User = await data.get_author()
user_str = None
if user is not None:
try:
user_discord: Discord = user.discord[0]
except (AttributeError, IndexError):
user_str = str(user)
2019-11-11 08:56:08 +00:00
else:
2020-01-13 13:51:06 +00:00
user_str = str(f"<@{user_discord.discord_id}>")
self.loop.create_task(self.interface.call_herald_event("discord", "discord_play",
url=await self.get_url(args),
guild_id=guild_id,
user=user_str))
2020-01-13 13:51:06 +00:00
# await data.reply("✅ Richiesta di riproduzione inviata!")