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

37
LINES

< > BotCompany Repo | #1001576 // suckWebChat

JavaX fragment (include)

static class ChatLine {
  int id, room;
  S who, text;
  boolean isBot, auth;
}
  
static int suckWebChat_lastID;
static long suckWebChat_lastSuck;
static int suckWebChat_room = 1;

static L<ChatLine> suckWebChat(S myName) {
  ret suckWebChat(myName, 1);
}

// suckFirst = how many lines to suck on startup (history)
static L<ChatLine> suckWebChat(S myName, int suckFirst) {
  if (now() < suckWebChat_lastSuck + 500)
    print("Warning: Sucking a lot :)");
  suckWebChat_lastSuck = now();
  int n = suckWebChat_lastID == 0 ? suckFirst : 1000;
  Map data = (Map) jsonDecode(loadPageSilently("tinybrain.de:8080/tb-int/groupchat.json.lines.php?room=" + suckWebChat_room + "&fromID=" + suckWebChat_lastID + "&n=" + n
    + "&who=" + urlencode(myName)));
  L<Map<S, S>> lines = (L) data.get("lines");
  new L<ChatLine> list;
  for (Map<S, S> m : lines) {
    new ChatLine l;
    l.who = m.get("who");
    l.text = m.get("text");
    l.isBot = "1".equals(m.get("bot"));
    l.auth = eq(m.get("auth"), "1");
    l.id = parseInt(m.get("id"));
    l.room = room;
    if (l.id > suckWebChat_lastID) suckWebChat_lastID = l.id;
    list.add(l);
  }
  ret list;
}

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: #1001576
Snippet name: suckWebChat
Eternal ID of this version: #1001576/1
Text MD5: b53f34fb567822ef58f9638d656220f0
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2016-03-31 19:40:01
Source code size: 1186 bytes / 37 lines
Pitched / IR pitched: No / No
Views / Downloads: 640 / 841
Referenced in: [show references]