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

1  
!747
2  
3  
m {
4  
  p {
5  
    makeAndroid3("Text Bot.");
6  
  }
7  
  
8  
  static synchronized S answer(S s) {
9  
    new Matches m;
10  
    
11  
    if (match3("get text for md5 *", s, m)) {
12  
      S text = getTextForMd5(unquote(m.m[0]));
13  
      ret text == null ? "Sorry." : format3("text: *", text);
14  
    }
15  
    
16  
    if (match3("do you have md5 *?", s, m)) {
17  
      File file = getTextFile(unquote(m.m[0]));
18  
      boolean yes = file.exists();
19  
      ret yes ? "Yes (" + file.length() + " bytes)." : "No.";
20  
    }
21  
    
22  
    if (match3("store text *", s, m)) {
23  
      S text = unquote(m.m[0]);
24  
      S md5 = storeText(text);
25  
      ret format3("OK, stored. md5: *", md5);
26  
    }
27  
    
28  
    if (match3("delete md5 *", s, m)) {
29  
      S md5 = unquote(m.m[0]);
30  
      getTextFile(md5).delete();
31  
      return "OK.";
32  
    }
33  
    
34  
    if (match3("n", s)) {
35  
      return "" + length(getProgramDir().listFiles());
36  
    }
37  
    
38  
    if (match3("list md5s", s)) {
39  
      File[] files = getProgramDir().listFiles();
40  
      new L<S> md5s;
41  
      if (files != null) for (File f : files) {
42  
        if (f.getName().endsWith(".txt"))
43  
          md5s.add(f.getName().substring(0, 32).toLowerCase());
44  
      }
45  
      return structure(md5s);
46  
    }
47  
    
48  
    ret null;
49  
  }
50  
  
51  
  static S storeText(S text) {
52  
    S md5 = md5(text);
53  
    saveTextFile(getTextFile(md5), text);
54  
    return md5;
55  
  }
56  
  
57  
  static File getTextFile(S md5) {
58  
    verifyMD5(md5);
59  
    return new File(programDir(), md5 + ".txt");
60  
  }
61  
  
62  
  static S getTextForMd5(S md5) {
63  
    return loadTextFile(getTextFile(md5));
64  
  }
65  
}

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