1 | sclass BakedBot { |
2 | VirtualMechLists lists = new SimpleMechLists; |
3 | Class bot; |
4 | int goodTests, badTests; |
5 | static S defaultSnippetID = #1017706; |
6 | S snippetID = defaultSnippetID; |
7 | |
8 | *(VirtualMechLists *lists) { _init(); } |
9 | *() { _init(); } |
10 | |
11 | void _init { |
12 | bot = hotwireDependentSharingClasses(snippetID, VirtualMechLists); |
13 | setOpt(bot, mechLibID := null); |
14 | setOpt(bot, makeAndroid3_disable := true); |
15 | //lists.verbose = true; |
16 | setLists(lists); |
17 | runMain(bot); |
18 | } |
19 | |
20 | S answer(S s) { |
21 | ret unnull(callAnswerMethod(bot, s)); |
22 | } |
23 | |
24 | S answer_verbose(S s) { |
25 | ret print("< ", answer(print("> ", s))); |
26 | } |
27 | |
28 | S check(S input, S expectedOutput) { |
29 | ret assertEqualsVerbose_match(unnull(expectedOutput), answer(print("> ", input))); |
30 | } |
31 | |
32 | bool pcheck(S input, S expectedOutput) { |
33 | pcall-short { check(input, expectedOutput); ++goodTests; true; } |
34 | ++badTests; false; |
35 | } |
36 | |
37 | bool pcheckOrPrintLog(S input, S expectedOutput) { |
38 | if (pcheck(input, expectedOutput)) true; |
39 | ret false with printLines((LS) getOpt(getBot('TelegramFactsBot), 'checkingLog)); |
40 | } |
41 | |
42 | void setList(S name, S text) { |
43 | lists.setText(name, text); |
44 | } |
45 | |
46 | S getList(S name) { |
47 | ret lists.mL_raw(name); |
48 | } |
49 | |
50 | void setAuthorized(bool b) { |
51 | setOpt(bot, authorized := b); |
52 | } |
53 | |
54 | S answerAuthed(S s) { |
55 | final bool authedOld = isTrue(getOpt(bot, 'authorized)); |
56 | setAuthorized(true); |
57 | tempAfterwards(r { setAuthorized(authedOld); }); |
58 | ret answer(s); |
59 | } |
60 | |
61 | void setLists(VirtualMechLists lists) { |
62 | this.lists = lists; |
63 | setAll(callOpt(bot, 'mechMode), readMode := lists, writeMode := lists); |
64 | } |
65 | |
66 | O getBot(S shortClassName) { |
67 | ret firstWithShortClassName((L) get(bot, 'bots), shortClassName); |
68 | } |
69 | |
70 | void cleanMeUp { |
71 | cleanUp(bot); |
72 | bot = null; |
73 | } |
74 | |
75 | O factsBot() { |
76 | ret getBot('TelegramFactsBot); |
77 | } |
78 | |
79 | void addFact(S fact) { |
80 | if (!contains(lines(lists.mL_raw("Random facts")), fact)) |
81 | lists.append("Random facts", fact); |
82 | } |
83 | |
84 | void printTestStats { |
85 | print("\nGood tests: " + goodTests + ", bad tests: " + badTests + "\n"); |
86 | } |
87 | |
88 | void imagineMode() { |
89 | set(factsBot(), imagineMode := true); |
90 | } |
91 | |
92 | Collection<S> imaginedFacts() { |
93 | ret (Collection<S>) get(factsBot(), 'imaginedFacts); |
94 | } |
95 | |
96 | void useIterate(bool useIterate) { |
97 | set(factsBot(), +useIterate); |
98 | } |
99 | |
100 | void useDiskCache(bool useDiskCache) { |
101 | setOpt(bot, transpileRaw_useDiskCache := useDiskCache); |
102 | } |
103 | |
104 | void debug(bool debug) { |
105 | set(factsBot(), +debug); |
106 | } |
107 | |
108 | void setRules(S rules) { |
109 | if (lists cast SimpleMechLists) |
110 | lists.setText("NL Logic Examples", rules); |
111 | } |
112 | } |
Began life as a copy of #1017766
download show line numbers debug dex old transpilations
Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1017768 |
Snippet name: | BakedBot - uses in-memory mech lists by default |
Eternal ID of this version: | #1017768/44 |
Text MD5: | 9b3eaaac8d03f38065c674be2085f11a |
Author: | stefan |
Category: | javax / a.i. |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2018-10-30 12:27:34 |
Source code size: | 2756 bytes / 112 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 511 / 1190 |
Version history: | 43 change(s) |
Referenced in: | [show references] |