!7 static Map cmdToProgram; static Map cmdToShell; static Map cmdToAnswer; static L> voiceCommandLog; p { magellan(); quietDB(); cmdToProgram = persistentTreeMap("Command to program"); cmdToShell = persistentTreeMap("Command to shell"); cmdToAnswer = persistentTreeMap("Command to answer"); 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 "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 "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; } S a = lookupByNLMatch(cmdToAnswer, s); ret a; } 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)) })); }