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

55
LINES

< > BotCompany Repo | #1002498 // Combiner Bot (developing) - combines answers from different bots

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

Libraryless. Click here for Pure Java version (1406L/9K/30K).

1  
!752
2  
3  
static class Bot {
4  
  S id; // always formatted
5  
  boolean enabled, always;
6  
}
7  
8  
answer {
9  
  if (matchStart("askall", s, m)) {
10  
    s = m.rest().trim();
11  
    Map<S, S> answers = getAllAnswers(s);
12  
    ret "Answers: " + structure(answers);
13  
  }
14  
  
15  
  if (matchStart("combine", s, m)) {
16  
    s = m.rest().trim();
17  
    Map<S, S> answers = getAllAnswers(s);
18  
    ret combineAnswers(answers);
19  
  }
20  
}
21  
22  
static S combineAnswers(Map<S, S> answers) {
23  
  new TreeSet<S> set;
24  
  for (S s : values(answers))
25  
    if (!isDunno(s))
26  
      set.add(s);
27  
  ret "Actual answers: " + structure(set);
28  
}
29  
30  
static boolean isDunno(S s) {
31  
  ret matchStart("dunno", s) || matchStart("i don't know", s);
32  
}
33  
34  
// map: bot id -> answer
35  
static Map<S, S> getAllAnswers(S s) {
36  
  O dispatcher = call(getMainBot(), "getDispatcher");
37  
  L bots = cast call(dispatcher, "getSubBots");
38  
  
39  
  new Map<S, S> map;
40  
  for (int i = 0; i < l(bots); i++) pcall {
41  
    Bot bot = (Bot) restructure(bots.get(i));
42  
    if (!bot.enabled)
43  
      continue;
44  
    if (sameSnippetID(bot.id, getProgramID()))
45  
      continue; // skip myself to be safe
46  
      
47  
    Class c = cast call(dispatcher, "getClassOfSubBot", bot.id);
48  
    if (c != null) {
49  
      S a = callStaticAnswerMethod(c, s);
50  
      if (!empty(a))
51  
        map.put(formatSnippetID(bot.id), a);
52  
    }
53  
  }
54  
  ret map;
55  
}

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: #1002498
Snippet name: Combiner Bot (developing) - combines answers from different bots
Eternal ID of this version: #1002498/1
Text MD5: 6ef7cef565ebd8e80afa7a21740dda19
Transpilation MD5: 1a1161d99c3cef907ffdf4aa6856103e
Author: stefan
Category: eleu
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2016-01-26 21:37:19
Source code size: 1349 bytes / 55 lines
Pitched / IR pitched: No / No
Views / Downloads: 758 / 1206
Referenced in: [show references]