1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-22 19:14:20 +00:00

Create conversation module

This commit is contained in:
Steffo 2020-12-30 14:59:37 +01:00
parent 1b8c721cc2
commit 6faf278eb3
5 changed files with 61 additions and 12 deletions

View file

@ -1 +1 @@
<mxfile host="Electron" modified="2020-12-27T10:33:23.298Z" agent="5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) draw.io/13.9.9 Chrome/85.0.4183.121 Electron/10.1.5 Safari/537.36" etag="JEjZWtflLNvLgdL41tIv" version="13.9.9" type="device"><diagram id="CE8n8ZrOl62DmRSVWgVr" name="Page-1">7VvbcqM4EP0aP2bLxtc8jnGcvWRqZ52ZzWbeZJBBiZBcQvgyXz8tIRkIjIN3Yw+ppSpJSU2rdenWOWpBOn032t0KtA4/ch/TjtP1d53+rOM440kP/irBPhUMrgepIBDET0W9THBPvmEj7BppQnwcFxQl51SSdVHoccawJwsyJATfFtVWnBZ7XaMAlwT3HqJl6QPxZZhKJ8NuJv8VkyC0Pfe65kmErLIRxCHy+TYn6t90+q7gXKalaOdiqtbOrkvabv6Dp4eBCcxknQbia7JYkMVfU+fPh+U4+EynH8Kr3tAMTu7tjLEPC2CqXMiQB5whepNJpzCTtXpKCXuGquAJ87HqpQu1rMkd52sQ9kD4hKXcG+eiRHIQhTKi5ineEfmPav7L0NQejTFVnu3ylb2tMCn2uUaq+mjtqUrWTNdsu/KqmYWMeSI8fGypTPQhEWB5TM9JFdU65nowTrnFPMIwIFAQmCJJNsVAQyZeg4Ne5lIoGK+e4uHU7gbRxPT0AHP3wpLf4y2JKGLKwSvOpA0BtWheSKh/h/Y8UROPJfKebW0ackG+gT6y3oTHQhpfO6OCxr1qaWwKHIPOJ+uI3gvRR7QrKN6hWNrRcErROiZLPT7VMAKfEDblUvLIKCFKAgZlD2xhYeeUjqo3UHVCqcspF3r2fdedz133WIBssJB4d9Sj5mnfbnmDeaOJqW8zBHEsToQ59LB6VUFgelsAyCEWwNRP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78bUPN+u9tCTe2ocBPZknVtsj6y/Y4C4/vh6kmDuNqWHwu8/RpXF5g6I+63T6grPjQ/BiZn52qoZv+lkCJh9q8e/Zvv</diagram></mxfile>
<mxfile host="Electron" modified="2020-12-30T12:59:53.921Z" agent="5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) draw.io/13.9.9 Chrome/85.0.4183.121 Electron/10.1.5 Safari/537.36" etag="RuLkLSMH5iLDTAz1iPYz" version="13.9.9" type="device"><diagram id="CE8n8ZrOl62DmRSVWgVr" name="Page-1">7RvZcuMo8Gv8mC1b8jWPsZ1kj0xtNpnZ7OwblrBEgkCLUBzP12+DQIclH5lJbGdGVSlHtKBp6LtBHXcaPV8JFIcfuY9px+n6zx131nGcnuO68E9BVhlkNB5ngEAQ33QqAHfkKzbAroGmxMdJpaPknEoSV4EeZwx7sgJDQvBltduC0+qsMQpwDXDnIVqH3hNfhhl0POgW8F8xCUI7c69r3kTIdjaAJEQ+X5ZA7kXHnQrOZfYUPU8xVZtn9yUbd7nhbU6YwEzuM0D8m97ektu/Js6f9/NR8IlOzsMzg+UJ0dQs+B7weaEhWa7sPiRLElHEoDVZcCbvzJsutL2QUP8arXiq6Egk8h5taxJyQb5Cf0ThVQ8A8FpIw2ZnWOlxp0YanAIn0OfGLq63BvqInisdr1EiLTWcUhQnZK7pUwMjJALCJlxKHplOiJKAwbMHuLCwa8qo6vVVm1A65ZQLvXp3Or28nE4BXt90u4NYSPxcAhkmXGEeYSlW0MW8HViBMBox7Jv2spAvx0pRWJKtsYEhI9JBjjqf7RZUALEAlp5P565PN65PN26YDZhTmQ1R2CmGJJ7wlPlJWdTgobTQAqQF8AXC6NSE8TyOqdo6YAfMnmjlVz+hWuAd8EBv7H8phgEOTDqkSujmAp4CqflM+ZKwQKFImScJZzmSJSJSWwShVlkfm8TYIwviwdtHwnz4xxfqZ/6g7IxBkskPrEvWNAbEQaORgj9iK0uMaxVKYuQBWdd4oXa7X0BuDQMUiINMLag2GSH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xm+yiPXguK2dVA/dXuu228P2kE47TBiJ7BSJnv4dyJmZ/fH64QiPnPLz+fDk56+8ZbGaFtaMFm9+SMh49g3BOiKlHPYfeRmTJUU15FGl/0UZerxp5vWbltHfYyun6AVJT5fQI1/waBXqwT+T1GzCdggQAB/T1d2BGotbrWdnfMxQqnT6ZGCtWUmPv5ql1f1cQV8a/x7lVG4JtDMG2aN9Wu/iOIrAGS870kUAmLD+3Od8uDjU2N9jnjcY4N6o/82l+8xlDTSTPFZ0CxbH+qMejmbXMPhEqX7hehkR9I7du4Dyk8tc0yb9O0peqf1zz9l1S+5Jg8+2NGDSLTzEzASs+aHUv/gc=</diagram></mxfile>

