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

113
LINES

< > BotCompany Repo | #1002679 // IRC Simplifying

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

Libraryless. Click here for Pure Java version (2657L/18K/56K).

!752

// must be run together with sub-bot #1002677 (IRC Log Bot)

static PersistentMap<S, S> tagsByTS;

p {
  tagsByTS = new PersistentMap("tagsByTS.log");
  makeBot("Slack Tagger Bot!!");
}

synchronized answer {
  /*if match "get tags for msg *" {
    S msgID = m.unq(0);
    L<Tag> tags = tagsByTS.get(msgID);
    if (empty(tags))
      ret "No tags for that msg";
    else
      ret structure(tags);
  }*/
}

static S html(S uri, Map<S, S> params) {
  L<S> keepFields = litlist("channel", "n");
  
  //S channelName = formatChannelName(or(params.get("channel"), "##linux"));
  S channelName = "freenode"; // rather the network name...
  O slurper = getBot("#1002677");
  L log = cast call(slurper, "getLog", channelName);
  
  boolean canEdit = master();
  
  if (canEdit)
    for (S key : keys(params))
      if (key.startsWith("tag_")) {
        S ts = dropPrefix("tag_", key);
        S val = params.get(key);
        tagsByTS.put(ts, val);
      }
      
  new L data;
  int n;
  if (!empty(params.get("n")))
    n = parseInt(params.get("n"));
  else
    n = max(0, l(log)-1)/100*100;
  for (int i = n; i < min(n+100, l(log)); i++) {
    O o = log.get(i);
    S line = getString(o, "line");
    O ts = get(o, "time");
    if (ts == null || line == null) continue;
    ts = str(ts);
    
    int i1 = line.indexOf(' ');
    if (i1 < 0) continue;
    int i2 = line.indexOf(' ', i1+1);
    if (i2 < 0) continue;
    S code = line.substring(i1+1, i2);
    if (!eq(code, "PRIVMSG")) continue;
    
    S text = dropPrefix(":", dropUntilSpace(line.substring(i2+1)));
    
    S tag = tagsByTS.get(ts);

    // Pure text fields
    
    Map map = htmlencode(litmap(
      "Timestamp", ts,
      //"Line", get(o, "line"),
      "#", i+1
    ));
    
    // Fields with actual HTML
    
    map.put("Text & Simplification",
      htmlencode(text) + "<br>" +
      htag("input", "", "type", "text", "name", "tag_" + ts, "value", or(tag, text), "style", "width: 100%"));
      
    /*if (mcBot != null) pcall {
      L mc = cast call(mcBot, "listMiniChat", "dc" + ts);
      new L<S> miniChat;
      for (O _m : mc) {
        McMsg m = cast restructure(_m);
        miniChat.add(htmlencode(m.user + ": " + m.text));
      }
      map.put("Mini-Chat", join("<br>", miniChat));
    }*/
      
    data.add(map);
  }
  
  new StringBuilder buf;
  S title = "Tagging " + channelName;
  buf.append(htag("title", title));
  buf.append(htag("h3", title));
  
  // navigation
  new L<S> l;
  for (int i = 0; i < l(log); i += 100)
    l.add(htag("a", str(i/100+1), "href", selfLink(params, keepFields, "n", str(i))));
  buf.append(htag("p", "Pages: " + join("\n", l)));
  
  if (canEdit)
    buf.append(htag("p","You are clear to edit."));
  
  S formContents = "";
  formContents += p(htag("input", "", "type", "submit", "value", "Submit!"));
  formContents += htmlTable(data, false);
  formContents += hiddenFields(params, keepFields);
  formContents += p(htag("input", "", "type", "submit", "value", "Submit!"));
  buf.append(htag("form", formContents, "method", "POST"));
  ret str(buf);
}

Author comment

Began life as a copy of #1002192

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1002679
Snippet name: IRC Simplifying
Eternal ID of this version: #1002679/1
Text MD5: 938bb3e3a5f963c051f4753a2e7a0fbe
Transpilation MD5: d88fbf5ce253fe3f0e3bd4f5238aad80
Author: stefan
Category: javax
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2016-02-13 04:22:12
Source code size: 3196 bytes / 113 lines
Pitched / IR pitched: No / No
Views / Downloads: 588 / 5256
Referenced in: [show references]