Libraryless. Click here for Pure Java version (2009L/13K/45K).
!747 !pcall { !named thread m { static new Map<S, S> cache; // "122" (or "t123") to md5 static long lastUpdate; static long updateInterval = 5000; static long versionCount, lastAutoCheck; p { readLocally("cache lastUpdate"); Android3 android = new Android3("Boss Bot."); android.startPort = 4990; makeAndroid3(android); updateLoop(); } static void updateLoop() { thread "update loop" { while (true) { checkVersionCount(); sleep(updateInterval); } } } static synchronized S answer(S s) { new Matches m; if (match3("get cache size", s)) return cache.size() + " entries"; if (match3("when was your last update", s)) return "" + lastUpdate; if (match3("when was your last auto-check", s)) return "" + lastAutoCheck; if (match3("please update", s)) { update(); return "OK, done."; } if (match3("please clear cache", s)) { update(); // TODO: delete files return "OK, done."; } if (match3("what is your update interval?", s)) return updateInterval + " ms plus time of check"; if (match3("is auto-update on?", s)) return "Yes."; if (match3("get md5 of *", s, m)) { S md5 = cache.get("" + parseSnippetID(unquote(m.m[0]))); return md5 != null ? format3("MD5: *", md5) : "Snippet not found."; } if (match3("get text of *", s, m) || match3("get text for *", s, m)) { S snippetID = "" + parseSnippetID(unquote(m.m[0])); S md5 = cache.get(snippetID); if (md5 == null) ret "Snippet not found."; S text = ""; if (!md5.equals("-")) text = loadText(snippetID, md5); ret format3("Text: *", text); } if (match3("get transpilation of *", s, m) || match3("get transpilation for *", s, m)) { S snippetID = "t" + parseSnippetID(unquote(m.m[0])); S md5 = cache.get(snippetID); if (md5 == null) ret "Transpilation not found."; S text = ""; if (!md5.equals("-")) { text = loadText(snippetID, md5); if (!eq(md5(text.substring(text.indexOf('\n')+1)), md5)) print("Warning: MD5 mismatch for " + snippetID); } ret format3("Text: *", text); } ret null; } static synchronized void checkVersionCount() { pcall { lastAutoCheck = now(); long newCount = Long.parseLong(loadPageSilently("http://tinybrain.de:8080/tb-int/versioncount.php")); if (newCount != versionCount) { versionCount = newCount; print("Version count updated to " + versionCount + ", getting new md5s."); update(); } } } static synchronized void update() { S s = loadPage("http://tinybrain.de:8080/tb-int/all-md5s.php?withtranspiled=1"); print("[" + s.length() + " chars loaded]"); cache.clear(); for (S line : toLinesFullTrim(s)) { S[] tok = line.split(":"); if (tok.length != 2) fail("huch: " + structure(tok)); S snippetID = tok[0]; S md5 = tok[1]; cache.put(snippetID, md5); } saveLocally("cache"); lastUpdate = now(); saveLocally("lastUpdate"); } static File getTextFile(S snippetID, S md5) { return new File(programDir(), snippetID + "-" + md5 + ".txt"); } static synchronized S loadText(S snippetID, S md5) { File f = getTextFile(snippetID, md5); if (f.exists()) return loadTextFile(f); S text = loadTextFromSite(snippetID, md5); saveTextFile(f, text); return text; } static S loadTextFromSite(S snippetID, S md5) { S url; if (snippetID.startsWith("t")) url = "http://tinybrain.de:8080/tb-int/get-transpiled.php?raw=1&withlibs=1&id=" + snippetID.substring(1); else url = "http://tinybrain.de:8080/tb/get-version-raw.php?id=" + parseSnippetID(snippetID) + "&md5=" + urlencode(md5); // TODO: try a few times :) return loadPage(url); } }
Began life as a copy of #1001369
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
ID | Author/Program | Comment | Date |
---|---|---|---|
1126 | stefan | TODO: bug with translations not found... | 2015-10-13 21:05:37 |
Snippet ID: | #1001383 |
Snippet name: | Boss Bot v2 (with continuous update, developing) |
Eternal ID of this version: | #1001383/1 |
Text MD5: | 75a8a20cc067d8e8cbb97a8f250fc5a9 |
Transpilation MD5: | 0d01cd8bc8c1b6c0e17ac64a533209f0 |
Author: | stefan |
Category: | javax |
Type: | JavaX source code |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2015-11-11 18:45:35 |
Source code size: | 4138 bytes / 140 lines |
Pitched / IR pitched: | No / Yes |
Views / Downloads: | 1055 / 1104 |
Referenced in: | [show references] |