1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-27 21:44:21 +00:00
royalnet/keipack/stars/api_kei.py

32 lines
1,012 B
Python
Raw Normal View History

2019-11-29 20:18:01 +00:00
import random
import datetime
from typing import *
2019-11-11 12:40:26 +00:00
from starlette.requests import Request
from starlette.responses import *
2019-11-29 20:18:01 +00:00
from royalnet.constellation import *
2019-11-11 12:40:26 +00:00
from royalnet.utils import *
class ApiKei(PageStar):
path = "/api/kei"
2019-11-29 20:18:01 +00:00
async def _generate(self, request, session) -> Tuple[str, str]:
if request.query_params.get("first", "false") == "true":
return random.sample([
("happy", "Ciao!"),
("question", "Come va?"),
("happy", "Sono al tuo servizio!"),
("happy", "Attendo ordini!"),
("happy", "Attendo ordini!"),
("cat", "Mandami un messaggio :3"),
], 1)[0]
return "x", "MISSINGNO."
2019-11-11 12:40:26 +00:00
async def page(self, request: Request) -> JSONResponse:
async with self.session_acm() as session:
emotion, text = await self._generate(request, session)
return JSONResponse({
"emotion": emotion,
"text": text,
})