I
I
Ivan Chistov2015-10-30 16:51:16
go
Ivan Chistov, 2015-10-30 16:51:16

How to enter arbitrary text before executing a command?

Hello.
I am writing a bot on go, for telegram.
It is necessary that you can enter arbitrary text before the command, and only then that the command is executed.

case "/w":
sendMessage(chatid, " — ачивка анлокед")

i.e.
See the world /w
Conclusion:
See the world - unlocked achievement.
How can this be done?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
twintwin1003, 2015-10-30
@suuuuumod

It seems to work.
Just correct the regular season for the characters you need (numbers, letters, etc.)

package main

import (
  "fmt"
  "regexp"
)
func main() {
  var regex = regexp.MustCompile(`^([a-z]*)\/w`)

  s := "lol/w"
  switch {
  case regex.MatchString(s):
    fmt.Println("OK")
  default:
    fmt.Println("NOT OK")
  }
}

UPD
In general, here is a regular expression for Russian letters, numbers and spaces
, substitute here
var regex = regexp.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question