mirror of
https://github.com/RYGhub/royalnet.git
synced 2024-12-17 23:24:20 +00:00
Final touches
This commit is contained in:
parent
d82b824a34
commit
34302754d5
3 changed files with 4 additions and 50 deletions
|
@ -5,13 +5,11 @@ It is pretty unstable, compared to the rest of the bot, but it *should* work."""
|
||||||
from .escape import escape
|
from .escape import escape
|
||||||
from .discordserf import DiscordSerf
|
from .discordserf import DiscordSerf
|
||||||
from .playable import Playable
|
from .playable import Playable
|
||||||
from .playableytdqueue import PlayableYTDQueue
|
|
||||||
from .voiceplayer import VoicePlayer
|
from .voiceplayer import VoicePlayer
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
"escape",
|
"escape",
|
||||||
"DiscordSerf",
|
"DiscordSerf",
|
||||||
"Playable",
|
"Playable",
|
||||||
"PlayableYTDQueue",
|
|
||||||
"VoicePlayer",
|
"VoicePlayer",
|
||||||
]
|
]
|
||||||
|
|
|
@ -1,46 +0,0 @@
|
||||||
import logging
|
|
||||||
from typing import Optional, List, AsyncGenerator, Tuple, Any, Dict
|
|
||||||
from royalnet.bard import YtdlDiscord
|
|
||||||
from .playable import Playable
|
|
||||||
try:
|
|
||||||
import discord
|
|
||||||
except ImportError:
|
|
||||||
discord = None
|
|
||||||
|
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
|
|
||||||
class PlayableYTDQueue(Playable):
|
|
||||||
"""A queue of :class:`YtdlDiscord` to be played in sequence."""
|
|
||||||
def __init__(self, start_with: Optional[List[YtdlDiscord]] = None):
|
|
||||||
super().__init__()
|
|
||||||
self.contents: List[YtdlDiscord] = []
|
|
||||||
self.now_playing: Optional[YtdlDiscord] = None
|
|
||||||
if start_with is not None:
|
|
||||||
self.contents = [*self.contents, *start_with]
|
|
||||||
log.debug(f"Created new PlayableYTDQueue containing: {self.contents}")
|
|
||||||
|
|
||||||
async def _generator(self) \
|
|
||||||
-> AsyncGenerator[Optional["discord.AudioSource"], Tuple[Tuple[Any, ...], Dict[str, Any]]]:
|
|
||||||
yield
|
|
||||||
while True:
|
|
||||||
log.debug(f"Dequeuing an item...")
|
|
||||||
try:
|
|
||||||
# Try to get the first YtdlDiscord of the queue
|
|
||||||
self.now_playing: YtdlDiscord = self.contents.pop(0)
|
|
||||||
except IndexError:
|
|
||||||
# If there isn't anything, yield None
|
|
||||||
log.debug(f"Nothing to dequeue, yielding None.")
|
|
||||||
yield None
|
|
||||||
continue
|
|
||||||
log.debug(f"Yielding FileAudioSource from: {self.now_playing}")
|
|
||||||
# Create a FileAudioSource from the YtdlDiscord
|
|
||||||
# If the file hasn't been fetched / downloaded / converted yet, it will do so before yielding
|
|
||||||
async with self.now_playing.spawn_audiosource() as fas:
|
|
||||||
# Yield the resulting AudioSource
|
|
||||||
yield fas
|
|
||||||
# Delete the YtdlDiscord file
|
|
||||||
log.debug(f"Deleting: {self.now_playing}")
|
|
||||||
await self.now_playing.delete_asap()
|
|
||||||
log.debug(f"Deleted successfully!")
|
|
|
@ -182,10 +182,12 @@ class Serf:
|
||||||
raise ExternalError(response.extra_info["message"])
|
raise ExternalError(response.extra_info["message"])
|
||||||
else:
|
else:
|
||||||
raise ProgramError(f"Invalid error in Herald event '{event_name}':\n"
|
raise ProgramError(f"Invalid error in Herald event '{event_name}':\n"
|
||||||
f"[p]{response}[/p]")
|
f"[b]{response.extra_info['type']}[/b]\n"
|
||||||
|
f"{response.extra_info['message']}")
|
||||||
elif response.name == "unhandled_exception_in_event":
|
elif response.name == "unhandled_exception_in_event":
|
||||||
raise ProgramError(f"Unhandled exception in Herald event '{event_name}':\n"
|
raise ProgramError(f"Unhandled exception in Herald event '{event_name}':\n"
|
||||||
f"[p]{response}[/p]")
|
f"[b]{response.extra_info['type']}[/b]\n"
|
||||||
|
f"{response.extra_info['message']}")
|
||||||
elif isinstance(response, rh.ResponseSuccess):
|
elif isinstance(response, rh.ResponseSuccess):
|
||||||
return response.data
|
return response.data
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in a new issue