[256485] Bot that asks for user's name / VStack version [dev.]

209 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 17:11:49

Post type: JavaX Code

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

In reference to:

sclass Bot {
  S userName;

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

  record answer(S s) extends VStackStructuredComputable<S> {
    new Matches m;
    
    Structure routine() {
      switch (step) {
        r { s = trim(dropPunctuation(s)); }
          step = 1; ret;
    
        case 1:
          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):