Warning: session_start(): open(/var/lib/php/sessions/sess_ooo2l7vav66i43vo9gpc4006i9, O_RDWR) failed: No space left on device (28) in /var/www/tb-usercake/models/config.php on line 51
Warning: session_start(): Failed to read session data: files (path: /var/lib/php/sessions) in /var/www/tb-usercake/models/config.php on line 51
!7
set flag DynModule.
sclass TelegramFactsBot > AbstractTelegramThinkBot {
bool debug;
bool imagineMode;
new LinkedHashSet imaginedFacts;
S evalExp(Exp e, NLLogicChecker_v2.Matching m) {
S code = nlLogic_text(e);
print("Eval'ing: " + code);
temp tempAdd(hotwire_copyOver_after, voidfunc(Class c) {
copyFields(mc(), c, 'telegram_msg_tl, 'telegram_recentHistory_tl)
});
S result = str(evalWithDollarVars(code, m.matches));
print("Result: " + shorten(result, 100));
ret result;
}
void thinkAbout(fS s) {
final Map msg = telegram_msg();
NLLogicChecker_v3 c = new NLLogicChecker_v3 {
L entities;
bool checkExpression(Exp e, Matching m) {
if (e instanceof Literal) {
// TEXT CONDITIONS
S text = nlLogic_text(e);
if (eq(text, "authorized"))
ret telegram_amIAuthorized();
else if(eq(text, "imagineMode"))
ret imagineMode;
}
ret super.checkExpression(e, m);
}
};
c.matcher = ai_standardMatcher();
c.input = s;
c.facts = imagineMode ? concatLists(imaginedFacts, mL_facts()) : mL_facts();
c.recentHistory = recentHistory;
LS unparsedRules = ai_unparsedTalkRules();
for (S listName : mL("Rule & Fact Lists"))
for (S x : splitAtEmptyLines(mL_raw(listName)))
if (anyJavaTokens(x))
if (nlLogic_parseRule(x) != null)
unparsedRules.add(x);
else
c.facts.add(x);
unparsedRules = sortedByCalculatedField(unparsedRules, func(S s) { jcontains(s, "entity(") });
L rules = map_pcall nlLogic_parseRule(unparsedRules);
for (S listName : mL("Default active scripts"))
addAll(rules, nlLogic_loadMechScript(listName));
nlLogic_expandMacros(rules);
final new L battleSpace;
applyNLLogicFacts_v4_verbose.set(debug);
applyNLLogicFacts_v4(c, voidfunc(IfThen rule, NLLogicChecker_v2.Matching m) {
// Rule fired!
battleSpace.add(new RuleWithParams(rule, m.matches));
}, rules);
print("Have " + n2(battleSpace, "possible rule"));
nlLogic_battleItOut(battleSpace);
fS msgGlobalID = getString(msg, 'globalID);
print("msgGlobalID=" + msgGlobalID);
for (RuleWithParams r : battleSpace) {
print("Firing rule " + r.rule.globalID);
// Save rule fire
if (nempty(msgGlobalID) && nempty(r.rule.globalID)) {
S fact = format("Rule * fired on message * at *", r.rule.globalID, msgGlobalID, localDateWithMilliseconds());
if (nempty(r.matches))
fact += " with vars " + dropPrefix("lhm", struct(r.matches));
print(addToMechList("Telegram Rule Fires", print(fact)));
}
// Execute rule
for (Exp e : nlLogic_unrollAnd(r.rule.out)) {
e = c.apply(e, r.matches);
if (e cast Func) {
S name = e.name;
if (eqOneOf(name, 'output, 'say))
postMessage(nlLogic_text(e.arg));
else if (eq(name, 'fact)) {
S fact = nlLogic_text(e.arg);
if (imagineMode) {
if (!containsNL(imaginedFacts, fact)) {
imaginedFacts.add(fact);
postMessage("Storing imaginary fact: " + fact);
}
} else if (ai_storeActualFact(fact))
postMessage("Storing fact: " + fact);
} else if (eq(name, 'storeRule)) {
S rule = nlLogic_text(e.arg);
rule = nlLogic_addGlobalID(rule);
if (mech_changed(appendToMechList_noUniq("NL Logic Examples", "\n" + rule)))
postMessage("Rule stored");
} else if (eq(name, 'imagineMode)) {
imagineMode = match("true", nlLogic_text(e.arg));
if (!imagineMode) imaginedFacts.clear();
}
}
}
}
}
}