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

112
LINES

< > BotCompany Repo | #1017768 // BakedBot - uses in-memory mech lists by default

JavaX fragment (include)

sclass BakedBot {
  VirtualMechLists lists = new SimpleMechLists;
  Class bot;
  int goodTests, badTests;
  static S defaultSnippetID = #1017706;
  S snippetID = defaultSnippetID;
  
  *(VirtualMechLists *lists) { _init(); }
  *() { _init(); }
  
  void _init {
    bot = hotwireDependentSharingClasses(snippetID, VirtualMechLists);
    setOpt(bot, mechLibID := null);
    setOpt(bot, makeAndroid3_disable := true);
    //lists.verbose = true;
    setLists(lists);
    runMain(bot);
  }
  
  S answer(S s) {
    ret unnull(callAnswerMethod(bot, s));
  }
  
  S answer_verbose(S s) {
    ret print("< ", answer(print("> ", s)));
  }
  
  S check(S input, S expectedOutput) {
    ret assertEqualsVerbose_match(unnull(expectedOutput), answer(print("> ", input)));
  }
  
  bool pcheck(S input, S expectedOutput) {
    pcall-short { check(input, expectedOutput); ++goodTests; true; }
    ++badTests; false;
  }
  
  bool pcheckOrPrintLog(S input, S expectedOutput) {
    if (pcheck(input, expectedOutput)) true;
    ret false with printLines((LS) getOpt(getBot('TelegramFactsBot), 'checkingLog));
  }
  
  void setList(S name, S text) {
    lists.setText(name, text);
  }
  
  S getList(S name) {
    ret lists.mL_raw(name);
  }
  
  void setAuthorized(bool b) {
    setOpt(bot, authorized := b);
  }
  
  S answerAuthed(S s) {
    final bool authedOld = isTrue(getOpt(bot, 'authorized));
    setAuthorized(true);
    tempAfterwards(r { setAuthorized(authedOld); });
    ret answer(s);
  }
  
  void setLists(VirtualMechLists lists) {
    this.lists = lists;
    setAll(callOpt(bot, 'mechMode), readMode := lists, writeMode := lists);
  }
  
  O getBot(S shortClassName) {
    ret firstWithShortClassName((L) get(bot, 'bots), shortClassName);
  }
  
  void cleanMeUp {
    cleanUp(bot);
    bot = null;
  }
  
  O factsBot() {
    ret getBot('TelegramFactsBot);
  }
  
  void addFact(S fact) {
    if (!contains(lines(lists.mL_raw("Random facts")), fact))
      lists.append("Random facts", fact);
  }
  
  void printTestStats {
    print("\nGood tests: " + goodTests + ", bad tests: " + badTests + "\n");
  }
  
  void imagineMode() {
    set(factsBot(), imagineMode := true);
  }
  
  Collection<S> imaginedFacts() {
    ret (Collection<S>) get(factsBot(), 'imaginedFacts);
  }
  
  void useIterate(bool useIterate) {
    set(factsBot(), +useIterate);
  }
  
  void useDiskCache(bool useDiskCache) {
    setOpt(bot, transpileRaw_useDiskCache := useDiskCache);
  }
  
  void debug(bool debug) {
    set(factsBot(), +debug);
  }
  
  void setRules(S rules) {
    if (lists cast SimpleMechLists)
      lists.setText("NL Logic Examples", rules);
  }
}

Author comment

Began life as a copy of #1017766

download  show line numbers  debug dex  old transpilations   

Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1017768
Snippet name: BakedBot - uses in-memory mech lists by default
Eternal ID of this version: #1017768/44
Text MD5: 9b3eaaac8d03f38065c674be2085f11a
Author: stefan
Category: javax / a.i.
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-10-30 12:27:34
Source code size: 2756 bytes / 112 lines
Pitched / IR pitched: No / No
Views / Downloads: 512 / 1190
Version history: 43 change(s)
Referenced in: #1034167 - Standard Classes + Interfaces (LIVE, continuation of #1003674)