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

65
LINES

< > BotCompany Repo | #1001417 // Text Bot (md5 -> text)

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

Libraryless. Click here for Pure Java version (1180L/9K/28K).

!747

m {
  p {
    makeAndroid3("Text Bot.");
  }
  
  static synchronized S answer(S s) {
    new Matches m;
    
    if (match3("get text for md5 *", s, m)) {
      S text = getTextForMd5(unquote(m.m[0]));
      ret text == null ? "Sorry." : format3("text: *", text);
    }
    
    if (match3("do you have md5 *?", s, m)) {
      File file = getTextFile(unquote(m.m[0]));
      boolean yes = file.exists();
      ret yes ? "Yes (" + file.length() + " bytes)." : "No.";
    }
    
    if (match3("store text *", s, m)) {
      S text = unquote(m.m[0]);
      S md5 = storeText(text);
      ret format3("OK, stored. md5: *", md5);
    }
    
    if (match3("delete md5 *", s, m)) {
      S md5 = unquote(m.m[0]);
      getTextFile(md5).delete();
      return "OK.";
    }
    
    if (match3("n", s)) {
      return "" + length(getProgramDir().listFiles());
    }
    
    if (match3("list md5s", s)) {
      File[] files = getProgramDir().listFiles();
      new L<S> md5s;
      if (files != null) for (File f : files) {
        if (f.getName().endsWith(".txt"))
          md5s.add(f.getName().substring(0, 32).toLowerCase());
      }
      return structure(md5s);
    }
    
    ret null;
  }
  
  static S storeText(S text) {
    S md5 = md5(text);
    saveTextFile(getTextFile(md5), text);
    return md5;
  }
  
  static File getTextFile(S md5) {
    verifyMD5(md5);
    return new File(programDir(), md5 + ".txt");
  }
  
  static S getTextForMd5(S md5) {
    return loadTextFile(getTextFile(md5));
  }
}

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1001417
Snippet name: Text Bot (md5 -> text)
Eternal ID of this version: #1001417/1
Text MD5: 81aa9620aa492a88f9d304d9c8e8a5b4
Transpilation MD5: eff525a9b03872cd4b7939a10d2ec495
Author: stefan
Category: javax
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2015-10-15 18:36:12
Source code size: 1576 bytes / 65 lines
Pitched / IR pitched: No / Yes
Views / Downloads: 606 / 830
Referenced in: [show references]