1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2025-02-17 10:53:57 +00:00
royalnet/royalpack/commands/funkwhale.py

32 lines
1.1 KiB
Python
Raw Normal View History

2020-05-11 00:46:12 +02:00
from typing import *
2020-01-06 00:44:02 +01:00
import aiohttp
import urllib.parse
2020-05-11 00:46:12 +02:00
import royalnet.commands as rc
from .play import PlayCommand
2020-01-06 00:44:02 +01:00
class FunkwhaleCommand(PlayCommand):
name: str = "funkwhale"
2020-01-16 03:07:38 +01:00
aliases = ["fuckwhale", "fw", "royalwhale", "rw"]
2020-01-06 00:44:02 +01:00
2020-03-28 18:38:28 +01:00
description: str = "Cerca una canzone su RoyalWhale e aggiungila alla coda della chat vocale."
2020-01-06 00:44:02 +01:00
syntax = "{ricerca}"
2020-01-30 20:08:31 +01:00
def get_embed_color(self):
return 0x009FE3
2020-03-28 19:38:14 +01:00
async def get_urls(self, args):
2020-01-06 00:44:02 +01:00
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:
if response.status >= 400:
raise rc.ExternalError(f"Request returned {response.status}")
2020-01-06 00:44:02 +01:00
j = await response.json()
if len(j["tracks"]) < 1:
2020-05-11 00:46:12 +02:00
raise rc.UserError("Nessun file audio trovato con il nome richiesto.")
2020-03-28 19:38:14 +01:00
return [f'{self.config["Funkwhale"]["instance_url"]}{j["tracks"][0]["listen_url"]}']