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

94
LINES

< > BotCompany Repo | #1001369 // Boss Bot (has up-to-date snippet contents)

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

Libraryless. Click here for Pure Java version (1541L/11K/36K).

1  
!747
2  
3  
m {
4  
  static new Map<S, S> cache; // "122" (or "t123") to md5
5  
  static long lastUpdate;
6  
  
7  
  p {
8  
    readLocally("cache lastUpdate");
9  
    Android3 android = new Android3("Boss Bot.");
10  
    android.startPort = 4990;
11  
    makeAndroid3(android);
12  
  }
13  
  
14  
  static synchronized S answer(S s) {
15  
    new Matches m;
16  
    
17  
    if (match3("get cache size", s))
18  
      return cache.size() + " entries";
19  
      
20  
    if (match3("when was your last update", s))
21  
      return "" + lastUpdate;
22  
      
23  
    if (match3("please update", s)) {
24  
      update();
25  
      return "OK, done.";
26  
    }
27  
    
28  
    if (match3("get md5 of *", s, m)) {
29  
      S md5 = cache.get("" + parseSnippetID(unquote(m.m[0])));
30  
      return md5 != null ? format3("MD5: *", md5) : "Snippet not found.";
31  
    }
32  
    
33  
    if (match3("get text of *", s, m) || match3("get text for *", s, m)) {
34  
      S snippetID = "" + parseSnippetID(unquote(m.m[0]));
35  
      S md5 = cache.get(snippetID);
36  
      if (md5 == null) ret "Snippet not found.";
37  
      S text = "";
38  
      if (!md5.equals("-"))
39  
        text = loadText(snippetID, md5);
40  
      ret format3("Text: *", text);
41  
    }
42  
    
43  
    if (match3("get transpilation of *", s, m) || match3("get transpilation for *", s, m)) {
44  
      S snippetID = "t" + parseSnippetID(unquote(m.m[0]));
45  
      S md5 = cache.get(snippetID);
46  
      if (md5 == null) ret "Transpilation not found.";
47  
      S text = "";
48  
      if (!md5.equals("-"))
49  
        text = loadText(snippetID, md5);
50  
      ret format3("Text: *", text);
51  
    }
52  
    
53  
    ret null;
54  
  }
55  
  
56  
  static synchronized void update() {
57  
    S s = loadPage("http://tinybrain.de:8080/tb-int/all-md5s.php?withtranspiled=1");
58  
    cache.clear();
59  
    for (S line : toLinesFullTrim(s)) {
60  
      S[] tok = line.split(":");
61  
      if (tok.length != 2)
62  
        fail("huch: " + structure(tok));
63  
      S snippetID = tok[0];
64  
      S md5 = tok[1];
65  
      cache.put(snippetID, md5);
66  
    }
67  
    saveLocally("cache");
68  
    lastUpdate = now();
69  
    saveLocally("lastUpdate");
70  
  }
71  
  
72  
  static File getTextFile(S snippetID, S md5) {
73  
    return new File(programDir(), snippetID + "-" + md5 + ".txt");
74  
  }
75  
  
76  
  static synchronized S loadText(S snippetID, S md5) {
77  
    File f = getTextFile(snippetID, md5);
78  
    if (f.exists()) return loadTextFile(f);
79  
    S text = loadTextFromSite(snippetID, md5);
80  
    saveTextFile(f, text);
81  
    return text;
82  
  }
83  
  
84  
  static S loadTextFromSite(S snippetID, S md5) {
85  
    S url;
86  
    if (snippetID.startsWith("t"))
87  
      url = "http://tinybrain.de:8080/tb-int/get-transpiled.php?raw=1&withlibs=1&id=" + snippetID.substring(1);
88  
    else
89  
      url = "http://tinybrain.de:8080/tb/get-version-raw.php?id=" + parseSnippetID(snippetID) + "&md5=" + urlencode(md5);
90  
    
91  
    // TODO: try a few times :)
92  
    return loadPage(url);
93  
  }
94  
}

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1001369
Snippet name: Boss Bot (has up-to-date snippet contents)
Eternal ID of this version: #1001369/1
Text MD5: c12c16ccc75cba3d6092d8c3c4267f29
Transpilation MD5: 67d4f314660dd5b0c76930c8d25cc26d
Author: stefan
Category: javax
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2015-10-12 00:59:04
Source code size: 2837 bytes / 94 lines
Pitched / IR pitched: No / Yes
Views / Downloads: 602 / 698
Referenced in: [show references]