From 6514d56519086f2a7a4e0f59573c39223e173d97 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Fri, 10 Jan 2020 19:03:14 +0100 Subject: [PATCH] Add api_discord_play endpoint --- royalpack/stars/__init__.py | 2 ++ royalpack/stars/api_discord_play.py | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 royalpack/stars/api_discord_play.py diff --git a/royalpack/stars/__init__.py b/royalpack/stars/__init__.py index 209efcfa..a5f71714 100644 --- a/royalpack/stars/__init__.py +++ b/royalpack/stars/__init__.py @@ -6,6 +6,7 @@ from .api_diario_get import ApiDiarioGetStar from .api_discord_cv import ApiDiscordCvStar from .api_wiki_get import ApiWikiGetStar from .api_wiki_list import ApiUserListStar +from .api_discord_play import ApiDiscordPlayStar # Enter the PageStars of your Pack here! available_page_stars = [ @@ -16,6 +17,7 @@ available_page_stars = [ ApiDiscordCvStar, ApiWikiGetStar, ApiUserListStar, + ApiDiscordPlayStar, ] # Enter the ExceptionStars of your Pack here! diff --git a/royalpack/stars/api_discord_play.py b/royalpack/stars/api_discord_play.py new file mode 100644 index 00000000..fc29674b --- /dev/null +++ b/royalpack/stars/api_discord_play.py @@ -0,0 +1,18 @@ +from typing import * +from starlette.requests import Request +from starlette.responses import * +from royalnet.constellation import * +from royalnet.utils import * + + +class ApiDiscordPlayStar(PageStar): + path = "/api/discord/play" + + async def page(self, request: Request) -> JSONResponse: + url = request.query_params.get("url", "") + try: + guild_id: Optional[int] = int(request.path_params.get("guild_id", None)) + except (ValueError, TypeError): + guild_id = None + response = await self.interface.call_herald_event("discord", "discord_play", url=url, guild_id=guild_id) + return JSONResponse(response)