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,
|
|
|
|
})
|