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

105
LINES

< > BotCompany Repo | #1002242 // Interest Points Bot (developing)

JavaX source code [tags: use-pretranspiled] - run with: x30.jar

Libraryless. Click here for Pure Java version (2125L/13K/46K).

!752

p {
  load("interestPoints");
  load("ipInfos");
  makeBot("Interest Points Bot");
}

static new L<S> interestPoints;

static new Map<S, IP> ipInfos;

static class Line {
  S user, text;
  S removedBy;
  
  *(S *user, S *text) {}
  *() {}
  
  public boolean equals(O o) {
    if (!(o instanceof Line)) ret false;
    Line l = cast o;
    ret eq(user, l.user) && eq(text, l.text);
  }
}

static class IP {
  S name;
  new L<S> bumpedBy;
  new L<Line> lines;
  new L<Line> removedLines;
  
  *(S *name) {}
  *() {}
  
  void addBumpedBy(S user) {
    if (user == null) ret;
    bumpedBy.remove(user);
    bumpedBy.add(user);
  }
}

synchronized answer {
  S user = getUserName();
  
  if (match("create interest point *", s, m) || match("open interest point *", s, m) || match("bump interest point *", s, m) || match("select interest point *", s, m)) {
    S point = m.unq(0);
    if (interestPoints.contains(point)) {
      if (eq(currentInterestPoint(), point))
        ret "Interest point already selected.";
      else {
        interestPoints.remove(point);
        interestPoints.add(0, point);
        getIpInfo(point).addBumpedBy(getUserName());
        save("ipInfos");
        save("interestPoints");
        ret format("Interest point * selected!", point);
      }
    }
    interestPoints.add(0, point);
    getIpInfo(point).addBumpedBy(user);
    save("ipInfos");
    save("interestPoints");
    ret format("OK, added & selected interest point *. Count now: *", point, l(interestPoints));
  }
  
  if "list interest points" {
    ret structure(interestPoints);
  }
  
  /*if "close interest point *" {
  }*/
  
  if (match("current interest point", s) || match("interest point", s)) {
    S ip = currentInterestPoint();
    ret ip == null ? "no interest point selected" : quote(ip);
  }
  
  if "show interest point" {
    ret structure(ipInfos.get(currentInterestPoint()));
  }
  
  if "add to *: *" { // TODO: actually match the colon
    S point = m.unq(0), text = m.unq(1);
    IP ip = ipInfos.get(point);
    if (ip == null) ret "Please create interest point first";
    Line l = new Line(user, text);
    if (ip.lines.contains(l))
      ret "Line already there!";
    ip.lines.add(l);
    save("ipInfos");
    ret "Line added as #" + l(ip.lines);
  }
}

static S currentInterestPoint() {
  ret first(interestPoints);
}

static IP getIpInfo(S point) {
  IP ip = ipInfos.get(point);
  if (ip == null)
    ipInfos.put(point, ip = new IP(point));
  ret ip;
}

download  show line numbers  debug dex  old transpilations   

Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1002242
Snippet name: Interest Points Bot (developing)
Eternal ID of this version: #1002242/1
Text MD5: 63af22063e0c340a53a9d15b509117bb
Transpilation MD5: 2957072031b0b32d382657c76168f2f8
Author: stefan
Category: nl bots
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2016-01-02 18:01:19
Source code size: 2582 bytes / 105 lines
Pitched / IR pitched: No / Yes
Views / Downloads: 616 / 1471
Referenced in: [show references]