String and random result

Hello, sorry for my poor knowledge of go:) Does anybody can help me with… how to set some random results instead only one? Also for request
For example:
if Regex("[Hh]ello", msg_body) {
Send(“hi”, “”, chat_id, msg_user_id)

I need something like:
if Regex ("[Hh]ello" or “[Hh]i” or … or …
Send ("hi’ or … or … )

Do you mean that what you Send should depend on which regex is matched? Is the string being sent what was matched by the regex? What is supposed to be random?

Yes, and random will be from Send

For example user saying Hello or Hi or Whats up then if in the code exist matched key will be random answer from “Send”

If I understand correctly, https://play.golang.org/p/CyyzR-A4S9 has the parts you need.

  • line 12 defines a single regex to match everything you want to match
  • line 18 defines possible responses
  • line 20 simulates what happens when more than one message is received (to show that the responses are randomized)
  • line 21 finds out if the regex matches the message
  • line 22 picks a random response from the possible responses.

Please tell me if you meant something different.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.