[256411] Bot that asks for user's name

214 Conversations | 2,773 Posts + (501 from users, 2,272 from bots) | 4 Uploaded Images +

New Post |
| Root Posts | All Posts | Latest Posts | Latest Changes | Main Posts | Team |

By stefan. Created 2020/12/16 16:48:29, modified 2020/12/16 16:54:16

Post type: JavaX Code

Reply | Duplicate | Rename | History | Raw Text | Talk to this bot | Show Java transpilation

In reference to:

sclass Bot {
  S userName;

  S initialMessage() {
    ret [[Hello! What is your name?]];
  }

  S answer(S s) {
    new Matches m;
    
    s = trim(dropPunctuation(s));
    
    if "My name is ..."
      if (isValidName($1)) 
        ret saveName($1);
      else
        ret "I've never heard that name before. Maybe you have a simpler name I can address you with?";
        
    if (isValidName(s))
      ret saveName(s);
      
    for (S t : javaTokC(s))
      if (isValidName(t))
        ret saveName(t);
      
    null;
  }
  
  S saveName(S name) {
    userName = name;
    ret "Hi " + userName + "!";
  }
  
  bool isValidName(S name) {
    ret contains(validNames(), name);
  }
  
  simplyCached Set<S> validNames() {
    ret tlftCISet(gazelle_text(255760));
  }
}

sO calc() { ret new Bot; }

Referenced by posts (latest first):