Libraryless. Click here for Pure Java version (10026L/69K/224K).
1 | !7 |
2 | |
3 | static Env env; |
4 | static new ThreadLocal<Session> session; |
5 | static ThreadLocal<L<S>> buttons = new ThreadLocal; |
6 | static Map<S, Int> spellMap; |
7 | |
8 | static interface Env { |
9 | void sayAsync(S session, S msg); |
10 | } |
11 | |
12 | concept Session { |
13 | S cookie; |
14 | S lastQuestion; |
15 | } |
16 | |
17 | sbool debug; |
18 | |
19 | svoid setSession(S cookie) { |
20 | session.set(uniq_sync(Session, +cookie)); |
21 | } |
22 | |
23 | svoid clearSession(S cookie) { |
24 | deleteConcepts(Session, +cookie); |
25 | } |
26 | |
27 | p { |
28 | db(); |
29 | |
30 | // load stuff |
31 | spellMap = loadSpellList(#1008389); |
32 | //printStruct(spellMap); |
33 | |
34 | veryBigConsole(); |
35 | bot(); |
36 | } |
37 | |
38 | sS returnQuestion(S q) { |
39 | cset(session!, lastQuestion := q); |
40 | ret q; |
41 | } |
42 | |
43 | sS answer(S s) { |
44 | if (session! == null) setSession("default"); |
45 | buttons.set(null); |
46 | if (creator() == null) if "debug" set debug; |
47 | |
48 | S lq = session->lastQuestion; |
49 | cset(session!, lastQuestion := null); |
50 | |
51 | if (eq(lq, "Would you like some tea?")) { |
52 | if "yes" ret "Here's your tea."; |
53 | if "no" ret "Very well then."; |
54 | } |
55 | |
56 | if "test buttons" { |
57 | buttons.set(ll("Yes", "No")); |
58 | ret returnQuestion("Would you like some tea?"); |
59 | } |
60 | |
61 | if "say something later" { |
62 | if (env == null) ret("No env"); |
63 | final S mySession = session->cookie; |
64 | thread { |
65 | sleepSeconds(5); |
66 | env.sayAsync(mySession, "Here it is."); |
67 | } |
68 | ret "OK, will do it in 5 seconds"; |
69 | } |
70 | |
71 | S _s = s; |
72 | s = levenAttract(spellMap, s); |
73 | if (neqic(s, _s)) print("Spell-correct => " + s); |
74 | |
75 | ret "Sorry, I didn't understand that"; |
76 | } |
77 | |
78 | sS initialMessage() { |
79 | ret "Your personal bot here. " + returnQuestion("How can I help you?"); |
80 | } |
Began life as a copy of #1008347
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: | #1013897 |
Snippet name: | Google Login Thought Bot [dev.] |
Eternal ID of this version: | #1013897/5 |
Text MD5: | 5853c87e304d843de92f1e66b08cb03f |
Transpilation MD5: | 966b0570e2b51097824ac7464d694193 |
Author: | stefan |
Category: | javax / a.i. |
Type: | JavaX source code |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2018-03-14 14:54:47 |
Source code size: | 1624 bytes / 80 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 420 / 880 |
Version history: | 4 change(s) |
Referenced in: | [show references] |