Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

66
LINES

< > BotCompany Repo | #1025026 // Discord Fan [shortened]

JavaX source code (Dynamic Module) [tags: use-pretranspiled] - run with: Stefan's OS

Uses 1319K of libraries. Click here for Pure Java version (13516L/74K).

!7

cmodule DiscordFan > DynPrintLogAndEnabled {
  transient Map<S, BWImage> protos = syncCIMap();
  ISegmenter segmenter;
  transient autoDispose new ScreenShooter shooter;
  transient ReliableSingleThread rstSegment = dm_rst(module(), r segment);
  transient ReliableSingleThread rstAOA = dm_rst(module(), r aoa);
  transient ImageInfo info, latestWithAOA;
  transient ImageSurface isThings;
  transient double minScore = 95;
  transient new Thinker thinker;
  switchable double waitBeforeClick = 1.0;
  switchable double patience = 1.0;
  
  sclass Segment extends BWImageAndRect { *() {} *(Rect r) { super(r); } }
  sclass ImageInfo extends ImageWithProtos<Segment> {}
  
  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...
    this.info = (ImageInfo) imageWithProtos_segment(segmenter, img,
      iwpClass := ImageInfo.class, segmentClass := Segment.class);
    rstAOA.trigger();
  }
  
  void aoa {
    ImageInfo info = this.info;
    if (info == null) ret;
    imageWithProtos_doAllOnAll(info, protos, +minScore, +isThings);
    latestWithAOA = info;
  }
  
  class Thinker {
    WaitForStableValue<Rect> wait = new(patience);
    
    void think {
      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);
      dm_moveMouseAndClick(wait.setAndClear(r), "Discord button");
    }
  }
}

Author comment

Began life as a copy of #1024978

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: #1025026
Snippet name: Discord Fan [shortened]
Eternal ID of this version: #1025026/15
Text MD5: fae5b1992fdc57df00b1af87d31feade
Transpilation MD5: 6fde94a11ef3dd79094c1904b1a959af
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 19:25:14
Source code size: 2379 bytes / 66 lines
Pitched / IR pitched: No / No
Views / Downloads: 305 / 465
Version history: 14 change(s)
Referenced in: #1025035 - DynVisualBot [continuous screenshots, searches for protos]
#1025036 - Discord Fan [shortened 2]