View file

@ -10,10 +10,10 @@
.. automodule:: royalnet.engineer.bullet
``command``
``conversation``
-----------
.. automodule:: royalnet.engineer.command
.. automodule:: royalnet.engineer.conversation
``dispenser``

View file

@ -5,7 +5,7 @@ All names are inspired by the `Engineer Class of Team Fortress 2 <https://wiki.t
"""
from .bullet import *
from .command import *
from .conversation import *
from .discard import *
from .dispenser import *
from .exc import *

View file

@ -0,0 +1,57 @@
"""
Conversations are wrapper classes that can be applied to functions which await
:class:`~royalnet.engineer.bullet.Bullet`\\ s from a :class:`~royalnet.engineer.sentry.Sentry`.
"""
from __future__ import annotations
import royalnet.royaltyping as t
import logging
from . import sentry
log = logging.getLogger(__name__)
class ConversationProtocol(t.Protocol):
"""
Typing annotation for Conversation functions.
"""
def __call__(self, *, _sentry: sentry.Sentry, **kwargs) -> t.Awaitable[t.Optional[ConversationProtocol]]:
...
class Conversation:
"""
The base class for Conversations. It does nothing on its own except providing better debug information.
"""
def __init__(self, f: ConversationProtocol):
self.f: ConversationProtocol = f
@classmethod
def new(cls):
"""
A decorator that instantiates a new :class:`Conversation` object using the decorated function.
:return: The created :class:`Conversation` object.
It can still be called in the same way as the previous function!
"""
def decorator(f: ConversationProtocol):
c = cls(f=f)
log.debug(f"Created: {repr(c)}")
return decorator
def __call__(self, *, _sentry: sentry.Sentry, **kwargs) -> t.Awaitable[t.Optional[ConversationProtocol]]:
log.debug(f"Calling: {repr(self)}")
return self.f(_sentry=_sentry, **kwargs)
def __repr__(self):
return f"<Conversation #{id(self)}>"
__all__ = (
"ConversationProtocol",
"Conversation"
)

View file

@ -11,9 +11,6 @@ from typing import *
# noinspection PyUnresolvedReferences
from typing import IO, TextIO, BinaryIO
if TYPE_CHECKING:
from royalnet.engineer import Sentry
JSONScalar = Union[
None,
@ -77,8 +74,3 @@ An async generator yielding either:
* another :data:`.AsyncAdventure`;
* :data:`None`.
"""
class Conversation(Protocol):
def __call__(self, _sentry: "Sentry", **kwargs) -> Awaitable["Conversation"]:
...