Libraryless. Click here for Pure Java version (1244L/9K/29K).
1 | !752 |
2 | |
3 | static S chatName = "Eleu"; |
4 | static int maxAnswerLength = 300; |
5 | |
6 | p {
|
7 | thread "Web Chat Bot" { toChat(); }
|
8 | } |
9 | |
10 | static void toChat() {
|
11 | while (licensed()) {
|
12 | pcall {
|
13 | for (ChatLine l : suckHumans(chatName)) |
14 | sayInWebChat(chatName, _answer(l)); |
15 | } |
16 | sleep(1000); |
17 | } |
18 | } |
19 | |
20 | static S _answer(ChatLine l) {
|
21 | S s = l.text; |
22 | s = s.trim(); |
23 | // if (s.startsWith("!"))
|
24 | ((ThreadLocal) get(getMainBot(), "attn")).set(true); |
25 | s = dropPrefix("!", s);
|
26 | |
27 | ((ThreadLocal) get(getMainBot(), "userName")).set(l.auth ? "stefanreich" : null); // hack for authing |
28 | |
29 | S a = askSelf(s); |
30 | if (empty(a)) ret null; |
31 | S userName = l.who; |
32 | |
33 | // post long stuff to tinybrain instead |
34 | if (l(a) > maxAnswerLength) {
|
35 | S q = s; |
36 | S title = "Answer for " + userName + " (>> " + q + ")"; |
37 | S id = ntUpload("eleutheria-for-user", title, unSlackSnippet(a));
|
38 | int shortenTo = maxAnswerLength; |
39 | a = shorten(a, shortenTo) + "\nFull answer here: #" + parseSnippetID(id); |
40 | } |
41 | |
42 | ret a = "@" + l.who + " " + a; |
43 | } |
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: | #1002878 |
| Snippet name: | Eleu Web Chat Bot |
| Eternal ID of this version: | #1002878/1 |
| Text MD5: | 1c4a7be55c1da6513ecbe3717d49e774 |
| Transpilation MD5: | ec02e8296f91a5058761ed2dd35ed1e0 |
| Author: | stefan |
| Category: | |
| Type: | JavaX source code |
| Public (visible to everyone): | Yes |
| Archived (hidden from active list): | No |
| Created/modified: | 2016-03-12 15:56:16 |
| Source code size: | 1058 bytes / 43 lines |
| Pitched / IR pitched: | No / No |
| Views / Downloads: | 845 / 1056 |
| Referenced in: | [show references] |