!7

cmodule DiscordFan > DynVisualBot {
  switchable double patience = 1.0;
  switchable double waitBeforeClick = 1.0;
  transient WaitForStableValue<Rect> wait = new(patience);
  
  // What are we looking for?
  void makeProtos {
    protoTexts("Open", "Open discord");
  }

  // How do we find it?
  ISegmenter makeSegmenter() {
    ret segmenterFromAGIBlue("Find things on discordapp.com #1");
  }
  
  // What do we do when we found it?
  void think {
    if (!enabled) ret;
    ImageInfo info = latestWithAOA, ret if null;
    //print("Keys", sfu(keys(info.foundProtos)));
    Rect r = print('r, rect(mapGet(info.foundProtos, quote("Open discord"))));
    dm_moveMouseAndClick(wait.setAndClear(r), "Discord button", +waitBeforeClick);
  }
  
  // Heart beat!
  void started { doEvery(1.0, rEnter think); }
}