1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-23 19:44:20 +00:00
This commit is contained in:
Steffo 2019-11-20 16:55:33 +01:00
parent 3feca93486
commit e11fd430d1
5 changed files with 18 additions and 8 deletions

View file

@ -1,6 +1,7 @@
from .createrichembed import create_rich_embed from .createrichembed import create_rich_embed
from .escape import escape from .escape import escape
from .discordserf import DiscordSerf from .discordserf import DiscordSerf
from .fileaudiosource import FileAudioSource
from . import discordbard from . import discordbard
__all__ = [ __all__ = [
@ -8,4 +9,5 @@ __all__ = [
"escape", "escape",
"DiscordSerf", "DiscordSerf",
"discordbard", "discordbard",
"FileAudioSource",
] ]

View file

@ -52,6 +52,9 @@ class DiscordBard:
self.now_playing = fas self.now_playing = fas
return fas return fas
async def cut(self):
"""Immediatly end the playback of the current file"""
async def add(self, ytd: YtdlDiscord) -> None: async def add(self, ytd: YtdlDiscord) -> None:
"""Add a new :class:`YtdlDiscord` to the :class:`DiscordBard`, if possible. """Add a new :class:`YtdlDiscord` to the :class:`DiscordBard`, if possible.

View file

@ -248,3 +248,6 @@ class DiscordSerf(Serf):
raise CommandError("The bot is already connected in another channel.\n" raise CommandError("The bot is already connected in another channel.\n"
" Please disconnect it before resummoning!") " Please disconnect it before resummoning!")
self.bards[channel.guild] = DBQueue(voice_client=voice_client) self.bards[channel.guild] = DBQueue(voice_client=voice_client)
async def voice_change(self, guild: "discord.Guild", bard: Type[DiscordBard]):
"""Safely change the :class:`DiscordBard` for a guild."""

View file

@ -1,6 +1,3 @@
from typing import Optional
from .ytdlinfo import YtdlInfo
try: try:
import discord import discord
except ImportError: except ImportError:
@ -21,6 +18,7 @@ class FileAudioSource(discord.AudioSource):
Arguments: Arguments:
file: the file to be played back.""" file: the file to be played back."""
self.file = file self.file = file
self._stopped = False
def __repr__(self): def __repr__(self):
if self.file.seekable(): if self.file.seekable():
@ -35,13 +33,18 @@ class FileAudioSource(discord.AudioSource):
``False``.""" ``False``."""
return False return False
def stop(self):
"""Stop the FileAudioSource. Once stopped, a FileAudioSource will immediatly stop reading more bytes from the
file."""
self._stopped = True
def read(self): def read(self):
"""Reads 20ms worth of audio. """Reads 20ms of audio.
If the stream has ended, then return an empty :py:class:`bytes`-like object.""" If the stream has ended, then return an empty :py:class:`bytes`-like object."""
data: bytes = self.file.read(discord.opus.Encoder.FRAME_SIZE) data: bytes = self.file.read(discord.opus.Encoder.FRAME_SIZE)
# If there is no more data to be streamed # If there is no more data to be streamed
if len(data) != discord.opus.Encoder.FRAME_SIZE: if self._stopped or len(data) != discord.opus.Encoder.FRAME_SIZE:
# Return that the stream has ended # Return that the stream has ended
return b"" return b""
return data return data

View file

@ -3,11 +3,10 @@ import re
import os import os
from contextlib import asynccontextmanager from contextlib import asynccontextmanager
from royalnet.utils import asyncify, MultiLock from royalnet.utils import asyncify, MultiLock
from .ytdlinfo import YtdlInfo from royalnet.bard import YtdlInfo, YtdlFile
from .ytdlfile import YtdlFile
try: try:
from royalnet.bard.fileaudiosource import FileAudioSource from royalnet.serf.discord.fileaudiosource import FileAudioSource
except ImportError: except ImportError:
FileAudioSource = None FileAudioSource = None