Uses 1319K of libraries. Click here for Pure Java version (13387L/73K).
1 | !7 |
2 | |
3 | cmodule DiscordFan > DynPrintLogAndEnabled { |
4 | transient Map<S, BWImage> protos = syncCIMap(); |
5 | ISegmenter segmenter; |
6 | transient new ScreenShooter shooter; |
7 | transient ReliableSingleThread rstSegment = dm_rst(module(), r segment); |
8 | transient ReliableSingleThread rstAOA = dm_rst(module(), r aoa); |
9 | transient ImageInfo info; |
10 | transient ImageInfo latestWithAOA; |
11 | transient ImageSurface isThings; |
12 | transient double minScore = 95; |
13 | transient new Thinker thinker; |
14 | switchable double waitBeforeClick = 1.0; |
15 | switchable double patience = 1.0; |
16 | |
17 | sclass Segment { |
18 | Rect rect; |
19 | BWImage bw; |
20 | |
21 | *() {} |
22 | *(Rect *rect) {} |
23 | } |
24 | |
25 | sclass ImageInfo { |
26 | BufferedImage image; |
27 | L<Segment> segments; |
28 | new AOA_CompareImagesToProtos aoa; |
29 | Map<S, Segment> foundProtos; |
30 | } |
31 | |
32 | visual jvsplit( |
33 | jCenteredSection("Things found on screen", jscroll_center(isThings = jDoubleBufferedImageSurface())), |
34 | super); |
35 | |
36 | start-thread { |
37 | dm_watchFieldAndNow enabled(r { set(shooter, +enabled) }); |
38 | if (empty(protos)) |
39 | putAll(protos, mapValues loadBWImage(imageSnippetIDsForNames(llQuoted("Open", "Open discord")))); |
40 | print("Have " + n2(protos, "proto")); |
41 | if (segmenter == null) |
42 | setField(segmenter := segmenterFromAGIBlue("Find things on discordapp.com #1")); |
43 | print("Have segmenter: " + segmenter); |
44 | |
45 | shooter.onNewImage.add(rstSegment); |
46 | shooter.start(enter := f<AutoCloseable> enter); |
47 | doEvery(1.0, rEnter { thinker.think() }); |
48 | } |
49 | |
50 | void segment { |
51 | BufferedImage img = shooter.latestImage; |
52 | if (!enabled || img == null || segmenter == null) ret; // man weiß ja nie... |
53 | |
54 | // Have picture!! |
55 | long time = sysNow(); |
56 | new ImageInfo info; |
57 | info.image = img; |
58 | info.segments = map(segmenter.get(img), r -> new Segment(r)); |
59 | this.info = info; |
60 | done2_always(time, "Make " + nSegments(info.segments)); |
61 | rstAOA.trigger(); |
62 | } |
63 | |
64 | void aoa { |
65 | ImageInfo info = this.info; |
66 | if (info == null) ret; // man weiß ja nie... |
67 | |
68 | long time = sysNow(); |
69 | AOA_CompareImagesToProtos aoa = info.aoa; |
70 | aoa.addProtos(protos); |
71 | for (Segment s : info.segments) |
72 | s.bw = toBWImage(bufferedImageClip(info.image, s.rect)); |
73 | aoa.addImages(iotaKeys_str(collect bw(info.segments))); |
74 | stepAll(aoa); |
75 | |
76 | Map<S, Scored<S>> bestImageForProto = aoa.bestImageForProto; |
77 | Map<S, Scored<S>> foundProtos1 = filterMapByValuePredicate(bestImageForProto, v -> score(v) >= minScore/100); |
78 | //print(+foundProtos1); |
79 | Map<S, Segment> foundProtos = ciMap(); |
80 | for (S proto, Scored<S> scoredImage : foundProtos1) |
81 | mapPut(foundProtos, proto, getStartingWith1(info.segments, parseInt(scoredImage!))); |
82 | info.foundProtos = foundProtos; |
83 | |
84 | //print('foundProtos, info.foundProtos); |
85 | if (isThings != null) isThings.setImage( |
86 | mergeBWImagesHorizontally(map bwInverted(collect bw(values(info.foundProtos))))); |
87 | print(mapValues doubleScoreAsIntPercent(bestImageForProto)); |
88 | latestWithAOA = info; |
89 | done2_always("AOA", time); |
90 | } |
91 | |
92 | class Thinker { |
93 | WaitForStableValue<Rect> wait = new(patience); |
94 | |
95 | void think { |
96 | //print("think " + enabled); |
97 | if (!enabled) ret; |
98 | ImageInfo info = latestWithAOA; |
99 | if (info == null) ret; // man weiß ja nie... |
100 | //print("Keys", sfu(keys(info.foundProtos))); |
101 | Segment s = mapGet(info.foundProtos, quote("Open discord")); |
102 | Rect r = s == null ? null : s.rect; |
103 | print(+r); |
104 | if (wait.set(r) != null) { |
105 | print("Moving mouse to Discord button!!!!"); |
106 | O mover = vmBus_query mouseMover(); |
107 | if (mover == null) ret with print("No mover"); |
108 | callWithImportExport(mover, 'moveMouse, centerOfRect(wait!)); |
109 | print("MOVED"); |
110 | long startTime = sysNow(); |
111 | while (licensed() && sysNow() < startTime+toMS(waitBeforeClick)) { |
112 | if (!enabled) ret; |
113 | if (isTrue_rcall blocked(mover)) |
114 | ret with print("INTERFERENCE, EXITING"); |
115 | sleepSeconds(0.05); |
116 | } |
117 | // TODO: check mouse position |
118 | print("CLICKING!"); |
119 | rcall click(mover); |
120 | print("CLICKED!"); |
121 | wait.clear(); |
122 | } |
123 | } |
124 | } |
125 | |
126 | void cleanMeUp { |
127 | dispose shooter; |
128 | } |
129 | } |
download show line numbers debug dex old transpilations
Travelled to 6 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1024978 |
Snippet name: | Discord Fan [clicks madly on "Open Discord" button on discordapp.com, OK] |
Eternal ID of this version: | #1024978/66 |
Text MD5: | 42f615c1623dbfbeddcfa1372309b350 |
Transpilation MD5: | 73c0a37dbd267b25a44ddbd98db37b5c |
Author: | stefan |
Category: | javax / visual bots |
Type: | JavaX source code (Dynamic Module) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2019-09-01 14:55:43 |
Source code size: | 4344 bytes / 129 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 363 / 1280 |
Version history: | 65 change(s) |
Referenced in: | [show references] |