1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-27 13:34:28 +00:00

Add funkwhalealbum and lazyfunkwhalealbum commands

This commit is contained in:
Steffo 2020-04-08 18:56:16 +02:00
parent 15c83da73b
commit d5e38ae29a
3 changed files with 60 additions and 0 deletions

View file

@ -48,6 +48,8 @@ from .lazypeertube import LazypeertubeCommand
from .lazysoundcloud import LazysoundcloudCommand from .lazysoundcloud import LazysoundcloudCommand
from .lazyyahoovideo import LazyyahoovideoCommand from .lazyyahoovideo import LazyyahoovideoCommand
from .lazyyoutube import LazyyoutubeCommand from .lazyyoutube import LazyyoutubeCommand
from .funkwhalealbum import FunkwhalealbumCommand
from .lazyfunkwhalealbum import LazyfunkwhalealbumCommand
# Enter the commands of your Pack here! # Enter the commands of your Pack here!
available_commands = [ available_commands = [
@ -100,6 +102,8 @@ available_commands = [
LazysoundcloudCommand, LazysoundcloudCommand,
LazyyahoovideoCommand, LazyyahoovideoCommand,
LazyyoutubeCommand, LazyyoutubeCommand,
FunkwhalealbumCommand,
LazyfunkwhalealbumCommand,
] ]
# Don't change this, it should automatically generate __all__ # Don't change this, it should automatically generate __all__

View file

@ -0,0 +1,28 @@
from .play import PlayCommand
from royalnet.commands import *
import aiohttp
import urllib.parse
class FunkwhalealbumCommand(PlayCommand):
name: str = "funkwhalealbum"
aliases = ["fwa", "fwalbum", "funkwhalea"]
description: str = "Cerca un album su RoyalWhale e aggiungila 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["albums"]) < 1:
raise UserError("Nessun file audio trovato con il nome richiesto.")
album = j["albums"][0]
return [f'{self.config["Funkwhale"]["instance_url"]}{track["listen_url"]}' for track in album["tracks"]]

View file

@ -0,0 +1,28 @@
from .lazyplay import LazyplayCommand
from royalnet.commands import *
import aiohttp
import urllib.parse
class LazyfunkwhalealbumCommand(LazyplayCommand):
name: str = "lazyfunkwhalealbum"
aliases = ["lfwa", "lfwalbum", "lazyfunkwhalea"]
description: str = "Cerca un album su RoyalWhale e aggiungilo (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["albums"]) < 1:
raise UserError("Nessun file audio trovato con il nome richiesto.")
album = j["albums"][0]
return [f'{self.config["Funkwhale"]["instance_url"]}{track["listen_url"]}' for track in album["tracks"]]