2020-01-10 18:03:14 +00:00
|
|
|
from typing import *
|
|
|
|
from starlette.requests import Request
|
|
|
|
from starlette.responses import *
|
|
|
|
from royalnet.constellation import *
|
2020-01-11 14:51:31 +00:00
|
|
|
import logging
|
|
|
|
|
|
|
|
|
|
|
|
log = logging.getLogger(__name__)
|
2020-01-10 18:03:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
class ApiDiscordPlayStar(PageStar):
|
|
|
|
path = "/api/discord/play"
|
|
|
|
|
|
|
|
async def page(self, request: Request) -> JSONResponse:
|
|
|
|
url = request.query_params.get("url", "")
|
2020-01-13 13:51:06 +00:00
|
|
|
user = request.query_params.get("user")
|
2020-01-10 18:03:14 +00:00
|
|
|
try:
|
2020-01-11 14:51:31 +00:00
|
|
|
guild_id: Optional[int] = int(request.query_params.get("guild_id", None))
|
2020-01-10 18:03:14 +00:00
|
|
|
except (ValueError, TypeError):
|
|
|
|
guild_id = None
|
2020-01-11 14:51:31 +00:00
|
|
|
log.info(f"Received request to play {url} on guild_id {guild_id} via web")
|
2020-01-13 13:51:06 +00:00
|
|
|
response = await self.interface.call_herald_event("discord", "discord_play",
|
|
|
|
url=url,
|
|
|
|
guild_id=guild_id,
|
|
|
|
user=user)
|
2020-01-11 02:27:21 +00:00
|
|
|
return JSONResponse(response, headers={
|
2020-01-13 13:51:06 +00:00
|
|
|
"Access-Control-Allow-Origin": "*",
|
2020-01-11 02:27:21 +00:00
|
|
|
})
|