Uses 4998K of libraries. Click here for Pure Java version (14933L/110K).
!7 abstract sclass DynListBot extends DynTalkBot2<.ByServer> { /* example program: The AI should ... = + The AI doesn't have to ... = - What should the AI do = listWithPattern("The AI should ...") The AI shouldn't do anything = clear after confirm */ S program; S nothingText = "nothing"; // for listing an empty database void init { super.init(); makeByServer = () -> new ByServer; useAGIBlueForDropPunctuation = false; preprocessAtSelfToMyName = false; } static noeq record Entry(S text) extends HasGlobalID {} transient IF0<Entry> makeEntry = () -> new Entry(); class ByServer extends DynTalkBot2.ByServer { Map<S, Entry> db = ciMap(); S add(S s) { if (!db.containsKey(s)) { db.put(s, setAll(makeEntry!, text := s)); change(); ret "OK, stored"; } ret "I know"; } S remove(S s) { ret db.remove(s) != null ? with(r change, "OK, then not") : "I know"; } S listWithPattern(S pat) { ret or2(lines(mapValuesToList(db, x -> discord_prependGlobalID(x) + format_ellipsis(pat, x.text))), nothingText); } S clearAfterConfirm() { ret "Function not implemented yet :)"; } // TODO sync S processSimplifiedLine(S s, O... _) { try answer super.processSimplifiedLine(s, _); new Matches m; for (S lhs, rhs : unpair extractLineEquations(program)) { if (matchX2(lhs, s, m)) { if (eq(rhs, "+")) ret add($1); if (eq(rhs, "-")) ret remove($1); if (eq(rhs, "clear after confirm")) ret clearAfterConfirm(); Pair<S, LS> call = parseFunctionCall(rhs); if (call != null && eq(call.a, "listWithPattern")) ret listWithPattern(unquote(first(call.b))); } } s = dropMyPrefixOrNull(s); if "download" { optPar Guild guild; optPar MessageChannel channel; ret serveGuildBackup(channel, guild, structure_nullingInstancesOfClass(_getClass(module()), ByServer.this)); } null; } } }
Began life as a copy of #1025493
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: | #1025497 |
Snippet name: | DynListBot [discord bot that manages a list with custom cmds] |
Eternal ID of this version: | #1025497/18 |
Text MD5: | 5a42cd959d9b5d4dfca73e26b35c7378 |
Transpilation MD5: | 8fe2326e5148417b442b85bef72d11ec |
Author: | stefan |
Category: | javax / a.i. |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2019-10-05 14:54:49 |
Source code size: | 2124 bytes / 63 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 344 / 772 |
Version history: | 17 change(s) |
Referenced in: | #1034167 - Standard Classes + Interfaces (LIVE, continuation of #1003674) |