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

50
LINES

< > BotCompany Repo | #1001893 // Generic chat bot algorithm using timestamped responses (developing)

JavaX source code - run with: x30.jar

1  
!752
2  
3  
p {
4  
  L<Msg> msgs = getLastMsgs(); // must be in order
5  
  for (Msg msg : msgs)
6  
    onMsg(msg);
7  
  now();
8  
  
9  
  while true {
10  
    msgs = getMoreMsgs();
11  
    for (Msg msg : msgs)
12  
      onMsg(msg);
13  
    if (!msgs.isEmpty())
14  
      now();
15  
    sleepSeconds(10);
16  
  }
17  
}
18  
19  
static void onMsg(Msg msg) {
20  
  if (isQuestion(msg))
21  
    questions.add(msg);
22  
  else if (isAnswer(msg)) {
23  
    Msg q = getQuestion(msg);
24  
    questions.remove(q);
25  
    if (current == q)
26  
      current = null;
27  
  }
28  
}
29  
30  
static void now() {
31  
  if (current != null) ret; // still waiting for my own answer to appear
32  
  if (!questions.isEmpty()) {
33  
    current = questions.get(0);
34  
    questions.remove(0);
35  
    postAnswer(current);
36  
  }
37  
}
38  
39  
static Msg getQuestion(Msg a) {
40  
  // TODO
41  
}
42  
43  
static void postAnswer(Msg q) {
44  
  // call the bot
45  
  // if answer == null:
46  
  //   if we're directly targeted in the question (@blabot),
47  
  //   say "i don't know".
48  
  //   if we're not targeted, delete the question from list.
49  
  // if there is an answer, post the answer with time stamp of question.
50  
}

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: #1001893
Snippet name: Generic chat bot algorithm using timestamped responses (developing)
Eternal ID of this version: #1001893/1
Text MD5: 38858f8436fd5bb2289a8abd9555b4ad
Author: stefan
Category:
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2015-12-06 18:32:48
Source code size: 1076 bytes / 50 lines
Pitched / IR pitched: No / Yes
Views / Downloads: 582 / 527
Referenced in: [show references]