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

69
LINES

< > BotCompany Repo | #1002323 // Definition bot

JavaX source code [tags: use-pretranspiled] - run with: x30.jar

Libraryless. Click here for Pure Java version (2221L/14K/48K).

1  
!752
2  
static Map<S, S> definitions = new HashMap<S, S>();
3  
p{
4  
  makeBot("Definition bot");
5  
  load("definitions");
6  
}
7  
8  
answer{
9  
  if(matchStart("define * : *", s, m)){
10  
    if(definitions.get(m.unq(0)) == null){
11  
      S def = s.replace("define " + m.unq(0) + " : ","" );
12  
      definitions.put(m.unq(0), def);
13  
      save("definitions");
14  
      ret "Defined " + m.unq(0) + ". Definition: " + def;
15  
    }else{
16  
      ret m.unq(0) + " is already defined. Definition: \"" + definitions.get(m.unq(0)) + "\"";
17  
    }
18  
  }
19  
  if(matchStart("meaning of * is *", s, m)){
20  
    if(definitions.get(m.unq(0)) == null){
21  
      S def = s.replace("meaning of " + m.unq(0) + " is ","" );
22  
      definitions.put(m.unq(0), def);
23  
      save("definitions");
24  
      ret "Defined " + m.unq(0) + ". Definition: " + def;
25  
    }else{
26  
      ret m.unq(0) + " is already defined. Definition: \"" + definitions.get(m.unq(0)) + "\"";
27  
    }
28  
  }
29  
  if(matchStart("get def *", s, m) || matchStart("what is the definition of *", s, m)){
30  
    if(definitions.get(m.unq(0)) == null){
31  
      ret "There is no such thing defined. Define it yourself with ```define * : *```";
32  
    }else{
33  
      ret "Definition of " + m.unq(0) + " is \"" + definitions.get(m.unq(0)) + "\""; 
34  
    }
35  
  }
36  
  if(matchStart("remove def *", s, m) || matchStart("undefine *", s, m)){
37  
    if(definitions.get(m.unq(0)) == null){
38  
      ret "The word " + m.unq(0) + " isn't defined.";
39  
    }else{
40  
      definitions.remove(m.unq(0));
41  
      save("definitions");
42  
      ret "Removed " + m.unq(0) + " from definitions list.";
43  
    }
44  
  }
45  
  if(matchStart("edit def * : *", s, m)){
46  
    if(definitions.get(m.unq(0)) == null){
47  
      ret "The word " + m.unq(0) + " isn't defined.";
48  
    }else{
49  
      S def = s.replace("edit def " + m.unq(0) + " : ","" );
50  
      definitions.put(m.unq(0),def);
51  
      save("definitions");
52  
      ret "Edited " + m.unq(0) + ". New definition: \"" + def + "\"";
53  
    }
54  
  }
55  
  if(match("all defs", s) || match("list definitions", s) || match("list all definitions", s)){
56  
    if(definitions == null){
57  
      ret "There is nothing defined right now.";
58  
    }else{
59  
      ret "Here is a list of definitions: ```"+definitions+"```";
60  
    }
61  
  }
62  
  if(match("list all defined words", s) || match("list defined words", s) || match("defkeys", s)){
63  
    if(definitions == null){
64  
      ret "There is nothing defined right now.";    
65  
    }else{
66  
      ret "These are all the defined words: ``` " + definitions.keySet() + " ```";
67  
    }
68  
  }
69  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1002323
Snippet name: Definition bot
Eternal ID of this version: #1002323/1
Text MD5: 021e9d4d20f70b5f49d1f1f86f294355
Transpilation MD5: bd531c68922b4be0bfd9d4fcd8a94088
Author: bgrgndz
Category:
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2016-01-25 19:58:46
Source code size: 2507 bytes / 69 lines
Pitched / IR pitched: No / No
Views / Downloads: 902 / 1662
Referenced in: [show references]