Libraryless. Click here for Pure Java version (2657L/18K/56K).
1 | !752 |
2 | |
3 | // must be run together with sub-bot #1002677 (IRC Log Bot) |
4 | |
5 | static PersistentMap<S, S> tagsByTS; |
6 | |
7 | p { |
8 | tagsByTS = new PersistentMap("tagsByTS.log"); |
9 | makeBot("Slack Tagger Bot!!"); |
10 | } |
11 | |
12 | synchronized answer { |
13 | /*if match "get tags for msg *" { |
14 | S msgID = m.unq(0); |
15 | L<Tag> tags = tagsByTS.get(msgID); |
16 | if (empty(tags)) |
17 | ret "No tags for that msg"; |
18 | else |
19 | ret structure(tags); |
20 | }*/ |
21 | } |
22 | |
23 | static S html(S uri, Map<S, S> params) { |
24 | L<S> keepFields = litlist("channel", "n"); |
25 | |
26 | //S channelName = formatChannelName(or(params.get("channel"), "##linux")); |
27 | S channelName = "freenode"; // rather the network name... |
28 | O slurper = getBot("#1002677"); |
29 | L log = cast call(slurper, "getLog", channelName); |
30 | |
31 | boolean canEdit = master(); |
32 | |
33 | if (canEdit) |
34 | for (S key : keys(params)) |
35 | if (key.startsWith("tag_")) { |
36 | S ts = dropPrefix("tag_", key); |
37 | S val = params.get(key); |
38 | tagsByTS.put(ts, val); |
39 | } |
40 | |
41 | new L data; |
42 | int n; |
43 | if (!empty(params.get("n"))) |
44 | n = parseInt(params.get("n")); |
45 | else |
46 | n = max(0, l(log)-1)/100*100; |
47 | for (int i = n; i < min(n+100, l(log)); i++) { |
48 | O o = log.get(i); |
49 | S line = getString(o, "line"); |
50 | O ts = get(o, "time"); |
51 | if (ts == null || line == null) continue; |
52 | ts = str(ts); |
53 | |
54 | int i1 = line.indexOf(' '); |
55 | if (i1 < 0) continue; |
56 | int i2 = line.indexOf(' ', i1+1); |
57 | if (i2 < 0) continue; |
58 | S code = line.substring(i1+1, i2); |
59 | if (!eq(code, "PRIVMSG")) continue; |
60 | |
61 | S text = dropPrefix(":", dropUntilSpace(line.substring(i2+1))); |
62 | |
63 | S tag = tagsByTS.get(ts); |
64 | |
65 | // Pure text fields |
66 | |
67 | Map map = htmlencode(litmap( |
68 | "Timestamp", ts, |
69 | //"Line", get(o, "line"), |
70 | "#", i+1 |
71 | )); |
72 | |
73 | // Fields with actual HTML |
74 | |
75 | map.put("Text & Simplification", |
76 | htmlencode(text) + "<br>" + |
77 | htag("input", "", "type", "text", "name", "tag_" + ts, "value", or(tag, text), "style", "width: 100%")); |
78 | |
79 | /*if (mcBot != null) pcall { |
80 | L mc = cast call(mcBot, "listMiniChat", "dc" + ts); |
81 | new L<S> miniChat; |
82 | for (O _m : mc) { |
83 | McMsg m = cast restructure(_m); |
84 | miniChat.add(htmlencode(m.user + ": " + m.text)); |
85 | } |
86 | map.put("Mini-Chat", join("<br>", miniChat)); |
87 | }*/ |
88 | |
89 | data.add(map); |
90 | } |
91 | |
92 | new StringBuilder buf; |
93 | S title = "Tagging " + channelName; |
94 | buf.append(htag("title", title)); |
95 | buf.append(htag("h3", title)); |
96 | |
97 | // navigation |
98 | new L<S> l; |
99 | for (int i = 0; i < l(log); i += 100) |
100 | l.add(htag("a", str(i/100+1), "href", selfLink(params, keepFields, "n", str(i)))); |
101 | buf.append(htag("p", "Pages: " + join("\n", l))); |
102 | |
103 | if (canEdit) |
104 | buf.append(htag("p","You are clear to edit.")); |
105 | |
106 | S formContents = ""; |
107 | formContents += p(htag("input", "", "type", "submit", "value", "Submit!")); |
108 | formContents += htmlTable(data, false); |
109 | formContents += hiddenFields(params, keepFields); |
110 | formContents += p(htag("input", "", "type", "submit", "value", "Submit!")); |
111 | buf.append(htag("form", formContents, "method", "POST")); |
112 | ret str(buf); |
113 | } |
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: | 600 / 5272 |
Referenced in: | [show references] |