!759 static Map cmdToProgram; static Map cmdToShell; static Map cmdToAnswer; static Map cmdToCmd; static L> voiceCommandLog; p { magellan(); quietDB(); cmdToProgram = persistentTreeMap("Command to program"); cmdToShell = persistentTreeMap("Command to shell"); cmdToAnswer = persistentTreeMap("Command to answer"); cmdToCmd = persistentTreeMap("Command to command"); 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(); 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"; } 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)) })); }