1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-23 11:34:18 +00:00

new stuff

This commit is contained in:
Steffo 2019-12-13 02:48:16 +01:00
parent 999524d367
commit a188c1ca05
9 changed files with 94 additions and 25 deletions

View file

@ -32,12 +32,14 @@ class ApiKei(PageStar):
convid = form["convid"]
msg = form.get("message")
previous = form.get("previous")
first = form.get("first", False)
person = await asyncify(session.query(self.alchemy.get(KeiPerson)).filter_by(kpid=kpid).one_or_none)
if person is None:
person = self.alchemy.get(KeiPerson)(kpid=kpid)
session.add(person)
first = True
else:
first = False
message = self.alchemy.get(KeiMessage)(kei_person=person, message=msg, previous=previous)
session.add(message)
await asyncify(session.commit)
@ -45,12 +47,15 @@ class ApiKei(PageStar):
while True:
if convid not in self._conversations:
# Create a new conversation
self._conversations[convid] = await ExampleConversation.create(self.interface)
if first:
self._conversations[convid] = await FirstConversation.create(self.interface)
else:
self._conversations[convid] = await MainConversation.create(self.interface)
log.info(f"[{convid}] SYSTEM: New conversation created - {self._conversations[convid]}")
conv: Conversation = self._conversations[convid]
try:
log.info(f"[{convid}] {person}: '{message}'")
log.info(f"[{convid}] {person}: '{message.message}'")
except Exception:
pass
try:
@ -63,7 +68,7 @@ class ApiKei(PageStar):
continue
except Exception as e:
log.error(f"[{convid}] ERROR: {e}")
emotion, text = Emotion.NEUTRAL, "...?"
emotion, text = Emotion.QUESTION, "...?"
del self._conversations[convid]
break
else:

View file

@ -1,6 +1,6 @@
from typing import *
from sqlalchemy import *
from sqlalchemy.orm import relationship
from sqlalchemy.orm import relationship, backref
from sqlalchemy.ext.declarative import declared_attr
@ -21,7 +21,8 @@ class KeiMessage:
@declared_attr
def kei_person(self) -> "KeiPerson":
return relationship("KeiPerson", foreign_keys=self.kei_person_id, backref="kei_messages")
return relationship("KeiPerson", foreign_keys=self.kei_person_id, backref=backref("kei_messages",
cascade="all, delete-orphan"))
@declared_attr
def previous(self) -> Optional[str]:

View file

@ -19,7 +19,7 @@ class KeiPerson:
return Column(Integer, ForeignKey("users.uid"))
@declared_attr
def user(self) -> Optional[User]:
def user(self) -> Optional["User"]:
return relationship("User", foreign_keys=self.user_id, backref="kei_people")
@declared_attr

View file

@ -1,10 +1,12 @@
from .emotion import Emotion
from .conversation import Conversation, ExampleConversation
from .conversation import Conversation, ExampleConversation, FirstConversation, MainConversation
from .anyinstring import any_in_string
__all__ = [
"Emotion",
"Conversation",
"ExampleConversation",
"FirstConversation",
"MainConversation",
"any_in_string",
]

View file

@ -2,7 +2,7 @@ from typing import *
import re
def any_in_string(patterns: List[str], string: str) -> bool:
def any_in_string(patterns: Collection[str], string: str) -> bool:
for pattern in patterns:
if re.search(pattern, string):
return True

View file

