Libraryless. Click here for Pure Java version (1912L/12K/43K).
1 | !752 |
2 | |
3 | sclass Tag {
|
4 | S name; |
5 | } |
6 | |
7 | sclass SlackMsg {
|
8 | S user, botName; // one of these is going to be set |
9 | S userName; // looked up if user != null |
10 | S type, text, ts; |
11 | O reactions; |
12 | S channelID; |
13 | |
14 | int index; |
15 | new TreeSet<S> tags; |
16 | } |
17 | |
18 | static PersistentMap<S, L<Tag>> tagMap; |
19 | static PersistentLog<SlackMsg> msgs; |
20 | static new L<SlackMsg> taggedMsgs; |
21 | static new TreeMap<Integer, SlackMsg> msgsByIndex; |
22 | static new MultiMap<S, SlackMsg> msgsByTag; |
23 | |
24 | p {
|
25 | tagMap = new PersistentMap("#1002192", "tagsByTS.log");
|
26 | print("Tags: " + l(tagMap));
|
27 | |
28 | S channelName = "talkingbots"; |
29 | msgs = new PersistentLog("#1002185", parseChannelName(channelName) + ".msgs");
|
30 | print("Msgs: " + l(msgs));
|
31 | if (empty(tagMap) || empty(msgs)) fail("no data");
|
32 | |
33 | //printStructure(last(msgs)); |
34 | |
35 | // put tags and index in messages |
36 | int n = 1; |
37 | for (SlackMsg msg : msgs) {
|
38 | L<Tag> tags = tagMap.get(msg.ts); |
39 | /*if (nempty(tags)) |
40 | print(structure(tags) + " " + structure(msg));*/ |
41 | msg.index = n++; |
42 | msgsByIndex.put(msg.index, msg); |
43 | for (Tag t : unnull(tags)) {
|
44 | if (msg.tags.add(t.name)) |
45 | msgsByTag.put(t.name, msg); |
46 | } |
47 | if (nempty(msg.tags)) |
48 | taggedMsgs.add(msg); |
49 | } |
50 | |
51 | print(l(taggedMsgs) + " tagged msgs."); |
52 | |
53 | for (SlackMsg msg : taggedMsgs) {
|
54 | for (S tag : msg.tags) {
|
55 | if (tag.startsWith("@") && isInteger(tag.substring(1))) pcall {
|
56 | int i = parseInt(tag.substring(1)); |
57 | if (i < 0) i += msg.index; |
58 | SlackMsg m2 = msgsByIndex.get(i); |
59 | S t2 = m2 == null ? "NOT FOUND" : m2.userName + ": " + m2.text; |
60 | S t1 = msg.userName + ": " + msg.text; |
61 | //print(msg.text + " => " + (m2 == null ? "NOT FOUND" : m2.text)); |
62 | print(t2); |
63 | print(" " + t1);
|
64 | print(); |
65 | } |
66 | } |
67 | } |
68 | |
69 | print("Bot greetings: " + structure(collect(msgsByTag.get("bot greeting"), "text")));
|
70 | } |
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: | #1003042 |
| Snippet name: | Load Slack log & tags |
| Eternal ID of this version: | #1003042/1 |
| Text MD5: | 9b9889358b833afa572ab6bfcb872642 |
| Transpilation MD5: | 3baa3e36b5ea4f8720ceb9a23f015580 |
| Author: | stefan |
| Category: | javax |
| Type: | JavaX source code |
| Public (visible to everyone): | Yes |
| Archived (hidden from active list): | No |
| Created/modified: | 2016-04-25 16:01:07 |
| Source code size: | 1934 bytes / 70 lines |
| Pitched / IR pitched: | No / No |
| Views / Downloads: | 864 / 977 |
| Referenced in: | [show references] |