Warning: session_start(): open(/var/lib/php/sessions/sess_1aus9khjetlc2af0t7etvfh016, 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
!759
static Map cmdToProgram;
static Map cmdToShell;
static Map cmdToAnswer;
static Map cmdToCmd;
static L> voiceCommandLog;
static IVar prioBot;
p {
magellan();
quietDB();
cmdToProgram = persistentTreeMap("Command to program");
cmdToShell = persistentTreeMap("Command to shell");
cmdToAnswer = persistentTreeMap("Command to answer");
cmdToCmd = persistentTreeMap("Command to command");
prioBot = persistentVar("Prio bot");
voiceCommandLog = persistentList("Voice Command Log");
makeBot("Voice Actions.");
}
sS answer(S s) {
new Matches m;
voiceCommandLog.add(pair(s, now());
if "user said: *" s = $1;
S a;
try { a = answer2(s); } catch e { printStackTrace(e); a = str(e); }
if (nempty(a)) infoBox_lower(a);
ret a;
}
sS answer2(S s) {
new Matches m;
// drop "ja" or "yep"
//S answerWord = dropPunctuation(botAnswerWord());
//if (matchStart(answerWord, s, m)) s = m.rest();
if (nempty(prioBot!)) pcall {
try answer send(prioBot!, "User said: *", s);
}
Set seen;
for ping (seen = new LinkedHashSet; l(seen) < 100; ) {
if "command * to program *" { cmdToProgram.put($1, $2); ret "OK"; }
if "command * to shell *" { cmdToShell.put($1, $2); ret "OK"; }
if "command * to answer *" { cmdToAnswer.put($1, $2); ret "OK"; }
if "command * to command *" { cmdToCmd.put($1, $2); ret "OK"; }
if "remove command *" { removeFromMaps($1, cmdToProgram, cmdToShell, cmdToAnswer); ret "OK"; }
if "applause" { applause(); ret "Applause!"; }
if "restart voice actions" { restartIn1(); ret "OK"; }
if "voice log" { showLog(); ret "OK"; }
if "prio bot *" { prioBot.set($1); ret "OK"; }
if "prio bot done *" { if (eqic(prioBot!, $1)) prioBot.set(null); ret "OK"; }
if "prio bot none" { prioBot.set(null); ret "OK"; }
S program = lookupByNLMatch(cmdToProgram, s);
if (nempty(program)) { nohupJavax(program); ret "Running: " + snippetWithTitle(program); }
S shell = lookupByNLMatch(cmdToShell, s);
if (nempty(shell)) { nohup(shell); ret "Running: " + shell; }
try answer lookupByNLMatch(cmdToAnswer, s);
seen.add(s);
s = lookupByNLMatch(cmdToCmd, s);
if (empty(s)) null;
if (seen.contains(s)) fail("bad cmd-to-cmd: " + sfu(seen));
}
fail("bad cmd-to-cmd: " + sfu(seen));
}
svoid showLog {
showTable_updatedOnConceptsChange("Voice Log", f renderLog);
}
static L renderLog() {
ret reversed(map(cloneList(voiceCommandLog), func(Pair p) {
litorderedmap("Command" := p.a, "Time" := formatDateAndTime(p.b))
}));
}