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

28 lines
965 B
Python
Raw Normal View History

2020-01-05 23:44:02 +00:00
from .play import PlayCommand
from royalnet.commands import *
import aiohttp
import urllib.parse
class FunkwhaleCommand(PlayCommand):
name: str = "funkwhale"
2020-01-16 02:07:38 +00:00
aliases = ["fuckwhale", "fw", "royalwhale", "rw"]
2020-01-05 23:44:02 +00:00
description: str = "Cerca un video su RoyalWhale e lo aggiunge alla coda della chat vocale."
syntax = "{ricerca}"
2020-01-30 19:08:31 +00:00
def get_embed_color(self):
return 0x009FE3
2020-01-05 23:44:02 +00:00
async def get_url(self, args):
search = urllib.parse.quote(args.joined(require_at_least=1))
async with aiohttp.ClientSession() as session:
async with session.get(self.config["Funkwhale"]["instance_url"] +
f"/api/v1/search?query={search}") as response:
j = await response.json()
if len(j["tracks"]) < 1:
2020-01-13 13:53:05 +00:00
raise UserError("Nessun file audio trovato con il nome richiesto.")
2020-01-05 23:44:02 +00:00
return f'{self.config["Funkwhale"]["instance_url"]}{j["tracks"][0]["listen_url"]}'