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 5786K of libraries. Click here for Pure Java version (9492L/49K).

1  
!7
2  
3  
set flag AllowMetaCode. set flag Reparse. meta-transformNow { tok_standardBot }
4  
5  
standard bot WeNeed {
6  
  Set<S> db = ciSet();
7  
  
8  
  S add(S s) { if (db.add(s)) change(); null; }
9  
  S remove(S s) { ret db.remove(s) ? with(r change, "What a relief") : null; }
10  
  S listWithPattern(S pat) { ret or2(lines(map(db, x -> format(ellipsisToStar(pat), x))), "nothing"); }
11  
  S clearAfterConfirm() { ret "You're kidding, right?"; }
12  
13  
  sync S processSimplifiedLine(S s, O... _) {
14  
    try answer super.processSimplifiedLine(s, _);
15  
    new Matches m;
16  
    
17  
    meta {
18  
      S program = [[
19  
        We need ... = +
20  
        We have ... = -
21  
        Someone gave us ...|Someone gave me ... = -
22  
        What do we need = listWithPattern("We need ...")
23  
        We don't need ... anymore = -
24  
        We need nothing|We don't need anything = clear after confirm
25  
      ]];
26  
    
27  
      LS tok = javaTok(program);
28  
      jreplace(tok, "+", "add(\\$1);");
29  
      jreplace(tok, "-", "remove(\\$1);");
30  
      jreplace(tok, "clear after confirm", "clearAfterConfirm();");
31  
      LS lines = lines(join(tok));
32  
      lines = map(lines, l -> {
33  
        PairS p = splitAtEquals_pair(l);
34  
        ret p == null ? l : "if (matchX2(\*quote(p.a)*/, s, m)) ret \*p.b*/;";
35  
      });
36  
      ret lines(lines);
37  
    }
38  
    null;
39  
  }
40  
}

download  show line numbers  debug dex   

Travelled to 2 computer(s): mqqgnosmbjvj, tvejysmllsmz

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: 59 / 2713
Version history: 29 change(s)
Referenced in: [show references]