Uses 4998K of libraries. Click here for Pure Java version (15364L/109K).
1 | !7 |
2 | |
3 | // cmodule fails because of loadPageWithUserAgent |
4 | module GBot > DynDiscordHopper { |
5 | S myName = "GBot"; |
6 | int defaultResults = 1; |
7 | Set<S> syntaxes = synchroSet(); |
8 | |
9 | @Override S answer(S input, Map map) { |
10 | ret mapEachLine_tlft_nempties(input, s -> { |
11 | print("Guild: " + map.get('guildID)); |
12 | |
13 | new Matches m; |
14 | |
15 | s = simpleSpaces_noTok(s); |
16 | s = regexpReplace_direct(s, "\\s+:", ":"); |
17 | |
18 | if (eqicOneOf(replaceIC(words2_spaces(s), " show ", " "), myName + " Help", myName + " info", myName + " commands")) |
19 | ret loadSnippet(#1024125); |
20 | |
21 | if (swic_trim(s, myName + ":", m)) |
22 | ret doIt(m.rest()); |
23 | |
24 | if (swic_trim(s, myName + " default results:", m)) { |
25 | setField(defaultResults := parseInt(m.rest()); |
26 | ret "OK, returning " + nResults(defaultResults) + " from now on"; |
27 | } |
28 | |
29 | if (eqic(s, myName + " default results")) |
30 | ret "I'm returning " + nResults(defaultResults) + " by default"; |
31 | |
32 | if (eqic(s, myName + " syntaxes")) |
33 | ret backtickQuote(lines_rtrim(elementPlusList(myName + ": ...", syntaxes))); |
34 | |
35 | if (swic_trim_any(s, m, myName + " new syntax:", myName + " add syntax:")) { |
36 | S syntax = massageSyntax(m.rest()); |
37 | if (!endsWithEllipsis(syntax)) |
38 | ret "Shouldn't this end with \"...\"? >> " + syntax; |
39 | if (!syntaxes.add(syntax)) ret "I already know that syntax!"; |
40 | change(); |
41 | ret "Syntax added! You can try: " + backtickQuote(replaceSuffix("...", randomThingToGoogle(), syntax)); |
42 | } |
43 | |
44 | if (swic_trim(s, myName + " forget syntax:", m)) { |
45 | S syntax = massageSyntax(m.rest()); |
46 | if (!syntaxes.remove(syntax)) ret "Syntax not found"; |
47 | change(); |
48 | ret "Syntax removed!"; |
49 | } |
50 | |
51 | if (ellipsisToDotPlusRegexpIC_matchAny(syntaxes, s, m)) |
52 | ret doIt(m.rest()); |
53 | |
54 | null; |
55 | }); |
56 | } |
57 | |
58 | S doIt(S query) { |
59 | LS l = regexpICFullMatch_groups("(\\d+) results? for[ :](.+)", query); |
60 | int results = defaultResults; |
61 | if (l != null) { |
62 | results = parseInt(first(l)); |
63 | query = unquote(trim(last(l))); |
64 | } |
65 | ret discord_google(query, +results); |
66 | } |
67 | |
68 | S randomThingToGoogle() { |
69 | ret "why are penguins black and white?"; |
70 | } |
71 | |
72 | S massageSyntax(S syntax) { |
73 | syntax = unquote(syntax); |
74 | ret trim(dropSuffix("...", syntax)) + " ..."; |
75 | } |
76 | } |
Began life as a copy of #1023494
download show line numbers debug dex old transpilations
Travelled to 6 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1024114 |
Snippet name: | GBot (Discord Bot that googles, v2, old) |
Eternal ID of this version: | #1024114/30 |
Text MD5: | 75212c80255f84fec29118d52161f5b1 |
Transpilation MD5: | de196de88772b0240264eb95eb988b36 |
Author: | stefan |
Category: | javax / discord / a.i. |
Type: | JavaX source code (Dynamic Module) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2019-07-21 21:01:07 |
Source code size: | 2482 bytes / 76 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 262 / 649 |
Version history: | 29 change(s) |
Referenced in: | [show references] |