Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

98
LINES

< > BotCompany Repo | #1009595 // Voice Actions 1 [OK]

JavaX source code [tags: use-pretranspiled] - run with: x30.jar

Uses 3874K of libraries. Click here for Pure Java version (11408L/81K/277K).

1  
!7
2  
3  
static Map<S, S> cmdToProgram;
4  
static Map<S, S> cmdToShell;
5  
static Map<S, S> cmdToAnswer;
6  
static Map<S, S> cmdToCmd;
7  
static Map<S, S> cmdToEval;
8  
static Map<S, Pair<S>> cmdToBotSend;
9  
static L<Pair<S, Long>> voiceCommandLog;
10  
static IVar<S> prioBot;
11  
12  
p {
13  
  magellan();
14  
  quietDB();
15  
  cmdToProgram = persistentTreeMap("Command to program");
16  
  cmdToShell = persistentTreeMap("Command to shell");
17  
  cmdToAnswer = persistentTreeMap("Command to answer");
18  
  cmdToCmd = persistentTreeMap("Command to command");
19  
  cmdToBotSend = persistentTreeMap("Command to bot send");
20  
  cmdToEval = persistentTreeMap("Command to eval");
21  
  prioBot = persistentVar("Prio bot");
22  
  voiceCommandLog = persistentList("Voice Command Log");
23  
  makeBot("Voice Actions.");
24  
}
25  
26  
sS answer(S s) {
27  
  new Matches m;
28  
  voiceCommandLog.add(pair(s, now()));
29  
  
30  
  if "prio bot *" { prioBot.set($1); consoleStatus(prioBot!); ret "OK"; }
31  
  if "prio bot done *" { if (eqic(prioBot!, $1)) prioBot.set(null); consoleStatus(prioBot!); ret "OK"; }
32  
  if "prio bot none" { prioBot.set(null); consoleStatus(prioBot!); ret "OK"; }
33  
34  
  if "user said: *" s = $1;
35  
  S a;
36  
  try { a = answer2(s); } catch e { printStackTrace(e); a = str(e); }
37  
  if (nempty(a)) infoBox_lower(a);
38  
  ret a;
39  
}
40  
41  
sS answer2(S s) {
42  
  new Matches m;
43  
  
44  
  // drop "ja" or "yep"
45  
  //S answerWord = dropPunctuation(botAnswerWord());
46  
  //if (matchStart(answerWord, s, m)) s = m.rest();
47  
  
48  
  if (nempty(prioBot!)) pcall {
49  
    try answer send(prioBot!, "User said: *", s);
50  
  }
51  
52  
  Set<S> seen;
53  
  for ping (seen = new LinkedHashSet; l(seen) < 100; ) {
54  
    if "command * to program *" { cmdToProgram.put($1, $2); ret "OK"; }
55  
    if "command * to shell *" { cmdToShell.put($1, $2); ret "OK"; }
56  
    if "command * to answer *" { cmdToAnswer.put($1, $2); ret "OK"; }
57  
    if "command * send * to *" { cmdToBotSend.put($1, pair($3, $2)); ret "OK"; }
58  
    if "command * to eval *" { cmdToEval.put($1, $2); ret "OK"; }
59  
    if "command * to command *" { cmdToCmd.put($1, $2); ret "OK"; }
60  
    if "remove command *" { removeFromMaps($1, cmdToProgram, cmdToShell, cmdToAnswer, cmdToBotSend, cmdToEval); ret "OK"; }
61  
    if "applause" { applause(); ret "Applause!"; }
62  
    if "restart voice actions" { restartIn1(); ret "OK"; }
63  
    if "voice log" { showLog(); ret "OK"; }
64  
    
65  
    S program = lookupByNLMatch(cmdToProgram, s);
66  
    if (nempty(program)) { nohupJavax(program); ret "Running: " + snippetWithTitle(program); }
67  
    
68  
    Pair<S> botSend = lookupByNLMatch(cmdToBotSend, s);
69  
    if (botSend != null)
70  
      ret send(botSend.a, botSend.b);
71  
72  
    S eval = lookupByNLMatch(cmdToEval, s);
73  
    if (eval != null)
74  
      ret or2(strOrEmpty(evalJava(eval)), "OK");
75  
76  
    S shell = lookupByNLMatch(cmdToShell, s);
77  
    if (nempty(shell)) { nohup(shell); ret "Running: " + shell; }
78  
    
79  
    try answer lookupByNLMatch(cmdToAnswer, s);
80  
    
81  
    seen.add(s);
82  
    s = lookupByNLMatch(cmdToCmd, s);
83  
    if (empty(s)) null;
84  
    if (seen.contains(s)) fail("bad cmd-to-cmd: " + sfu(seen));
85  
  }
86  
  
87  
  fail("bad cmd-to-cmd: " + sfu(seen));
88  
}
89  
90  
svoid showLog {
91  
  showTable_updatedOnConceptsChange("Voice Log", f renderLog);
92  
}
93  
94  
static L renderLog() {
95  
  ret reversed(map(cloneList(voiceCommandLog), func(Pair<S, Long> p) {
96  
    litorderedmap("Command" := p.a, "Time" := formatDateAndTime(p.b))
97  
  }));
98  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 15 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt, wtqryiryparv

No comments. add comment

Snippet ID: #1009595
Snippet name: Voice Actions 1 [OK]
Eternal ID of this version: #1009595/47
Text MD5: c9f7fd4cef3fb50eaabb3a9ae565cadb
Transpilation MD5: 81d5e4a72f7ec3352d5a6af6726b382f
Author: stefan
Category: javax / speech
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-08-22 22:14:06
Source code size: 3368 bytes / 98 lines
Pitched / IR pitched: No / No
Views / Downloads: 596 / 1544
Version history: 46 change(s)
Referenced in: [show references]