mirror of
https://github.com/RYGhub/royalnet.git
synced 2024-11-23 19:44:20 +00:00
5.0a62: Fix everything that broke
This commit is contained in:
parent
e3770adda8
commit
e9a5d3450c
5 changed files with 27 additions and 18 deletions
|
@ -13,6 +13,10 @@ class YtdlDiscord:
|
||||||
self.pcm_filename: typing.Optional[str] = None
|
self.pcm_filename: typing.Optional[str] = None
|
||||||
self._fas_spawned: typing.List[FileAudioSource] = []
|
self._fas_spawned: typing.List[FileAudioSource] = []
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
return f"<{self.__class__.__name__} {self.info.title or 'Unknown Title'} ({'ready' if self.pcm_available() else 'not ready'}," \
|
||||||
|
f" {len(self._fas_spawned)} audiosources spawned)>"
|
||||||
|
|
||||||
def pcm_available(self):
|
def pcm_available(self):
|
||||||
return self.pcm_filename is not None and os.path.exists(self.pcm_filename)
|
return self.pcm_filename is not None and os.path.exists(self.pcm_filename)
|
||||||
|
|
||||||
|
@ -24,7 +28,7 @@ class YtdlDiscord:
|
||||||
ffmpeg.input(self.ytdl_file.filename)
|
ffmpeg.input(self.ytdl_file.filename)
|
||||||
.output(destination_filename, format="s16le", ac=2, ar="48000")
|
.output(destination_filename, format="s16le", ac=2, ar="48000")
|
||||||
.overwrite_output()
|
.overwrite_output()
|
||||||
.run_async(quiet=True)
|
.run(quiet=True)
|
||||||
)
|
)
|
||||||
self.pcm_filename = destination_filename
|
self.pcm_filename = destination_filename
|
||||||
|
|
||||||
|
|
|
@ -217,7 +217,7 @@ class DiscordBot(GenericBot):
|
||||||
guild_music_data = self.music_data[guild]
|
guild_music_data = self.music_data[guild]
|
||||||
for dfile in dfiles:
|
for dfile in dfiles:
|
||||||
log.debug(f"Adding {dfile} to music_data")
|
log.debug(f"Adding {dfile} to music_data")
|
||||||
dfile.ready_up()
|
await asyncify(dfile.ready_up)
|
||||||
guild_music_data.add(dfile)
|
guild_music_data.add(dfile)
|
||||||
if guild_music_data.now_playing is None:
|
if guild_music_data.now_playing is None:
|
||||||
await self.advance_music_data(guild)
|
await self.advance_music_data(guild)
|
||||||
|
|
|
@ -89,6 +89,16 @@ class NetworkLink:
|
||||||
self.connect_event: asyncio.Event = asyncio.Event(loop=self._loop)
|
self.connect_event: asyncio.Event = asyncio.Event(loop=self._loop)
|
||||||
self.identify_event: asyncio.Event = asyncio.Event(loop=self._loop)
|
self.identify_event: asyncio.Event = asyncio.Event(loop=self._loop)
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
if self.identify_event.is_set():
|
||||||
|
return f"<{self.__class__.__name__} (identified)>"
|
||||||
|
elif self.connect_event.is_set():
|
||||||
|
return f"<{self.__class__.__name__} (connected)>"
|
||||||
|
elif self.error_event.is_set():
|
||||||
|
return f"<{self.__class__.__name__} (error)>"
|
||||||
|
else:
|
||||||
|
return f"<{self.__class__.__name__} (disconnected)>"
|
||||||
|
|
||||||
async def connect(self):
|
async def connect(self):
|
||||||
"""Connect to the :py:class:`royalnet.network.NetworkServer` at ``self.master_uri``."""
|
"""Connect to the :py:class:`royalnet.network.NetworkServer` at ``self.master_uri``."""
|
||||||
log.info(f"Connecting to {self.master_uri}...")
|
log.info(f"Connecting to {self.master_uri}...")
|
||||||
|
@ -149,13 +159,12 @@ class NetworkLink:
|
||||||
log.debug(f"Received response: {request} -> {response}")
|
log.debug(f"Received response: {request} -> {response}")
|
||||||
return response
|
return response
|
||||||
|
|
||||||
async def run(self, loops: numbers.Real = math.inf):
|
async def run(self):
|
||||||
"""Blockingly run the Link."""
|
"""Blockingly run the Link."""
|
||||||
log.debug(f"Running main client loop for {self.nid}.")
|
log.debug(f"Running main client loop for {self.nid}.")
|
||||||
if self.error_event.is_set():
|
if self.error_event.is_set():
|
||||||
raise ConnectionClosedError("RoyalnetLinks can't be rerun after an error.")
|
raise ConnectionClosedError("RoyalnetLinks can't be rerun after an error.")
|
||||||
while loops:
|
while True:
|
||||||
loops -= 1
|
|
||||||
if not self.connect_event.is_set():
|
if not self.connect_event.is_set():
|
||||||
await self.connect()
|
await self.connect()
|
||||||
if not self.identify_event.is_set():
|
if not self.identify_event.is_set():
|
||||||
|
|
|
@ -125,17 +125,13 @@ class NetworkServer:
|
||||||
destination_conv_id=package.destination_conv_id)
|
destination_conv_id=package.destination_conv_id)
|
||||||
await destination.send(specific_package)
|
await destination.send(specific_package)
|
||||||
|
|
||||||
async def serve(self):
|
def serve(self):
|
||||||
log.debug(f"Serving on ws://{self.address}:{self.port}")
|
log.debug(f"Serving on ws://{self.address}:{self.port}")
|
||||||
await websockets.serve(self.listener, host=self.address, port=self.port, loop=self.loop)
|
server = self.loop.run_until_complete(websockets.serve(self.listener,
|
||||||
log.debug(f"Serve has finished?!")
|
host=self.address,
|
||||||
|
port=self.port,
|
||||||
async def run(self):
|
loop=self.loop))
|
||||||
if self.loop is None:
|
self.loop.run_forever()
|
||||||
self.loop = asyncio.get_event_loop()
|
|
||||||
log.debug(f"Starting main server loop on ws://{self.address}:{self.port}")
|
|
||||||
# noinspection PyAsyncCall
|
|
||||||
await self.serve()
|
|
||||||
|
|
||||||
def run_blocking(self, verbose=False):
|
def run_blocking(self, verbose=False):
|
||||||
if verbose:
|
if verbose:
|
||||||
|
@ -147,4 +143,4 @@ class NetworkServer:
|
||||||
core_logger.debug("Logging setup complete.")
|
core_logger.debug("Logging setup complete.")
|
||||||
if self.loop is None:
|
if self.loop is None:
|
||||||
self.loop = asyncio.get_event_loop()
|
self.loop = asyncio.get_event_loop()
|
||||||
self.loop.run_until_complete(self.run())
|
self.serve()
|
||||||
|
|
|
@ -41,8 +41,8 @@ def test_request_creation():
|
||||||
|
|
||||||
def test_links(async_loop: asyncio.AbstractEventLoop):
|
def test_links(async_loop: asyncio.AbstractEventLoop):
|
||||||
address, port = "127.0.0.1", 1235
|
address, port = "127.0.0.1", 1235
|
||||||
master = NetworkServer(address, port, "test")
|
master = NetworkServer(address, port, "test", loop=async_loop)
|
||||||
async_loop.run_until_complete(master.start())
|
run_server_task = async_loop.create_task(master.run())
|
||||||
# Test invalid secret
|
# Test invalid secret
|
||||||
wrong_secret_link = NetworkLink("ws://127.0.0.1:1235", "invalid", "test", echo_request_handler, loop=async_loop)
|
wrong_secret_link = NetworkLink("ws://127.0.0.1:1235", "invalid", "test", echo_request_handler, loop=async_loop)
|
||||||
with pytest.raises(ConnectionClosedError):
|
with pytest.raises(ConnectionClosedError):
|
||||||
|
|
Loading…
Reference in a new issue