|
|
@@ -1,9 +1,11 @@
|
|
|
#!/usr/bin/env python
|
|
|
# -*- coding: utf-8 -*-
|
|
|
+from importlib.resources import contents
|
|
|
from Stats import Stats
|
|
|
import configparser
|
|
|
-from Network import Network
|
|
|
-from Texts import ContentFile
|
|
|
+from lib.Network import Network
|
|
|
+from Jessi import ContentFile
|
|
|
+from Jessi import Contents
|
|
|
import datetime
|
|
|
import math
|
|
|
import json
|
|
|
@@ -30,9 +32,9 @@ class Text:
|
|
|
return Text.instance
|
|
|
|
|
|
def __init__(self):
|
|
|
- self.stats = Stats.getInstance()
|
|
|
+ self.stats:Stats = Stats.getInstance()
|
|
|
self.config = configparser.ConfigParser()
|
|
|
- self.config.read("config.ini")
|
|
|
+ self.config.read("config/config.ini")
|
|
|
self.replacer = list()
|
|
|
# TODO: Replacer.js laden, und alle 60-180 Sekunden eine List-Variable mit möglichen Antworten füllen / aktualisieren
|
|
|
# z.B. aus der Replacer.js "badwords" mit allen möglichen Antworten, abhängig der Requirements, in die Variable "replacer["badwords"][]" füllen
|
|
|
@@ -40,17 +42,17 @@ class Text:
|
|
|
self.readReplacer()
|
|
|
|
|
|
|
|
|
- def getText(self, intent, tags):
|
|
|
+ def getText(self, intent:str, tags) -> Contents:
|
|
|
if intent not in self.content:
|
|
|
- if os.path.isfile("text/"+intent+".json") == False:
|
|
|
+ if os.path.isfile("ressources/texts/"+intent+".json") == False:
|
|
|
print("Failed to load intent text: "+intent)
|
|
|
return ""
|
|
|
self.content[intent] = ContentFile.ContentFile(intent+".json")
|
|
|
return self.content[intent].getText(tags)
|
|
|
|
|
|
- def executeText(self, intent, tags):
|
|
|
+ def executeText(self, intent:str, tags) -> str:
|
|
|
if intent not in self.content:
|
|
|
- if os.path.isfile("text/"+intent+".json") == False:
|
|
|
+ if os.path.isfile("ressources/texts/"+intent+".json") == False:
|
|
|
print("Failed to load intent text: "+intent)
|
|
|
return ""
|
|
|
self.content[intent] = ContentFile.ContentFile(intent+".json")
|
|
|
@@ -113,7 +115,7 @@ class Text:
|
|
|
deadcounter+=1
|
|
|
if deadcounter > 40:
|
|
|
break
|
|
|
- print("Eexit Replacer Loop")
|
|
|
+ print("Exit Replacer Loop")
|
|
|
return text
|
|
|
|
|
|
def _formatText_DateTime(self,text:str,dt:datetime.datetime,name:str):
|
|
|
@@ -140,7 +142,7 @@ class Text:
|
|
|
|
|
|
def readReplacer(self):
|
|
|
tmp = {}
|
|
|
- with open("text/Replacer.json") as json_file:
|
|
|
+ with open("ressources/texts/Replacer.json") as json_file:
|
|
|
data = json.load(json_file)
|
|
|
for k in data:
|
|
|
tmp[k] = list()
|
|
|
@@ -151,10 +153,10 @@ class Text:
|
|
|
"freezy","funny","happyness","hot","humanity","hungry","intelligent","irritated","lonely","naiv",
|
|
|
"playful","sad","shy","sleepy","soziality","temperate","toLoud","toQuiet","usefull","useless"]
|
|
|
for sk in statKeys:
|
|
|
- if sk+"_max" in i["mood_required"] and i["mood_required"][sk+"_max"] <= getattr(self.stats.deviceStats,sk):
|
|
|
+ if sk+"_max" in i["mood_required"] and i["mood_required"][sk+"_max"] <= getattr(self.stats.DeviceStats,sk):
|
|
|
add = False
|
|
|
break
|
|
|
- if sk+"_min" in i["mood_required"] and i["mood_required"][sk+"_min"] >= getattr(self.stats.deviceStats,sk):
|
|
|
+ if sk+"_min" in i["mood_required"] and i["mood_required"][sk+"_min"] >= getattr(self.stats.DeviceStats,sk):
|
|
|
add = False
|
|
|
break
|
|
|
if add == True and "text" in i:
|