Uses 4998K of libraries. Click here for Pure Java version (15364L/109K).
!7 // cmodule fails because of loadPageWithUserAgent module GBot > DynDiscordHopper { S myName = "GBot"; int defaultResults = 1; Set<S> syntaxes = synchroSet(); @Override S answer(S input, Map map) { ret mapEachLine_tlft_nempties(input, s -> { print("Guild: " + map.get('guildID)); new Matches m; s = simpleSpaces_noTok(s); s = regexpReplace_direct(s, "\\s+:", ":"); if (eqicOneOf(replaceIC(words2_spaces(s), " show ", " "), myName + " Help", myName + " info", myName + " commands")) ret loadSnippet(#1024125); if (swic_trim(s, myName + ":", m)) ret doIt(m.rest()); if (swic_trim(s, myName + " default results:", m)) { setField(defaultResults := parseInt(m.rest()); ret "OK, returning " + nResults(defaultResults) + " from now on"; } if (eqic(s, myName + " default results")) ret "I'm returning " + nResults(defaultResults) + " by default"; if (eqic(s, myName + " syntaxes")) ret backtickQuote(lines_rtrim(elementPlusList(myName + ": ...", syntaxes))); if (swic_trim_any(s, m, myName + " new syntax:", myName + " add syntax:")) { S syntax = massageSyntax(m.rest()); if (!endsWithEllipsis(syntax)) ret "Shouldn't this end with \"...\"? >> " + syntax; if (!syntaxes.add(syntax)) ret "I already know that syntax!"; change(); ret "Syntax added! You can try: " + backtickQuote(replaceSuffix("...", randomThingToGoogle(), syntax)); } if (swic_trim(s, myName + " forget syntax:", m)) { S syntax = massageSyntax(m.rest()); if (!syntaxes.remove(syntax)) ret "Syntax not found"; change(); ret "Syntax removed!"; } if (ellipsisToDotPlusRegexpIC_matchAny(syntaxes, s, m)) ret doIt(m.rest()); null; }); } S doIt(S query) { LS l = regexpICFullMatch_groups("(\\d+) results? for[ :](.+)", query); int results = defaultResults; if (l != null) { results = parseInt(first(l)); query = unquote(trim(last(l))); } ret discord_google(query, +results); } S randomThingToGoogle() { ret "why are penguins black and white?"; } S massageSyntax(S syntax) { syntax = unquote(syntax); ret trim(dropSuffix("...", syntax)) + " ..."; } }
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: | 263 / 650 |
Version history: | 29 change(s) |
Referenced in: | #1024115 - GBot backup v1 (Discord Bot that googles) #1024131 - GBot v3 (Discord Bot that googles, server-aware version, LIVE) |