Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

40
LINES

< > BotCompany Repo | #1025375 // We Need Bot [LIVE]

JavaX source code (Dynamic Module) [tags: use-pretranspiled] - run with: Stefan's OS

Uses 5909K of libraries. Click here for Pure Java version (9492L/49K).

!7

set flag AllowMetaCode. set flag Reparse. meta-transformNow { tok_standardBot }

standard bot WeNeed {
  Set<S> db = ciSet();
  
  S add(S s) { if (db.add(s)) change(); null; }
  S remove(S s) { ret db.remove(s) ? with(r change, "What a relief") : null; }
  S listWithPattern(S pat) { ret or2(lines(map(db, x -> format(ellipsisToStar(pat), x))), "nothing"); }
  S clearAfterConfirm() { ret "You're kidding, right?"; }

  sync S processSimplifiedLine(S s, O... _) {
    try answer super.processSimplifiedLine(s, _);
    new Matches m;
    
    meta {
      S program = [[
        We need ... = +
        We have ... = -
        Someone gave us ...|Someone gave me ... = -
        What do we need = listWithPattern("We need ...")
        We don't need ... anymore = -
        We need nothing|We don't need anything = clear after confirm
      ]];
    
      LS tok = javaTok(program);
      jreplace(tok, "+", "add(\\$1);");
      jreplace(tok, "-", "remove(\\$1);");
      jreplace(tok, "clear after confirm", "clearAfterConfirm();");
      LS lines = lines(join(tok));
      lines = map(lines, l -> {
        PairS p = splitAtEquals_pair(l);
        ret p == null ? l : "if (matchX2(\*quote(p.a)*/, s, m)) ret \*p.b*/;";
      });
      ret lines(lines);
    }
    null;
  }
}

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: #1025375
Snippet name: We Need Bot [LIVE]
Eternal ID of this version: #1025375/30
Text MD5: 1132d30dbe5ba57c775da1c80736738b
Transpilation MD5: 3a7e799b72d26757dbca8e9b489febaf
Author: stefan
Category: javax / discord bots
Type: JavaX source code (Dynamic Module)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-09-27 01:57:16
Source code size: 1319 bytes / 40 lines
Pitched / IR pitched: No / No
Views / Downloads: 475 / 23852
Version history: 29 change(s)
Referenced in: [show references]