mirror of
https://github.com/RYGhub/royalnet.git
synced 2024-11-23 19:44:20 +00:00
yes
This commit is contained in:
parent
3feca93486
commit
e11fd430d1
5 changed files with 18 additions and 8 deletions
|
@ -1,6 +1,7 @@
|
|||
from .createrichembed import create_rich_embed
|
||||
from .escape import escape
|
||||
from .discordserf import DiscordSerf
|
||||
from .fileaudiosource import FileAudioSource
|
||||
from . import discordbard
|
||||
|
||||
__all__ = [
|
||||
|
@ -8,4 +9,5 @@ __all__ = [
|
|||
"escape",
|
||||
"DiscordSerf",
|
||||
"discordbard",
|
||||
"FileAudioSource",
|
||||
]
|
||||
|
|
|
@ -52,6 +52,9 @@ class DiscordBard:
|
|||
self.now_playing = fas
|
||||
return fas
|
||||
|
||||
async def cut(self):
|
||||
"""Immediatly end the playback of the current file"""
|
||||
|
||||
async def add(self, ytd: YtdlDiscord) -> None:
|
||||
"""Add a new :class:`YtdlDiscord` to the :class:`DiscordBard`, if possible.
|
||||
|
||||
|
|
|
@ -248,3 +248,6 @@ class DiscordSerf(Serf):
|
|||
raise CommandError("The bot is already connected in another channel.\n"
|
||||
" Please disconnect it before resummoning!")
|
||||
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."""
|
||||
|
|
|
@ -1,6 +1,3 @@
|
|||
from typing import Optional
|
||||
from .ytdlinfo import YtdlInfo
|
||||
|
||||
try:
|
||||
import discord
|
||||
except ImportError:
|
||||
|
@ -21,6 +18,7 @@ class FileAudioSource(discord.AudioSource):
|
|||
Arguments:
|
||||
file: the file to be played back."""
|
||||
self.file = file
|
||||
self._stopped = False
|
||||
|
||||
def __repr__(self):
|
||||
if self.file.seekable():
|
||||
|
@ -35,13 +33,18 @@ class FileAudioSource(discord.AudioSource):
|
|||
``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):
|
||||
"""Reads 20ms worth of audio.
|
||||
"""Reads 20ms of audio.
|
||||
|
||||
If the stream has ended, then return an empty :py:class:`bytes`-like object."""
|
||||
data: bytes = self.file.read(discord.opus.Encoder.FRAME_SIZE)
|
||||
# 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 b""
|
||||
return data
|
|
@ -3,11 +3,10 @@ import re
|
|||
import os
|
||||
from contextlib import asynccontextmanager
|
||||
from royalnet.utils import asyncify, MultiLock
|
||||
from .ytdlinfo import YtdlInfo
|
||||
from .ytdlfile import YtdlFile
|
||||
from royalnet.bard import YtdlInfo, YtdlFile
|
||||
|
||||
try:
|
||||
from royalnet.bard.fileaudiosource import FileAudioSource
|
||||
from royalnet.serf.discord.fileaudiosource import FileAudioSource
|
||||
except ImportError:
|
||||
FileAudioSource = None
|
||||
|
Loading…
Reference in a new issue