2020-01-10 18:03:14 +00:00
|
|
|
from typing import *
|
2020-02-08 00:49:07 +00:00
|
|
|
from royalnet.constellation.api import *
|
2020-01-11 14:51:31 +00:00
|
|
|
import logging
|
|
|
|
|
|
|
|
|
|
|
|
log = logging.getLogger(__name__)
|
2020-01-10 18:03:14 +00:00
|
|
|
|
|
|
|
|
2020-02-08 00:49:07 +00:00
|
|
|
class ApiDiscordPlayStar(ApiStar):
|
2020-02-09 18:12:34 +00:00
|
|
|
path = "/api/discord/play/v1"
|
2020-01-10 18:03:14 +00:00
|
|
|
|
2020-02-08 00:49:07 +00:00
|
|
|
async def api(self, data: ApiData) -> dict:
|
|
|
|
url = data["url"]
|
|
|
|
user = data.get("user")
|
|
|
|
guild_id_str = data.get("guild_id")
|
|
|
|
if guild_id_str:
|
|
|
|
try:
|
|
|
|
guild_id: Optional[int] = int(guild_id_str)
|
|
|
|
except (ValueError, TypeError):
|
|
|
|
raise InvalidParameterError("'guild_id' is not a valid int.")
|
2020-02-24 00:50:54 +00:00
|
|
|
else:
|
|
|
|
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-02-09 18:12:34 +00:00
|
|
|
return response
|