Libraryless. Click here for Pure Java version (8819L/62K/194K).
1 | !7 |
2 | |
3 | !include #1007827 // Slack Bot |
4 | |
5 | sbool doSlack = true; |
6 | |
7 | static SelectBot<Bool> greetBot; |
8 | |
9 | p { |
10 | db(); |
11 | greetBot = uniq(SelectBot); |
12 | |
13 | slackSpeed = 1000; |
14 | if (doSlack) |
15 | initSlackBot(); |
16 | dediSay("Booting..."); |
17 | |
18 | dediSay("Yo, back online!"); |
19 | if (doSlack) |
20 | slackBotLoop(); |
21 | } |
22 | |
23 | answer { |
24 | s = trim(s); |
25 | if (eq(s, "!data")) |
26 | ret struct(greetBot); |
27 | if (eq(s, "!reload")) { |
28 | thread { sleepSeconds(2); restart(); } |
29 | ret "krasser reload"; |
30 | } |
31 | if (startsWithWord(s, "!greet", m)) { |
32 | greetBot.put($1, true); |
33 | ret "ok"; |
34 | } |
35 | if (startsWithWord(s, "!nogreet", m)) { |
36 | greetBot.put($1, false); |
37 | ret "ok"; |
38 | } |
39 | if (eq(s, "!source")) |
40 | ret progLink(); |
41 | if (eq(s, "!help")) |
42 | ret autoHelp(); |
43 | //if "hi celestia" ret "hi!"; |
44 | if (isTrue(greetBot.get(s))) |
45 | ret s + " => hi!"; |
46 | } |
47 | |
48 | sS autoHelp() { |
49 | new L<S> cmds; |
50 | L<S> tok = javaTokMe(); |
51 | for (S pat : toLinesFullTrim([[ |
52 | startsWithWord(s, <quoted>, |
53 | eq(s, <quoted>) |
54 | ]])) |
55 | for (int i : jfindAll(tok, pat)) |
56 | cmds.add(trim(unquote(tok.get(i+8)))); |
57 | ret "Commands: " + join(" ", cmds); |
58 | } |
download show line numbers debug dex old transpilations
Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, jtubtzbbkimh, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1007829 |
Snippet name: | Celestia Slack Bot [LIVE] - can recognize greetings and say "hi!" |
Eternal ID of this version: | #1007829/16 |
Text MD5: | 4f61c93e1fec86c4a777e62f134faf35 |
Transpilation MD5: | c54bff937faa306ed63c1f8a19ab3a20 |
Author: | stefan |
Category: | javax / slack bots |
Type: | JavaX source code |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2017-04-23 12:43:44 |
Source code size: | 1142 bytes / 58 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 654 / 1497 |
Version history: | 15 change(s) |
Referenced in: | [show references] |