From 5ed03118c0677216b1e9e225a5ff7221ee40b635 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Mon, 6 Jan 2020 00:44:02 +0100 Subject: [PATCH] Add funkwhale command --- pyproject.toml | 2 +- royalpack/commands/__init__.py | 1 + royalpack/commands/funkwhale.py | 24 ++++++++++++++++++++++++ royalpack/version.py | 2 +- 4 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 royalpack/commands/funkwhale.py diff --git a/pyproject.toml b/pyproject.toml index 01b5f50b..226f19bb 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -2,7 +2,7 @@ [tool.poetry] name = "royalpack" - version = "5.1.9" + version = "5.1.10" description = "A Royalnet command pack for the Royal Games community" authors = ["Stefano Pigozzi "] license = "AGPL-3.0+" diff --git a/royalpack/commands/__init__.py b/royalpack/commands/__init__.py index 6921a8e5..ad70374a 100644 --- a/royalpack/commands/__init__.py +++ b/royalpack/commands/__init__.py @@ -27,6 +27,7 @@ from .ahnonlosoio import AhnonlosoioCommand from .eat import EatCommand from .pmots import PmotsCommand from .peertube import PeertubeCommand +from .funkwhale import FunkwhaleCommand from .eval import EvalCommand from .exec import ExecCommand diff --git a/royalpack/commands/funkwhale.py b/royalpack/commands/funkwhale.py new file mode 100644 index 00000000..cecf1d7b --- /dev/null +++ b/royalpack/commands/funkwhale.py @@ -0,0 +1,24 @@ +from .play import PlayCommand +from royalnet.commands import * +import aiohttp +import urllib.parse + + +class FunkwhaleCommand(PlayCommand): + name: str = "funkwhale" + + aliases = ["fw", "royalwhale", "rw"] + + description: str = "Cerca un video su RoyalWhale e lo aggiunge alla coda della chat vocale." + + syntax = "{ricerca}" + + 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: + raise InvalidInputError("Nessun video trovato.") + return f'{self.config["Funkwhale"]["instance_url"]}{j["tracks"][0]["listen_url"]}' diff --git a/royalpack/version.py b/royalpack/version.py index a0d642bb..c3eb0c9c 100644 --- a/royalpack/version.py +++ b/royalpack/version.py @@ -1 +1 @@ -semantic = "5.1.9" +semantic = "5.1.10"