1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-12-17 23:24:20 +00:00
royalnet/royalpack/events/discord_playable.py

49 lines
1.7 KiB
Python
Raw Normal View History

2020-03-28 23:14:55 +00:00
import datetime
from typing import *
import discord
import royalnet.commands as rc
import royalnet.serf.discord as rsd
import royalnet.bard.discord as rbd
from ..utils import RoyalQueue, RoyalPool
class DiscordPlaymodeEvent(rc.Event):
name = "discord_playmode"
async def run(self,
playable_string: str,
guild_id: Optional[int] = None,
user: Optional[str] = None,
**kwargs) -> dict:
if not isinstance(self.serf, rsd.DiscordSerf):
raise rc.UnsupportedError()
serf: rsd.DiscordSerf = self.serf
client: discord.Client = self.serf.client
guild: discord.Guild = client.get_guild(guild_id) if guild_id is not None else None
candidate_players: List[rsd.VoicePlayer] = serf.find_voice_players(guild)
if len(candidate_players) == 0:
raise rc.UserError("Il bot non è in nessun canale vocale.\n"
"Evocalo prima con [c]summon[/c]!")
elif len(candidate_players) == 1:
voice_player = candidate_players[0]
else:
raise rc.CommandError("Non so a che Server cambiare Playable...\n"
"Invia il comando su Discord, per favore!")
if playable_string.upper() == "QUEUE":
2020-03-29 23:33:07 +00:00
playable = await RoyalQueue.create()
2020-03-28 23:14:55 +00:00
elif playable_string.upper() == "POOL":
2020-03-29 23:33:07 +00:00
playable = await RoyalPool.create()
2020-03-28 23:14:55 +00:00
else:
raise rc.InvalidInputError(f"Unknown playable '{playable_string.upper()}'")
await voice_player.change_playing(playable)
return {
"name": f"{playable.__class__.__qualname__}"
}