!7 !include #1005410 // Awareness Include static JLabel lblStatus; p { conceptsAndBot(); if (match("i am aware", sendToLocalBotOpt_original("Awareness Bot", "are you aware"))) { print("Has awareness."); ret; } awt { showControls(lblStatus = jlabel("Setting Up Awareness...")); awtOnConceptChanges(lblStatus, 1000, f updateStatus); installTimer(lblStatus, 30000, f updateStatus); componentPopupMenu(lblStatus, voidfunc(JPopupMenu menu) { for (final MachineInfo info : findConcepts(MachineInfo, "me", false)) { if (!validPeer(info) || eq(osName(info), "Android")) continue; // Remote PC popup items follow addMenuItem(menu, "Grab clipboard from " + info.ip, r { S s = sendToAwareness(info.ip, "get clipboard"); if (nempty(s) && neq(s, "empty or unknown")) { L l = cast safeUnstructure(s); S type = cast first(l); if (eq(type, "text")) { S text = (S) l.get(1); copyTextToClipboard(text); print("Copied text to clipboard: " + quote(shorten(text, 100))); } else if (eq(type, "png")) { copyImageToClipboard(fromPNG((byte[]) l.get(1))); print("Copied image to clipboard."); } else print("Unknown clipboard type: " + type); } }); addMenuItem(menu, "Grab screenshot from " + info.ip, r { S s = sendToAwareness(info.ip, "screenshot"); if (startsWith(s, "[")) { L l = cast safeUnstructure(s); S type = cast first(l); if (eq(type, "png")) { BufferedImage img = fromPNG((byte[]) l.get(1)); showImage("Screenshot from " + info.ip + " at " + ymd_hms(), img); } } }); } }); } print("Yo Setting Up Awareness..."); makeBot("Awareness Bot."); phonePublicCommBot(); // works for PCs too findBot_timeout = 1000*60; pingThread(null); print("Awareness Set Up!"); printMyIPs(); scanSubnet(); } answer { if "are you aware" ret "i am aware"; if "Ping" ret "pong"; /*if "say in english *" { thread "Speaking" { androidSayInEnglish(m.unq(0)); } ret "OK"; } if "say in english now *" { androidSayInEnglish(m.unq(0)); ret "OK"; }*/ try answer fileOpBot(s); if "please eval java *" ret "ok " + structure(evalJava($1)); if "please eval java fresh *" ret "ok " + structure(evalJavaFresh($1)); if "list other pcs" ret structure(otherPCs()); try answer awarenessBot(s); try answer clipboardBot(s); try answer screenshotBot(s); //try answer proxyBot(s); } sbool validPeer(MachineInfo info) { if (!info.aware || info.computerID == null) false; if (info.lastChecked < now()-l(pinging)*pingLoopInterval*2*1000) false; true; } sS osName(MachineInfo info) { ret contains(info.bots, "Dex Bot.") ? "Android" : info.os; } svoid updateStatus { new L l; for (MachineInfo info : concatLists( findConcepts(MachineInfo, "me", true), findConcepts(MachineInfo, "me", false))) { if (!validPeer(info)) continue; l.add(info.ip + ": " + /*info.computerID*/ osName(info) + (info.me ? " [me]" : "")); } S text = isEmpty(l) ? "Looking for peers" : n(l, "machine") + ": " + join(", ", l); lblStatus.setText(text); } svoid scanSubnet { pcall { S ip = getMyIP(); int i = ip.lastIndexOf('.'); if (i < 0) ret; print("Scanning my subnet..."); for (int n = 1; n <= 255; n++) { S peer = substring(ip, 0, i+1) + n; pcall { if (!pinging.contains(peer)) { print("Trying " + peer); if (isAware(peer)) addPeers(ll(peer)); } } } print("Subnet scanned."); } } static L otherPCs() { new L ips; for (final MachineInfo info : findConcepts(MachineInfo, "me", false)) if (validPeer(info) && neq(osName(info), "Android")) ips.add(info.ip); ret ips; }