Libraryless. Click here for Pure Java version (2532L/17K/56K).
1 | !752 |
2 | |
3 | static Class receivingBot; |
4 | static int delay = 3000; // fast // 10000; |
5 | static boolean keepPreSpunVM = false; |
6 | |
7 | static new L<S> acceptedProgramIDs; // none unless you change it |
8 | |
9 | p { |
10 | readLocally("acceptedProgramIDs"); |
11 | makeAndroid3("Accept incoming bots bot."); |
12 | |
13 | if (keepPreSpunVM) |
14 | runInNewThread("#1001379"); |
15 | |
16 | while (true) { |
17 | pcall { doIt(); } |
18 | sleep(delay); |
19 | } |
20 | } |
21 | |
22 | static void doIt() { |
23 | S answer = sendToRemoteBot("Identity Manager", format3("Who is moving to * (full state)", getComputerID())); |
24 | print(answer); |
25 | |
26 | processIncoming(answer); |
27 | } |
28 | |
29 | static synchronized void processIncoming(S answer) { |
30 | for (DynamicObject state : (L<DynamicObject>) unstructure(answer)) { |
31 | print("State: " + structure(state)); |
32 | |
33 | S botID = cast state.fieldValues.get("id"); |
34 | S dataID = cast state.fieldValues.get("dataID"); |
35 | |
36 | if (!acceptedProgramIDs.contains(formatSnippetID(botID))) { |
37 | print("Rejecting bot " + botID + "."); |
38 | print(sendToRemoteBot("Identity Manager", format3("* is now in state *", botID, "rejected"))); |
39 | continue; |
40 | } else |
41 | print("OK, accepting bot " + botID + " as per white list."); |
42 | |
43 | try { |
44 | if (receivingBot == null) |
45 | receivingBot = hotwire("#1001337"); |
46 | |
47 | answer = (S) call(receivingBot, "doIt", botID, dataID); |
48 | print(answer); |
49 | if (!match3("All done.", answer)) |
50 | continue; |
51 | |
52 | print(sendToRemoteBot("Identity Manager", format3("* is now in state *", botID, "residing"))); |
53 | } catch (Throwable e) { |
54 | e.printStackTrace(); |
55 | print(sendToRemoteBot("Identity Manager", format3("* is now in state *", botID, "error: " + getStackTrace(e)))); |
56 | } |
57 | } |
58 | } |
59 | |
60 | static synchronized S answer(S s, L<S> history) { |
61 | new Matches m; |
62 | |
63 | if (match3("please accept bot * from now on", s, m)) { |
64 | S id = formatSnippetID(unquote(m.m[0])); |
65 | if (!acceptedProgramIDs.contains(id)) { |
66 | acceptedProgramIDs.add(id); |
67 | saveLocally("acceptedProgramIDs"); |
68 | } |
69 | ret "OK."; |
70 | } |
71 | |
72 | if (match3("please reject bot * from now on", s, m)) { |
73 | S id = formatSnippetID(unquote(m.m[0])); |
74 | acceptedProgramIDs.remove(id); |
75 | saveLocally("acceptedProgramIDs"); |
76 | ret "OK."; |
77 | } |
78 | |
79 | if (match3("would you accept bot *?", s, m)) { |
80 | S id = formatSnippetID(unquote(m.m[0])); |
81 | return acceptedProgramIDs.contains(id) ? "Yes." : "No."; |
82 | } |
83 | |
84 | if (match3("show white list", s)) |
85 | return structure(acceptedProgramIDs); |
86 | |
87 | ret null; |
88 | } |
Began life as a copy of #1001357
download show line numbers debug dex old transpilations
Travelled to 16 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, dhtvkmknsjym, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, teubizvjbppd, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1001385 |
Snippet name: | Accept incoming bots bot (with white list) |
Eternal ID of this version: | #1001385/1 |
Text MD5: | 637cce1e264c128b4fdfce69b6543bdf |
Transpilation MD5: | 74304e3e82e23792d6d8eee08b919f16 |
Author: | stefan |
Category: | javax |
Type: | JavaX source code |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2016-05-17 13:53:12 |
Source code size: | 2553 bytes / 88 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 666 / 820 |
Referenced in: | [show references] |