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

57
LINES

< > BotCompany Repo | #1003048 // Load Slack log & tags (include)

JavaX fragment (include)

1  
sclass Tag {
2  
  S name;
3  
}
4  
5  
sclass SlackMsg {
6  
  S user, botName; // one of these is going to be set
7  
  S userName; // looked up if user != null
8  
  S type, text, ts;
9  
  O reactions;
10  
  S channelID;
11  
  
12  
  int index;
13  
  new TreeSet<S> tags;
14  
}
15  
16  
static PersistentMap<S, L<Tag>> tagMap;
17  
static PersistentLog<SlackMsg> msgs;
18  
static new L<SlackMsg> taggedMsgs;
19  
static new TreeMap<Integer, SlackMsg> msgsByIndex;
20  
static new MultiMap<S, SlackMsg> msgsByTag;
21  
22  
static void init() {
23  
  tagMap = new PersistentMap("#1002192", "tagsByTS.log");
24  
  print("Tags: " + l(tagMap));
25  
  
26  
  S channelName = "talkingbots";
27  
  msgs = new PersistentLog("#1002185", parseChannelName(channelName) + ".msgs");
28  
  print("Msgs: " + l(msgs));
29  
  if (empty(tagMap) || empty(msgs)) fail("no data");
30  
  
31  
  //printStructure(last(msgs));
32  
  
33  
  // put tags and index in messages
34  
  int n = 1;
35  
  for (SlackMsg msg : msgs) {
36  
    L<Tag> tags = tagMap.get(msg.ts);
37  
    /*if (nempty(tags))
38  
      print(structure(tags) + " " + structure(msg));*/
39  
    msg.text = trim(msg.text);
40  
    msg.index = n++;
41  
    msgsByIndex.put(msg.index, msg);
42  
    for (Tag t : unnull(tags)) {
43  
      if (msg.tags.add(t.name))
44  
        msgsByTag.put(t.name, msg);
45  
    }
46  
    if (nempty(msg.tags))
47  
      taggedMsgs.add(msg);
48  
  }
49  
  
50  
  print(l(taggedMsgs) + " tagged msgs.");
51  
}
52  
53  
static void filterTag(S tag) {
54  
  for (SlackMsg msg : msgs) {
55  
    msg.tags = msg.tags.contains(tag) ? littreeset(tag) : main.<S> littreeset();
56  
  }
57  
}

Author comment

Began life as a copy of #1003042

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: #1003048
Snippet name: Load Slack log & tags (include)
Eternal ID of this version: #1003048/1
Text MD5: 3a35a73d3b1e120428342f8238065b23
Author: stefan
Category: eleu / nl
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2016-04-26 17:08:42
Source code size: 1488 bytes / 57 lines
Pitched / IR pitched: No / No
Views / Downloads: 551 / 769
Referenced in: [show references]