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).

!752

static class Bot {
  S id; // always formatted
  boolean enabled, always;
}

answer {
  if (matchStart("askall", s, m)) {
    s = m.rest().trim();
    Map<S, S> answers = getAllAnswers(s);
    ret "Answers: " + structure(answers);
  }
  
  if (matchStart("combine", s, m)) {
    s = m.rest().trim();
    Map<S, S> answers = getAllAnswers(s);
    ret combineAnswers(answers);
  }
}

static S combineAnswers(Map<S, S> answers) {
  new TreeSet<S> set;
  for (S s : values(answers))
    if (!isDunno(s))
      set.add(s);
  ret "Actual answers: " + structure(set);
}

static boolean isDunno(S s) {
  ret matchStart("dunno", s) || matchStart("i don't know", s);
}

// map: bot id -> answer
static Map<S, S> getAllAnswers(S s) {
  O dispatcher = call(getMainBot(), "getDispatcher");
  L bots = cast call(dispatcher, "getSubBots");
  
  new Map<S, S> map;
  for (int i = 0; i < l(bots); i++) pcall {
    Bot bot = (Bot) restructure(bots.get(i));
    if (!bot.enabled)
      continue;
    if (sameSnippetID(bot.id, getProgramID()))
      continue; // skip myself to be safe
      
    Class c = cast call(dispatcher, "getClassOfSubBot", bot.id);
    if (c != null) {
      S a = callStaticAnswerMethod(c, s);
      if (!empty(a))
        map.put(formatSnippetID(bot.id), a);
    }
  }
  ret map;
}

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: 665 / 1096
Referenced in: [show references]