1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-24 03:54:20 +00:00
royalnet/royalpack/commands/lazyfunkwhale.py

30 lines
1 KiB
Python
Raw Normal View History

2020-05-10 22:46:12 +00:00
from typing import *
import royalnet.commands as rc
2020-03-29 19:19:58 +00:00
import aiohttp
import urllib.parse
2020-05-10 22:46:12 +00:00
from .lazyplay import LazyplayCommand
2020-03-29 19:19:58 +00:00
class LazyfunkwhaleCommand(LazyplayCommand):
name: str = "lazyfunkwhale"
aliases = ["lazyfuckwhale", "lfw", "lazyroyalwhale", "lrw"]
description: str = "Cerca una canzone su RoyalWhale e aggiungila (lazy) alla coda della chat vocale."
syntax = "{ricerca}"
def get_embed_color(self):
return 0x009FE3
async def get_urls(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-05-10 22:46:12 +00:00
raise rc.UserError("Nessun file audio trovato con il nome richiesto.")
2020-03-29 19:19:58 +00:00
return [f'{self.config["Funkwhale"]["instance_url"]}{j["tracks"][0]["listen_url"]}']