mirror of
https://github.com/RYGhub/royalnet.git
synced 2024-11-23 11:34:18 +00:00
💥 Change command behaviour and sentry type annotations
This commit is contained in:
parent
69f817c188
commit
ab16467844
2 changed files with 14 additions and 9 deletions
|
@ -7,6 +7,7 @@ import royalnet.royaltyping as t
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
import re
|
import re
|
||||||
|
import asyncio
|
||||||
|
|
||||||
from . import teleporter
|
from . import teleporter
|
||||||
from . import bullet
|
from . import bullet
|
||||||
|
@ -95,8 +96,12 @@ class Command:
|
||||||
"""
|
"""
|
||||||
A conversation which runs the command.
|
A conversation which runs the command.
|
||||||
"""
|
"""
|
||||||
log.debug(f"Waiting for a message...")
|
log.debug(f"Getting a message from the queue...")
|
||||||
msg = await (_sentry | wrench.Type(bullet.Message))
|
try:
|
||||||
|
msg: bullet.Message = (_sentry | wrench.Type(bullet.Message)).get_nowait()
|
||||||
|
except asyncio.QueueEmpty:
|
||||||
|
log.debug(f"No message found in the queue, returning...")
|
||||||
|
return
|
||||||
|
|
||||||
log.debug(f"Getting text of {msg}...")
|
log.debug(f"Getting text of {msg}...")
|
||||||
text = await msg.text()
|
text = await msg.text()
|
||||||
|
|
|
@ -30,7 +30,7 @@ class Sentry(metaclass=abc.ABCMeta):
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
@abc.abstractmethod
|
@abc.abstractmethod
|
||||||
def get_nowait(self) -> bullet.Bullet:
|
def get_nowait(self):
|
||||||
"""
|
"""
|
||||||
Try to get a single :class:`~.bullet.Bullet` from the pipeline, without blocking or handling discards.
|
Try to get a single :class:`~.bullet.Bullet` from the pipeline, without blocking or handling discards.
|
||||||
|
|
||||||
|
@ -42,7 +42,7 @@ class Sentry(metaclass=abc.ABCMeta):
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
@abc.abstractmethod
|
@abc.abstractmethod
|
||||||
async def get(self) -> bullet.Bullet:
|
async def get(self):
|
||||||
"""
|
"""
|
||||||
Try to get a single :class:`~.bullet.Bullet` from the pipeline, blocking until something is available, but
|
Try to get a single :class:`~.bullet.Bullet` from the pipeline, blocking until something is available, but
|
||||||
without handling discards.
|
without handling discards.
|
||||||
|
@ -53,7 +53,7 @@ class Sentry(metaclass=abc.ABCMeta):
|
||||||
"""
|
"""
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
async def wait(self) -> bullet.Bullet:
|
async def wait(self):
|
||||||
"""
|
"""
|
||||||
Try to get a single :class:`~.bullet.Bullet` from the pipeline, blocking until something is available and is not
|
Try to get a single :class:`~.bullet.Bullet` from the pipeline, blocking until something is available and is not
|
||||||
discarded.
|
discarded.
|
||||||
|
@ -143,10 +143,10 @@ class SentryFilter(Sentry):
|
||||||
def __len__(self) -> int:
|
def __len__(self) -> int:
|
||||||
return len(self.previous) + 1
|
return len(self.previous) + 1
|
||||||
|
|
||||||
def get_nowait(self) -> bullet.Bullet:
|
def get_nowait(self):
|
||||||
return self.previous.get_nowait()
|
return self.previous.get_nowait()
|
||||||
|
|
||||||
async def get(self) -> bullet.Bullet:
|
async def get(self):
|
||||||
return await self.previous.get()
|
return await self.previous.get()
|
||||||
|
|
||||||
async def put(self, item) -> None:
|
async def put(self, item) -> None:
|
||||||
|
@ -168,10 +168,10 @@ class SentrySource(Sentry):
|
||||||
def __len__(self) -> int:
|
def __len__(self) -> int:
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
def get_nowait(self) -> bullet.Bullet:
|
def get_nowait(self):
|
||||||
return self.queue.get_nowait()
|
return self.queue.get_nowait()
|
||||||
|
|
||||||
async def get(self) -> bullet.Bullet:
|
async def get(self):
|
||||||
return await self.queue.get()
|
return await self.queue.get()
|
||||||
|
|
||||||
async def put(self, item) -> None:
|
async def put(self, item) -> None:
|
||||||
|
|
Loading…
Reference in a new issue