Libraryless. Click here for Pure Java version (1858L/13K/41K).
1 | !752 |
2 | |
3 | // must be run together with sub-bot #1002185 (queries the |
4 | // slack slurper's database) |
5 | |
6 | static class SlackMsg { |
7 | S user, botName; // one of these is going to be set |
8 | S userName; // looked up if user != null |
9 | S type, text, ts; |
10 | O reactions; |
11 | S channelID; |
12 | } |
13 | |
14 | static O mainBot; |
15 | |
16 | p { |
17 | makeBot("Slack Answerer (about msgs)"); |
18 | } |
19 | |
20 | synchronized answer { |
21 | O slurper = getBot("#1002185"); |
22 | |
23 | if (match("what was the * msg in #*", s, m) |
24 | || match("what was msg * in #*", s, m)) exceptionToUser { |
25 | S what = m.unq(0); |
26 | S channelName = "#" + m.unq(1); |
27 | List log = cast call(slurper, "getLog", channelName); |
28 | if (empty(log)) |
29 | ret "The channel is empty or unslurped."; |
30 | O e; |
31 | try { |
32 | int i = elementIndexFromNL(log, what); |
33 | e = get(log, i); |
34 | } catch (Throwable x) { |
35 | ret exceptionToUser(x); |
36 | } |
37 | ret e == null ? "No msg found, sorry" : structure(e); // structure of msg |
38 | } |
39 | |
40 | if "how many messages in *" exceptionToUser { |
41 | S channelName = "#" + m.unq(0); |
42 | List log = cast call(slurper, "getLog", channelName); |
43 | ret lstr(log); |
44 | } |
45 | } |
46 | |
47 | static int elementIndexFromNL(L l, S s) { |
48 | new Matches m; |
49 | |
50 | // matches stuff like "5" or "5th" or "52nd" |
51 | S n = get(javaTok(s), 1); |
52 | if (isInteger(n)) |
53 | ret parseInt(n)-1; |
54 | |
55 | // matching on s |
56 | |
57 | if "first" ret 0; |
58 | if "last" ret l(l)-1; |
59 | if "second" ret 1; |
60 | if "second to last" ret l(l)-2; |
61 | |
62 | throw fail("What is " + quote(s) + "?"); |
63 | } |
Began life as a copy of #1002185
download show line numbers debug dex old transpilations
Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1002190 |
Snippet name: | Slack Answerer |
Eternal ID of this version: | #1002190/1 |
Text MD5: | e749b075d44900e2c93efac044070f07 |
Transpilation MD5: | e23dccc9631a0a344946a539217f0939 |
Author: | stefan |
Category: | javax |
Type: | JavaX source code |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2016-02-20 20:29:23 |
Source code size: | 1506 bytes / 63 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 785 / 2101 |
Referenced in: | [show references] |