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

80
LINES

< > BotCompany Repo | #1013897 // Google Login Thought Bot [dev.]

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

Libraryless. Click here for Pure Java version (10026L/69K/224K).

!7

static Env env;
static new ThreadLocal<Session> session;
static ThreadLocal<L<S>> buttons = new ThreadLocal;
static Map<S, Int> spellMap;

static interface Env {
  void sayAsync(S session, S msg);
}

concept Session {
  S cookie;
  S lastQuestion;
}

sbool debug;

svoid setSession(S cookie) {
  session.set(uniq_sync(Session, +cookie));
}

svoid clearSession(S cookie) {
  deleteConcepts(Session, +cookie);
}

p {
  db();
  
  // load stuff
  spellMap = loadSpellList(#1008389);
  //printStruct(spellMap);

  veryBigConsole();
  bot();
}

sS returnQuestion(S q) {
  cset(session!, lastQuestion := q);
  ret q;
}

sS answer(S s) {
  if (session! == null) setSession("default");
  buttons.set(null);
  if (creator() == null) if "debug" set debug;
  
  S lq = session->lastQuestion;
  cset(session!, lastQuestion := null);
  
  if (eq(lq, "Would you like some tea?")) {
    if "yes" ret "Here's your tea.";
    if "no" ret "Very well then.";
  }
  
  if "test buttons" {
    buttons.set(ll("Yes", "No"));
    ret returnQuestion("Would you like some tea?");
  }
  
  if "say something later" {
    if (env == null) ret("No env");
    final S mySession = session->cookie;
    thread {
      sleepSeconds(5);
      env.sayAsync(mySession, "Here it is.");
    }
    ret "OK, will do it in 5 seconds";
  }

  S _s = s;
  s = levenAttract(spellMap, s);
  if (neqic(s, _s)) print("Spell-correct => " + s);

  ret "Sorry, I didn't understand that";
}

sS initialMessage() {
  ret "Your personal bot here. " + returnQuestion("How can I help you?");
}

Author comment

Began life as a copy of #1008347

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: #1013897
Snippet name: Google Login Thought Bot [dev.]
Eternal ID of this version: #1013897/5
Text MD5: 5853c87e304d843de92f1e66b08cb03f
Transpilation MD5: 966b0570e2b51097824ac7464d694193
Author: stefan
Category: javax / a.i.
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-03-14 14:54:47
Source code size: 1624 bytes / 80 lines
Pitched / IR pitched: No / No
Views / Downloads: 421 / 880
Version history: 4 change(s)
Referenced in: #1013898 - Google Login Bot [dev.]