@ -1,10 +1,11 @@
import re
import random
from typing import *
from royalnet.commands import CommandInterface
from royalnet.utils import *
from .emotion import Emotion
from ..tables import KeiPerson, KeiMessage
from ..utils import any_in_string
from ..utils.anyinstring import any_in_string
class Conversation:
@ -53,10 +54,10 @@ class ExampleConversation(Conversation):
class FirstConversation(Conversation):
async def _generator(self):
yield
yield Emotion.NEUTRAL, "Ciao!"
yield Emotion.QUESTION, "Come sei arrivato qui...?"
yield Emotion.HAPPY, "Capisco... Ad ogni modo, sono Kei! Tu come ti chiami?"
yield NameConversation.create(self.interface)
yield Emotion.HAPPY, "Ciao!"
yield Emotion.HAPPY, "Come hai trovato questo posto?"
yield Emotion.HAPPY, "Capisco... Ad ogni modo, io sono Kei! Tu come ti chiami?"
yield await NameConversation.create(self.interface)
class NameConversation(Conversation):
@ -77,35 +78,94 @@ class NameConversation(Conversation):
continue
self._person.name = name
await asyncify(self._session.commit())
await asyncify(self._session.commit)
break
yield Emotion.GRIN, f"O-kei! {self._person.name}!"
yield Emotion.HAPPY, "Saro' sempre a tua disposizione quando mi vorrai dire qualcosa!"
yield Emotion.QUESTION, "Pero' prima ti vorrei chiedere un favore..."
yield Emotion.HAPPY, "Pero' prima ti vorrei chiedere un favore..."
yield Emotion.NEUTRAL, "Qualcuno ha criptato con delle password tutti i miei file...\n" \
"Se ne trovi qualcuna in giro, potresti dirmela?\n"
while True:
if self._message.message == "no":
yield Emotion.CRY, "Non farmi questo... Per piacere, accetta!"
yield Emotion.CRY, "Non puoi farmi questo... Per piacere, accetta!"
else:
break
yield Emotion.HAPPY, "Grazie! Prometto che quando riavro' tutto ti ricompensero' adeguatamente!"
yield Emotion.HAPPY, "Grazie! Ti prometto che quando riavro' tutti i miei file ti ricompensero' adeguatamente!"
class StartConversation(Conversation):
async def _generator(self):
yield
yield Emotion.HAPPY, "Di cosa vuoi parlare?"
yield MainConversation.create(self.interface)
class MainConversation(Conversation):
async def _generator(self):
yield
yield Emotion.HAPPY, "Di cosa vuoi parlare?"
while True:
msg = self._message.message
if any_in_string([r"gatt[oiae]", "ny[ae]+", "mi+a+o+", "me+o+w+", "felin[oi]", "mici[ao]"], msg):
yield Emotion.CAT, "Nyan!"
def anym(*args) -> bool:
return any_in_string(args, msg)
if anym(r"passwords?"):
yield PasswordConversation.create(self.interface)
elif anym(r"[aeou]w[aeou]"):
yield Emotion.CAT, random.sample([
"OwO",
"UwU",
":3",
"owo",
"uwu",
"ewe",
"awa",
], 1)[0]
elif anym(r"gatt[oiae]", "ny[ae]+", "mi+a+o+", "me+o+w+", "felin[oi]", "mici[ao]", "ma+o+"):
yield Emotion.CAT, random.sample([
"Nyan!",
"Miao!",
"Meow!",
"Nyaaaa...",
"Nya?",
"Mao!",
"*purr*",
], 1)[0]
elif anym(r"can[ei]",
r"dog(?:g(?:hi|os?)|s)?",
r"corgis?",
r"cagnolin[oiae]",
r"wo+f+",
r"b[ao]+r+k+",
r"ba+u+"):
yield Emotion.CAT, random.sample([
"Woof!",
"Bark!",
"Bork!",
"*arf* *arf*",
])
else:
yield Emotion.QUESTION, "...?"
yield Emotion.WORRIED, "Scusa... Non conosco molte cose... Ho bisogno di più password!"
class PasswordConversation(Conversation):
async def _generator(self):
yield
yield Emotion.SURPRISED, "Hai trovato una password? O-kei, dimmi!"
if False:
...
else:
yield Emotion.NEUTRAL, "No, non ha funzionato."
yield MainConversation.create(self.interface)

View file

@ -1 +0,0 @@
semantic = "0.3"

View file

@ -2,7 +2,7 @@
[tool.poetry]
name = "keipack"
version = "0.3"
version = "0.3.7"
description = "A mysterious AI assistant"
authors = ["Stefano Pigozzi <ste.pigozzi@gmail.com>"]
license = "AGPL-3.0+"

2
send.bat Normal file
View file

@ -0,0 +1,2 @@
scp -i "D:\Chiavi e robe\Terza.pem" "dist/*" "root@ryg.steffo.eu:"
ssh -i "D:\Chiavi e robe\Terza.pem" "root@ryg.steffo.eu"