Warning: session_start(): open(/var/lib/php/sessions/sess_rn624r6bp3tmj3pqmr2poq387u, 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
set flag Matches_fsi.
sbool assisting;
sclass RandomMain {
S generatorsID;
JFrame frame;
JTable table, chatTable;
//JTextArea chat;
JTextField input;
L log = synchroList();
L recommendations;
L thinkThreads = synchroList();
JLabel status;
S lastInput;
Map matchingSuggestion;
Map> allLogs = synchroMap();
JFrame analyzersFrame;
S dialogImageID;
JFrame dialogImageFrame;
int listDelay = 2000;
int maxLineLength = 1000;
int maxLongStringLength = 100*1000;
Bool thinking;
new Thinker thinker;
bool showCPU = true;
S systemPrefix = "[system]";
S dialog = "new";
void randomMain() {
regularGC();
//substanceLAF("EmeraldDusk"); // Too dark!
//substanceLAF("ChallengerDeep"); // So purple!
//substance("MistAqua");
substance("Moderate");
table = tableWithTooltips();
//chat = autoScroll(wordWrapTextArea());
chatTable = tableWithTooltips();
input = new JTextField;
status = jlabel("");
S title = assisting ? "Assistance - " + autoFrameTitle() : autoFrameTitle();
frame = showFrame(title, vgrid(centerAndSouth(
//jtabs(1, "Chat", chat, "Details", chatTable),
chatTable,
input), centerAndSouth(table, jline(jMemoryInfo(), status))));
if (!assisting) hideConsole();
//setFrameIconLater(frame, "#1003593");
addMenu(frame, "Random",
"Pop up last line in window (!pop)", r { pop(); },
"Delete last line (!delete)", r { post("!delete"); },
"Reload generators (!gen)", r { post("!gen"); },
"Restart app (!restart)", r { post("!restart"); },
"Restart Java engine (!fresh)", r { post("!fresh"); },
"Execute Java code (!j ...)", r { setInput("!j 1+2"); },
"Switch dialog (!dialog ...)", r { setInput("!dialog bla"); },
"Restore last input", r { if (nempty(lastInput)) setInput(lastInput); },
"Show raw dialog", r { showText("Raw Dialog", rawDialog()); },
);
makeDialogsMenu();
addMenu(frame, "Tools",
"Show Logic List", r { nohupJavax("#1004419"); }
);
onEnter(input, r {
post();
});
onDoubleClick(table, voidfunc(int row) {
chooseSuggestionForEditing(row);
});
for (int i = 1; i <= 12; i++) {
final int _i = i;
registerFunctionKey(frame, i, r {
chooseSuggestionForEditing(_i-1);
});
registerShiftFunctionKey(frame, i, r {
chooseSuggestion(_i-1);
});
registerCtrlFunctionKey(frame, i, r {
// post user input and then choose suggestion for editing
Map map = getTableLineAsMap(table, _i-1);
if (map == null) ret;
rankToTop(map);
S s = trim(unnull(map.get("Suggestion")));
logEvent("Suggestion chosen for editing with pre-post", mapPlus(map, "Row", _i, "Input", getInput(), "Top Suggesters", topSuggesters()));
post();
setInput(s);
});
}
onDoubleClickOrEnter(chatTable, voidfunc(int row) {
Map map = getTableLineAsMap(chatTable, row);
if (map != null)
setInput(getString(map, "Text"));
});
onUpdate(input, r { updateOnce(); });
loadDialog();
logEvent("Starting");
updateOnce();
input.requestFocus();
makeBot("Chat.", this);
veryQuickJava_optimize();
S last = last(log);
if (isAction(last) && confirmYesNo(input, "Run action? " + last(log)))
action(last);
}
S getInput() {
ret joinLines(" # ", input.getText().trim());
}
void post() {
postAsUser(getInput(), null);
}
void postAsUser(S i, Map infos) {
if (inputAllowedByUser(i))
post(i, infos);
}
void chooseSuggestionForEditing(int row) {
Map map = getTableLineAsMap(table, row);
if (map == null) ret;
rankToTop(map);
S s = trim(unnull(map.get("Suggestion")));
logEvent("Suggestion chosen for editing", mapPlus(map, "Row", row+1, "Input", getInput(), "Top Suggesters", topSuggesters()));
setInput(s);
}
void setInput(final S s) {
awtIfNecessary {
lastInput = input.getText();
input.setText(s);
input.selectAll();
input.requestFocus();
}
}
void rankToTop(Map map) {
rankToTop(map, false);
}
void rankToTop(Map map, bool removeISuggesters) {
if (map == null) ret;
O s = map.get("Suggesters");
// Table cells have been structure'd by dataToTable
L sugg = s instanceof L ? (L) s : (L) unstructure((S) s);
// These are cheaters!
if (removeISuggesters)
sugg = rejectWhere(func(S s) { s.endsWith("/i") }, sugg);
thinker.rankToTop(first(sugg));
}
void chooseSuggestion(int row) {
Map map = getTableLineAsMap(table, row);
if (map == null) ret;
rankToTop(map);
S s = trim(unnull(map.get("Suggestion")));
if (empty(s)) ret;
//logEvent("Suggestion chosen", mapPlus(map, "Row", row+1, "Input", getInput(), "Top Suggesters", topSuggesters));
setInput(s);
postAsUser(s, mapPlus(map, "Index", row+1));
}
L topSuggesters() {
int n = 20;
n = min(n, tableRows(table));
new L topSuggesters;
for (int i = 0; i < n; i++)
topSuggesters.add(getTableLineAsMap(table, i));
//if (empty(topSuggesters)) topSuggesters = null;
ret topSuggesters;
}
void logEvent(S type) {
logEvent(type, litmap());
}
void logEvent(S type, Map map) {
logStructure(new File(dialogDir(), "event.log"),
ll(type, chatTime(), map));
}
bool inputAllowedByUser(S i) {
ret !swic(i, systemPrefix);
}
// may be called from other thread
void postSystemMessage(final S msg) {
if (empty(msg)) ret;
awtIfNecessary {
post(systemPrefix + " " + msg, litmap("By", "System"));
}
}
S post(S i) {
ret post(i, null);
}
S post(S i, Map infos) {
S chatTime = null;
try {
i = trim(i);
if (empty(i)) null;
//i = escapeNewLines(i);
if (infos == null) {
infos = matchingSuggestion;
if (infos != null)
print("Ranking to top: " + struct(infos));
rankToTop(infos, true);
}
infos = mapPlus(infos, "Top Suggesters", topSuggesters());
bool tooLong = l(i) > maxLongStringLength;
if (l(i) > maxLineLength) {
S id = saveLongString(i);
i = substring(i, 0, maxLineLength) + "... [" + (tooLong ? "too " : "") + "long text " + id + "]";
}
} catch e {
printStackTrace(e);
i = systemPrefix + " " + exceptionToStringShort(e);
}
S s = i + "\n";
//chat.append(escapeNewLines(i) + "\n");
chatTime = chatTime();
appendToFile(logFile(), "[" + chatTime + "] " + s);
logEvent("Posting", litmap("Text", i, "Infos", infos));
log.add(i);
updateChatTable();
input.selectAll();
updateOnce();
try {
action(i);
} catch e {
printStackTrace(e);
postSystemMessage(exceptionToStringShort(e));
}
ret chatTime;
}
S dropActionPrefix(S s) {
if (s == null) null;
s = dropBracketPrefix(s); // e.g. "[bot]"
if (!s.startsWith("!")) null;
ret s.substring(1);
}
bool isAction(S s) {
ret dropActionPrefix(s) != null;
}
void action(S s) {
s = dropActionPrefix(s);
if (s == null) ret;
final S _s = s;
thread "Action" {
JWindow _loading_window = showLoadingAnimation();
try {
genLog_set(getLog()); // 'case user needs it
gOtherLogs_set(getOtherLogs()); // ditto
randomsOwnCmds(_s);
systemCommands(_s, RandomMain.this);
} catch e {
printStackTrace(e);
postSystemMessage("Error - " + exceptionToStringShort(e));
} finally {
genLog_clear();
gOtherLogs_clear();
disposeWindow(_loading_window);
}
}
}
volatile bool again;
// This logic is bad...
void fillList(bool force) {
bool t = force || shouldUpdateList();
if (neq(t, thinking)) {
thinking = t;
setFrameIcon(table, t ? "#1003603" : "#1003593");
}
if (!t) {
if (!force)
againl8r();
} else {
if (nempty(thinkThreads)) { again = true; ret; }
fillListImpl();
}
}
void addKeys(L