mirror of
https://github.com/RYGhub/royalnet.git
synced 2024-11-23 03:24:20 +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 re
|
||||
import asyncio
|
||||
|
||||
from . import teleporter
|
||||
from . import bullet
|
||||
|
@ -95,8 +96,12 @@ class Command:
|
|||
"""
|
||||
A conversation which runs the command.
|
||||
"""
|
||||
log.debug(f"Waiting for a message...")
|
||||
msg = await (_sentry | wrench.Type(bullet.Message))
|
||||
log.debug(f"Getting a message from the queue...")
|
||||
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}...")
|
||||
text = await msg.text()
|
||||
|
|
|
@ -30,7 +30,7 @@ class Sentry(metaclass=abc.ABCMeta):
|
|||
raise NotImplementedError()
|
||||
|
||||
@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.
|
||||
|
||||
|
@ -42,7 +42,7 @@ class Sentry(metaclass=abc.ABCMeta):
|
|||
raise NotImplementedError()
|
||||
|
||||
@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
|
||||
without handling discards.
|
||||
|
@ -53,7 +53,7 @@ class Sentry(metaclass=abc.ABCMeta):
|
|||
"""
|
||||
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
|
||||
discarded.
|
||||
|
@ -143,10 +143,10 @@ class SentryFilter(Sentry):
|
|||
def __len__(self) -> int:
|
||||
return len(self.previous) + 1
|
||||
|
||||
def get_nowait(self) -> bullet.Bullet:
|
||||
def get_nowait(self):
|
||||
return self.previous.get_nowait()
|
||||
|
||||
async def get(self) -> bullet.Bullet:
|
||||
async def get(self):
|
||||
return await self.previous.get()
|
||||
|
||||
async def put(self, item) -> None:
|
||||
|
@ -168,10 +168,10 @@ class SentrySource(Sentry):
|
|||
def __len__(self) -> int:
|
||||
return 1
|
||||
|
||||
def get_nowait(self) -> bullet.Bullet:
|
||||
def get_nowait(self):
|
||||
return self.queue.get_nowait()
|
||||
|
||||
async def get(self) -> bullet.Bullet:
|
||||
async def get(self):
|
||||
return await self.queue.get()
|
||||
|
||||
async def put(self, item) -> None:
|
||||
|
|
Loading…
Reference in a new issue