Uses 1319K of libraries. Click here for Pure Java version (13387L/73K).
!7 cmodule DiscordFan > DynPrintLogAndEnabled { transient Map<S, BWImage> protos = syncCIMap(); ISegmenter segmenter; transient new ScreenShooter shooter; transient ReliableSingleThread rstSegment = dm_rst(module(), r segment); transient ReliableSingleThread rstAOA = dm_rst(module(), r aoa); transient ImageInfo info; transient ImageInfo latestWithAOA; transient ImageSurface isThings; transient double minScore = 95; transient new Thinker thinker; switchable double waitBeforeClick = 1.0; switchable double patience = 1.0; sclass Segment { Rect rect; BWImage bw; *() {} *(Rect *rect) {} } sclass ImageInfo { BufferedImage image; L<Segment> segments; new AOA_CompareImagesToProtos aoa; Map<S, Segment> foundProtos; } visual jvsplit( jCenteredSection("Things found on screen", jscroll_center(isThings = jDoubleBufferedImageSurface())), super); start-thread { dm_watchFieldAndNow enabled(r { set(shooter, +enabled) }); if (empty(protos)) putAll(protos, mapValues loadBWImage(imageSnippetIDsForNames(llQuoted("Open", "Open discord")))); print("Have " + n2(protos, "proto")); if (segmenter == null) setField(segmenter := segmenterFromAGIBlue("Find things on discordapp.com #1")); print("Have segmenter: " + segmenter); shooter.onNewImage.add(rstSegment); shooter.start(enter := f<AutoCloseable> enter); doEvery(1.0, rEnter { thinker.think() }); } void segment { BufferedImage img = shooter.latestImage; if (!enabled || img == null || segmenter == null) ret; // man weiß ja nie... // Have picture!! long time = sysNow(); new ImageInfo info; info.image = img; info.segments = map(segmenter.get(img), r -> new Segment(r)); this.info = info; done2_always(time, "Make " + nSegments(info.segments)); rstAOA.trigger(); } void aoa { ImageInfo info = this.info; if (info == null) ret; // man weiß ja nie... long time = sysNow(); AOA_CompareImagesToProtos aoa = info.aoa; aoa.addProtos(protos); for (Segment s : info.segments) s.bw = toBWImage(bufferedImageClip(info.image, s.rect)); aoa.addImages(iotaKeys_str(collect bw(info.segments))); stepAll(aoa); Map<S, Scored<S>> bestImageForProto = aoa.bestImageForProto; Map<S, Scored<S>> foundProtos1 = filterMapByValuePredicate(bestImageForProto, v -> score(v) >= minScore/100); //print(+foundProtos1); Map<S, Segment> foundProtos = ciMap(); for (S proto, Scored<S> scoredImage : foundProtos1) mapPut(foundProtos, proto, getStartingWith1(info.segments, parseInt(scoredImage!))); info.foundProtos = foundProtos; //print('foundProtos, info.foundProtos); if (isThings != null) isThings.setImage( mergeBWImagesHorizontally(map bwInverted(collect bw(values(info.foundProtos))))); print(mapValues doubleScoreAsIntPercent(bestImageForProto)); latestWithAOA = info; done2_always("AOA", time); } class Thinker { WaitForStableValue<Rect> wait = new(patience); void think { //print("think " + enabled); if (!enabled) ret; ImageInfo info = latestWithAOA; if (info == null) ret; // man weiß ja nie... //print("Keys", sfu(keys(info.foundProtos))); Segment s = mapGet(info.foundProtos, quote("Open discord")); Rect r = s == null ? null : s.rect; print(+r); if (wait.set(r) != null) { print("Moving mouse to Discord button!!!!"); O mover = vmBus_query mouseMover(); if (mover == null) ret with print("No mover"); callWithImportExport(mover, 'moveMouse, centerOfRect(wait!)); print("MOVED"); long startTime = sysNow(); while (licensed() && sysNow() < startTime+toMS(waitBeforeClick)) { if (!enabled) ret; if (isTrue_rcall blocked(mover)) ret with print("INTERFERENCE, EXITING"); sleepSeconds(0.05); } // TODO: check mouse position print("CLICKING!"); rcall click(mover); print("CLICKED!"); wait.clear(); } } } void cleanMeUp { dispose shooter; } }
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: | 361 / 1276 |
Version history: | 65 change(s) |
Referenced in: | [show references] |