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

45
LINES

< > BotCompany Repo | #1002084 // Snippet Text Bot (seems to work)

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

Libraryless. Click here for Pure Java version (5851L/40K/130K).

// Logic: asks Snippet MD5 Bot for current MD5

!752

m {
  static DiskTextMap map; // snippet ID to text
  
  p {
    map = new DiskTextMap("mymap");
    startBot("Snippet MD5 Bot", "#1002079");
    makeBot("Snippet Text Bot.");
  }
  
  static synchronized S answer(S s) {
    new Matches m;
    if (match3("what is the text of snippet *", s, m)) {
      S snippetID = formatSnippetID(m.unq(0));
      S answer = sendToLocalBot("Snippet MD5 Bot", "what is the md5 of snippet *", snippetID);
      assertTrue(match("the md5 of snippet * is *", answer, m));
      S md5 = m.unq(1);
      S text = map.get(snippetID);
      if (text == null || neq(md5(text), md5)) {
        text = loadSnippetVersion(snippetID, md5);
        if (text == null) ret "null";
        map.put(snippetID, text);
      }
      ret format("The text of snippet * is *.", snippetID, text);
    }
    
    if (match3("clear snippet text cache", s, m)) {
      clear();
      ret "OK.";
    }
    
    if (match3("get snippet text cache size", s, m)) {
      ret "Cache entries: " + map.size();
    }
    
    ret null;
  }
  
  static synchronized void clear() {
    map.clear();
  }
}

Author comment

Began life as a copy of #1002079

download  show line numbers  debug dex  old transpilations   

Travelled to 16 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, jtubtzbbkimh, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, teubizvjbppd, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1002084
Snippet name: Snippet Text Bot (seems to work)
Eternal ID of this version: #1002084/1
Text MD5: 5963cfcd9f338842f62b57596354e005
Transpilation MD5: ac85aa4a225b7a8534dc9ce07c2f07a9
Author: stefan
Category: javax
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-06-09 03:18:18
Source code size: 1201 bytes / 45 lines
Pitched / IR pitched: No / No
Views / Downloads: 664 / 1972
Referenced in: [show references]