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

43
LINES

< > BotCompany Repo | #1002878 // Eleu Web Chat Bot

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

Libraryless. Click here for Pure Java version (1244L/9K/29K).

!752

static S chatName = "Eleu";
static int maxAnswerLength = 300;

p {
  thread "Web Chat Bot" { toChat(); }
}

static void toChat() {
  while (licensed()) {
    pcall {
      for (ChatLine l : suckHumans(chatName))
        sayInWebChat(chatName, _answer(l));
    }
    sleep(1000);
  }
}

static S _answer(ChatLine l) {
  S s = l.text;
  s = s.trim();
  // if (s.startsWith("!"))
  ((ThreadLocal) get(getMainBot(), "attn")).set(true);
  s = dropPrefix("!", s);
  
  ((ThreadLocal) get(getMainBot(), "userName")).set(l.auth ? "stefanreich" : null); // hack for authing

  S a = askSelf(s);
  if (empty(a)) ret null;
  S userName = l.who;
  
  // post long stuff to tinybrain instead
  if (l(a) > maxAnswerLength) {
    S q = s;
    S title = "Answer for " + userName + " (>> " + q + ")";
    S id = ntUpload("eleutheria-for-user", title, unSlackSnippet(a));
    int shortenTo = maxAnswerLength;
    a = shorten(a, shortenTo) + "\nFull answer here: #" + parseSnippetID(id);
  }
  
  ret a = "@" + l.who + " " + a;
}

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: #1002878
Snippet name: Eleu Web Chat Bot
Eternal ID of this version: #1002878/1
Text MD5: 1c4a7be55c1da6513ecbe3717d49e774
Transpilation MD5: ec02e8296f91a5058761ed2dd35ed1e0
Author: stefan
Category:
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2016-03-12 15:56:16
Source code size: 1058 bytes / 43 lines
Pitched / IR pitched: No / No
Views / Downloads: 550 / 683
Referenced in: [show references]