// Bot Ref Bot knows which bots are online on some machine. !747 m { static int interval = 4000; static L bots = new ArrayList(); p { makeAndroid3("Bot Ref Bot."); while (true) { scan(); sleep(interval); } } static void scan() { setBots(quickBotScan()); } static synchronized void setBots(L l) { bots = l; } // returned list is thread-safe (immutable even) static synchronized L getBots() { ret bots; } static synchronized S answer(S s, L history) { new Matches m; if (match3("please forward to bot *: *", s, m)) { S bot = m.unq(0); S line = m.unq(1); DialogIO io = findBotFromList(bot); if (io != null) { S hello = io.readLine(); if (startsWithIgnoreCase(hello, bot)) { io.sendLine(line); S answer = io.readLine(); io.close(); ret answer; } } // default case print("not in list, fallback"); ret sendToLocalBot(bot, line); // TODO: keep connections } ret useQuestionBot(s, history); } static S useQuestionBot(S s, L history) { ret sendToLocalBot("Questions Bot", "how can question * to bot * be answered?", s, getProgramID()); } static DialogIO findBotFromList(S botName) { for (ProgramScan.Program p : getBots()) if (startsWithIgnoreCase(p.helloString, botName)) ret talkTo(p.port); ret null; } }