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).

!752
static Map<S, S> definitions = new HashMap<S, S>();
p{
  makeBot("Definition bot");
  load("definitions");
}

answer{
  if(matchStart("define * : *", s, m)){
    if(definitions.get(m.unq(0)) == null){
      S def = s.replace("define " + m.unq(0) + " : ","" );
      definitions.put(m.unq(0), def);
      save("definitions");
      ret "Defined " + m.unq(0) + ". Definition: " + def;
    }else{
      ret m.unq(0) + " is already defined. Definition: \"" + definitions.get(m.unq(0)) + "\"";
    }
  }
  if(matchStart("meaning of * is *", s, m)){
    if(definitions.get(m.unq(0)) == null){
      S def = s.replace("meaning of " + m.unq(0) + " is ","" );
      definitions.put(m.unq(0), def);
      save("definitions");
      ret "Defined " + m.unq(0) + ". Definition: " + def;
    }else{
      ret m.unq(0) + " is already defined. Definition: \"" + definitions.get(m.unq(0)) + "\"";
    }
  }
  if(matchStart("get def *", s, m) || matchStart("what is the definition of *", s, m)){
    if(definitions.get(m.unq(0)) == null){
      ret "There is no such thing defined. Define it yourself with ```define * : *```";
    }else{
      ret "Definition of " + m.unq(0) + " is \"" + definitions.get(m.unq(0)) + "\""; 
    }
  }
  if(matchStart("remove def *", s, m) || matchStart("undefine *", s, m)){
    if(definitions.get(m.unq(0)) == null){
      ret "The word " + m.unq(0) + " isn't defined.";
    }else{
      definitions.remove(m.unq(0));
      save("definitions");
      ret "Removed " + m.unq(0) + " from definitions list.";
    }
  }
  if(matchStart("edit def * : *", s, m)){
    if(definitions.get(m.unq(0)) == null){
      ret "The word " + m.unq(0) + " isn't defined.";
    }else{
      S def = s.replace("edit def " + m.unq(0) + " : ","" );
      definitions.put(m.unq(0),def);
      save("definitions");
      ret "Edited " + m.unq(0) + ". New definition: \"" + def + "\"";
    }
  }
  if(match("all defs", s) || match("list definitions", s) || match("list all definitions", s)){
    if(definitions == null){
      ret "There is nothing defined right now.";
    }else{
      ret "Here is a list of definitions: ```"+definitions+"```";
    }
  }
  if(match("list all defined words", s) || match("list defined words", s) || match("defkeys", s)){
    if(definitions == null){
      ret "There is nothing defined right now.";    
    }else{
      ret "These are all the defined words: ``` " + definitions.keySet() + " ```";
    }
  }
}

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: 901 / 1660
Referenced in: [show references]