1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-23 19:44:20 +00:00
royalnet/keipack/utils/conversation.py

44 lines
1.3 KiB
Python
Raw Normal View History

2019-12-09 23:39:33 +00:00
from royalnet.commands import CommandInterface
2019-12-09 01:22:29 +00:00
from .emotion import Emotion
2019-12-09 23:39:33 +00:00
2019-12-09 01:22:29 +00:00
class Conversation:
2019-12-09 23:39:33 +00:00
def __init__(self, interface: CommandInterface):
2019-12-09 01:22:29 +00:00
self.generator = self._generator()
2019-12-09 23:39:33 +00:00
self.interface: CommandInterface = interface
self._person = None
self._session = None
self._message = None
2019-12-09 01:22:29 +00:00
async def _generator(self):
yield
raise NotImplementedError()
@classmethod
2019-12-09 23:39:33 +00:00
async def create(cls, interface: CommandInterface):
conv = cls(interface=interface)
2019-12-09 01:22:29 +00:00
await conv.generator.asend(None)
return conv
async def next(self, session, person, message):
2019-12-09 23:39:33 +00:00
self._session = session
self._person = person
self._message = message
reply = await self.generator.asend(None)
2019-12-09 01:22:29 +00:00
return reply
# noinspection PyTupleAssignmentBalance
class ExampleConversation(Conversation):
async def _generator(self):
2019-12-09 23:39:33 +00:00
yield
yield Emotion.HAPPY, "Ciao!"
response = await self.interface.call_herald_event("discord", "discord_cv")
yield Emotion.SURPRISED, f"Ci sono {len(response['guild']['members'])} persone in RYG."
yield Emotion.NEUTRAL, "Questa è una conversazione di prova."
yield await ExampleConversation.create(self.interface)
yield Emotion.WORRIED, "Questo non dovrebbe mai venire fuori."