diff --git a/royalpack/commands/__init__.py b/royalpack/commands/__init__.py index b96c3acd..e997f6b8 100644 --- a/royalpack/commands/__init__.py +++ b/royalpack/commands/__init__.py @@ -48,6 +48,8 @@ from .lazypeertube import LazypeertubeCommand from .lazysoundcloud import LazysoundcloudCommand from .lazyyahoovideo import LazyyahoovideoCommand from .lazyyoutube import LazyyoutubeCommand +from .funkwhalealbum import FunkwhalealbumCommand +from .lazyfunkwhalealbum import LazyfunkwhalealbumCommand # Enter the commands of your Pack here! available_commands = [ @@ -100,6 +102,8 @@ available_commands = [ LazysoundcloudCommand, LazyyahoovideoCommand, LazyyoutubeCommand, + FunkwhalealbumCommand, + LazyfunkwhalealbumCommand, ] # Don't change this, it should automatically generate __all__ diff --git a/royalpack/commands/funkwhalealbum.py b/royalpack/commands/funkwhalealbum.py new file mode 100644 index 00000000..4965b2ce --- /dev/null +++ b/royalpack/commands/funkwhalealbum.py @@ -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"]] diff --git a/royalpack/commands/lazyfunkwhalealbum.py b/royalpack/commands/lazyfunkwhalealbum.py new file mode 100644 index 00000000..5de6d935 --- /dev/null +++ b/royalpack/commands/lazyfunkwhalealbum.py @@ -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"]]