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

78
LINES

< > BotCompany Repo | #1002669 // Dialog Network Action Bot (dev.)

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

Libraryless. Click here for Pure Java version (1792L/11K/37K).

!752

static class LineSaid extends Status {
  S lineID, text;
  
  *() {}
  *(O line) {
    lineID = getString(line, "id");
    text = getString(line, "text");
  }
  
  S answer(S s) {
    status(null);
    ret askSelf("dn add * to *", s, lineID);
  }
}

static class WhatShouldISayTo extends Status {
  S lineID, text;
  
  *() {}
  *(O line) {
    lineID = getString(line, "id");
    text = getString(line, "text");
  }
  
  S answer(S s) {
    status(null);
    new Matches m;
    if (matchStart("say", s, m)) {
      S text = unquote(m.rest().trim());
      ret askSelf("dn add * to *", text, lineID);
    }
    ret null;
  }
}

answer {
  if "say something" exceptionToUser {
    L starters = cast call(getDialogEngine(), "findStarters");
    if (empty(starters)) ret "Nothing found to say...";
    O line = randomOne(starters);
    ret lineSaid(line);
  }

  try answer status_answer(s);
  
  if (attn()) exceptionToUser {
    O line = call(getDialogEngine(), "findStarter", s);
    if (line != null) {
      L refs = cast call(getDialogEngine(), "getReferences", line);
      line = randomOne(refs);
      if (line != null)
        ret lineSaid(line);
    }

    // make new entry

    line = call(getDialogEngine(), "add", s);    
    status(new WhatShouldISayTo(line));

    // ask what i should say
    ret "what should i say to that, master?";
  }
  

}

static O getDialogEngine() {
  O dialogEngine = getBot("#1002666");
  if (dialogEngine == null) ret "No dialog engine (install #1002666!)";
  ret dialogEngine;
}

static S lineSaid(O line) {
  status(new LineSaid(line));
  ret getString(line, "text");
}

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1002669
Snippet name: Dialog Network Action Bot (dev.)
Eternal ID of this version: #1002669/1
Text MD5: 27b42ac2e7fcfe24a284a813d978c871
Transpilation MD5: 6bbc57b474e972021b0e6bb3dacda5f2
Author: stefan
Category: eleu / javax
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2016-02-12 01:20:25
Source code size: 1699 bytes / 78 lines
Pitched / IR pitched: No / No
Views / Downloads: 826 / 858
Referenced in: [show references]