1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2025-02-17 10:53:57 +00:00
royalnet/royalpack/stars/api_discord_play.py

41 lines
1.4 KiB
Python
Raw Normal View History

2020-01-10 19:03:14 +01:00
from typing import *
2020-06-26 16:13:11 +02:00
import royalnet.constellation.api as rca
2020-01-11 15:51:31 +01:00
import logging
log = logging.getLogger(__name__)
2020-01-10 19:03:14 +01:00
2020-06-26 16:13:11 +02:00
class ApiDiscordPlayStar(rca.ApiStar):
2020-06-22 19:27:11 +02:00
path = "/api/discord/play/v2"
2020-01-10 19:03:14 +01:00
2020-03-09 21:21:07 +01:00
parameters = {
2020-06-22 19:27:11 +02:00
"post": {
"url": "The url of the audio file to add.",
"user": "The name to display in the File Added message.",
"guild_id": "The id of the guild owning the RoyalQueue to add the audio file to.",
}
2020-03-09 21:21:07 +01:00
}
tags = ["discord"]
2020-06-26 16:13:11 +02:00
@rca.magic
async def post(self, data: rca.ApiData) -> dict:
2020-06-22 19:27:11 +02:00
"""Add a audio file to the RoyalQueue of a Discord Guild."""
2020-02-08 01:49:07 +01:00
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):
2020-06-26 16:13:11 +02:00
raise rca.InvalidParameterError("'guild_id' is not a valid int.")
2020-02-24 01:50:54 +01:00
else:
guild_id = None
2020-01-11 15:51:31 +01:00
log.info(f"Received request to play {url} on guild_id {guild_id} via web")
2020-01-13 14:51:06 +01:00
response = await self.interface.call_herald_event("discord", "discord_play",
urls=[url],
2020-01-13 14:51:06 +01:00
guild_id=guild_id,
user=user)
2020-02-09 19:12:34 +01:00
return response