!7 static S defaultTemplateID = "#1002609"; static S speechTemplateID = "#1002347"; static S mobileTemplateID = "#1002450"; static S mobileSpeechTemplateID = "#1002350"; static S titleImg = "http://eyeocr.sourceforge.net/filestore/filestore.php?cmd=serve&file=blob_1002488&contentType=image/png"; static S news; p { news = htag("li", "We are making an A.I. Join the community to find out more.") + htag("li", shortSystemName() + "'s current " + htag("a", "Turing score", "href", "http://bots.tinybrain.de/1002408") + ": " + htag("b", "$turing")) + htag("li", "PS: You can donate to make this project fly! -" + tag("a", "Stefan", "href", "mailto:info@superinformatiker.de")); } static int maxQuestionLength = 500; static int maxAnswerLength = 200; static S html(S subUri, Map params) { S _q = params.get("q"); boolean speech = nempty(params.get("speech")); boolean mobile = !empty(params.get("m")); boolean noredir = !empty(params.get("d")); int loaded = l((L) get(mainBot, "bots")); int total = l((L) get(mainBot, "botIDs")); S template; if (mobile) template = speech ? mobileSpeechTemplateID : mobileTemplateID; else template = speech ? speechTemplateID : defaultTemplateID; S html = loadSnippet(template); boolean isAuthed = webAuthed(params); if (noredir) { L tok = htmlcoarsetok(html); int i1 = tok.indexOf([[", i1+1); print("i1=" + i1 + ", i2=" + i2); if (i1 >= 0 && i2 > i1) { clearAllTokens(tok.subList(i1, i2+1)); html = join(tok); } } // get answer and print it! boolean def = empty(_q); if (def) _q = "Greet me!"; if (!empty(_q)) { S a = trim((S) call(mainBot, "webAnswer", _q, !def)); if (isEmpty(a)) a = "(no response)"; S toreplace = [[
]]; try { a = encodeAnswerForWeb(a); } catch (Throwable e) { printStackTrace(e); a = htmlencode(a); } html = html.replace(toreplace, toreplace + "" + system() + ": " + a); } // title image S origImg = "http://eyeocr.sourceforge.net/filestore/filestore.php?cmd=serve&file=blob_1002279&contentType=image/png"; //html = html.replace(origImg, "http://eyeocr.sourceforge.net/filestore/filestore.php?cmd=serve&file=blob_1002409&contentType=image/png"); html = html.replace(origImg, titleImg); // link html = html.replace(htmlQuote("http://tinybrain.de"), htmlQuote("http://sister.tinybrain.de")); // fix note html = html.replace(".It learns about computers first, then humans.", ". It learns about computers first, then humans. " + hrefBlank("http://bots.tinybrain.de", "Bot list.")); // system name html = html.replace("Eleutheria", system()); html = html.replace("International International", "International"); // one is enough! S systemURL = systemURL(); if (nempty(systemURL)) pcall { int idx = html.indexOf(""); html = html.substring(0, idx+1) + html.substring(idx+1).replace(system() + " is learning how to think", tag("a", system(), "href", systemURL) + " is learning how to think"); } // show if authed if (isAuthed) html = html.replace("Talk to the robot", "Talk to the robot (you are authorized)"); // no talk for not authed if (!isAuthed) html = deleteFromTo(html, "
"); //html = html.replace("PUT # OF BOTS HERE", loaded + "/" + total); L history = cast get(mainBot, "history"); new StringBuffer buf; pcall { int x = max(l(history)-5, 0); print("l(history)=" + l(history) + ", x=" + x); for (int i = l(history)-1; i >= x; i--) { O dialog = history.get(i); S q = shorten(getString(dialog, "question"), maxQuestionLength); S a = shorten(getString(dialog, "answer"), maxAnswerLength); buf.append(htag("li", "User: " + htmlencode(q) + "", "class", "splash-li") + "\n"); buf.append(htag("li", system() + ": " + htmlencode(a) + "", "class", "splash-li") + "\n"); } } L tok = htmlcoarsetok(html); // Last dialogs int i1 = tok.indexOf("
    "); int i2 = indexOf(tok, "
", i1+1); //print("i1=" + i1 + ", i2= " + i2); if (i1 >= 0 && i2 > i1) { clearAllTokens(tok.subList(i1+1, i2)); tok.set(i1+1, str(buf)); } // News i1 = indexOf(tok, "
    ", i1+1); i2 = indexOf(tok, "
", i1+1); if (i1 >= 0 && i2 > i1) { clearAllTokens(tok.subList(i1+1, i2)); S dehnews = news; pcall { S score = or((S) callOpt(getBot("#1002408"), "getTuringScore"), "not calculated yet"); dehnews = dehnews.replace("$turing", score); } tok.set(i1+1, dehnews); } O visitorsBot = callOpt(mainBot, "getBot", "#1002157"); S visitorStats = visitorsBot == null ? null : str(callHtmlMethod(visitorsBot, "/")); if (nempty(visitorStats)) pcall { //html = "\n" + html; // Coolbox visitorStats = visitorStats.substring(visitorStats.indexOf("
") + 4); int i = tok.indexOf(""); if (i < 0) i = tok.indexOf("
"); if (i >= 0) tok.set(i, tok.get(i) + [[

$title

$content
]].replace("$title", "Visitor Stats") .replace("$content", htag("p", visitorStats))); } html = join(tok); html = html.replace("(latest first)", "(latest first, " + l(history) + " total)"); // Bot List link S botsList = "/1002771"; html = html.replace("=\"http://bots.tinybrain.de/\"" , "=\"" + botsList + "\""); html = html.replace("=\"http://bots.tinybrain.de\"", "=\"" + botsList + "\""); ret html; } static S encodeAnswerForWeb(S s) { s = s.trim(); new Matches m; S s2 = dropPrefixIgnoreCase("lookie here: ", s); if (neq(s, s2) || s.contains(".gstatic.com/images?") || s.startsWith("http://tinyurl.com/")) { S url = s2.trim(); print("url: " + quote(url)); if (isURL(url)) ret "
" + tag("img", "", "src", url); } if (isURL(s)) ret tag("a", htmlencode(s), "href", s, "target", "_blank"); new StringBuilder buf; int i = 0; while (i < l(s)) { int i1 = smartIndexOf(s, "```", i); int i2 = smartIndexOf(s, "```", i1+3); buf.append(htmlencode(s.substring(i, i1))); if (i2 > i1) buf.append(sourceCodeToHTML(s.substring(i1+3, i2))); i = i2+3; } ret str(buf); }