!747 m { static new Map entries; static S pattern = "meta * - just got it from the web. snippet * now has md5 * and title *."; p { readLocally("entries"); print(entries.size() + " entries in cache."); makeAndroid("Snippet Cache Bot. v2."); } static void addEntry(S e) { entries.put(extractID(e), e); // TODO: compare timestamps saveLocally("entries"); } static S getEntry(S roughID) { S id = formatSnippetID(unquote(roughID)); S e = entries.get(id); if (e == null) { // Load from web! S title = getSnippetTitle(id); S md5 = getSnippetMD5(id); e = "meta " + quote(now()) + " - just got it from the web. snippet " + quote(id) + " now has md5 " + quote(md5) + " and title " + quote(title) + "."; addEntry(e); } return e; } static S extractID(S e) { new Matches m; if (!find3("snippet *", e, m)) return null; return formatSnippetID(unquote(m.m[0])); } static S extractMD5(S e) { new Matches m; if (!find3("md5 *", e, m)) return null; return unquote(m.m[0]); } static S extractTitle(S e) { new Matches m; if (!find3("title *", e, m)) return null; return unquote(m.m[0]); } static synchronized S answer(S s) { new Matches m; // put new information in store if (match3(pattern, s, m)) { print("New entry: " + structure(m.m)); addEntry(s); return "OK, stored."; } // retrieve information if (match3("get md5 of snippet *", s, m)) return extractMD5(getEntry(m.m[0])); if (match3("get title of snippet *", s, m)) { return extractTitle(getEntry(m.m[0])); } // other commands if (match3("please consolidate", s, m)) return "OK, nothing to consolidate."; return null; } }