Advertisement
BlackBeltPanda

RegexAutoHelp

May 15th, 2016
257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.25 KB | None | 0 0
  1. Example automatic help system that intelligently determines when players are asking about certain features:
  2.  
  3. #Match questions about warps
  4. match (?i)what.*?warp
  5. then warn &dIt looks like you may have a question about the warps. Use &a/warps &dto see a list of warps and &a/warp <name> &dto warp to it.
  6.  
  7. Explanation:
  8. This is a simple one. It just matches any string that starts with "what" and ends with "warp". It may have some false positives but that's not a big problem here since we don't cancel the players chat. We use ChatControl's "then warn", which is normally used to send a warning to a player, to instead send them a helpful message about their question. We use "(?i)" in the beginning to make the match case-insensitive.
  9.  
  10. #Match asking about staff ranks
  11. match (?i)(?:can|may|would you like if) i (?:have|be|become|get|has) (?:op|admin|mod|builder|staff|chatmod|mod)
  12. then warn &dYou can find staff applications here: http://www.yourwebsitehere.com/staffapplications
  13.  
  14. Explanation:
  15. This one is a little bit more complicated. We use passive groups ("(?:<regex_here>)") to match several possible words to catch different ways of wording the question. This one just checks to see if a player is asking about becoming staff.
  16.  
  17. #Match questions about the custom tools
  18. match (?i)how do(?:es)?.*?(?:clock|pipe|miner|placer|fisher|sieve|sift|collect|sort|compost)(?:s)?
  19. then warn &dIt looks like you may have a question about our custom tools. Here's a tutorial video! https://www.youtube.com/watch?v=dSIbt8B2nJM
  20.  
  21. Explanation:
  22. This one is probably as complicated as it needs to be. It uses passive groups to check for common words in the question that can be formatted differently depending on how you ask it. In this case, it checks if the player's asking about custom tools on the server. This one also uses ".*?".
  23. "." matches any character except a new line.
  24. "*" matches 0 or more of the character we previously matched.
  25. "?" makes the previous check lazy so it uses less resources when checking by only matching the minimum amount of characters.
  26. In addition, we use a passive group with "?" appended to it ("(?:s)?"). This makes the match optional by checking for either 0 or 1 of that match and, in our case, allows us to match the plural forms of the words in the question.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement