Libraryless. Click here for Pure Java version (1511L/10K/36K).
// Bot Ref Bot knows which bots are online on some machine. !747 m { static int interval = 4000; static L<ProgramScan.Program> bots = new ArrayList<ProgramScan.Program>(); p { makeAndroid3("Bot Ref Bot."); while (true) { scan(); sleep(interval); } } static void scan() { setBots(quickBotScan()); } static synchronized void setBots(L<ProgramScan.Program> l) { bots = l; } // returned list is thread-safe (immutable even) static synchronized L<ProgramScan.Program> getBots() { ret bots; } static synchronized S answer(S s, L<S> 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<S> 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; } }
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
No comments. add comment
Snippet ID: | #1001493 |
Snippet name: | Bot Ref Bot |
Eternal ID of this version: | #1001493/1 |
Text MD5: | 61da5d3dcfcdb3711468b41f0edba539 |
Transpilation MD5: | 9beca85b20143d07991631b3cb7dd845 |
Author: | stefan |
Category: | |
Type: | JavaX source code |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2015-10-21 17:33:18 |
Source code size: | 1634 bytes / 68 lines |
Pitched / IR pitched: | No / Yes |
Views / Downloads: | 672 / 710 |
Referenced in: | [show references] |