add go
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
36b8707404
commit
954263fc0d
|
@ -6,4 +6,5 @@ const (
|
|||
Start = Command("/start")
|
||||
Help = Command("/help")
|
||||
Ping = Command("/ping")
|
||||
Go = Command("/go")
|
||||
)
|
||||
|
|
30
main.go
30
main.go
|
@ -14,8 +14,16 @@ import (
|
|||
|
||||
const (
|
||||
version = "v0.1.1"
|
||||
userStateNone = userState("None")
|
||||
userStateGo = userState("Go")
|
||||
)
|
||||
|
||||
var (
|
||||
state = userStateNone
|
||||
)
|
||||
|
||||
type userState string
|
||||
|
||||
type Opts struct {
|
||||
Token string `short:"t" long:"token" description:"Telegram api token"`
|
||||
Name string `short:"n" long:"name" description:"Telegram bot name" default:"@body_weight_loss_bot"`
|
||||
|
@ -78,16 +86,34 @@ func run() {
|
|||
|
||||
text := update.Message.Text
|
||||
chatID := update.Message.Chat.ID
|
||||
// username := update.Message.From.UserName
|
||||
// username := update.Message.From.UserName
|
||||
|
||||
if state == userStateGo {
|
||||
_, _ = bot.Send(tgbot.NewMessage(chatID, text))
|
||||
state = userStateNone
|
||||
continue
|
||||
}
|
||||
|
||||
command := commands.Command(strings.Replace(text, opts.Name, "", 1))
|
||||
switch command {
|
||||
case commands.Start:
|
||||
_, _ = bot.Send(tgbot.NewMessage(chatID, fmt.Sprintf("Здорова, я Валера (%s), твой тренер (%d).", version, chatID)))
|
||||
case commands.Help:
|
||||
_, _ = bot.Send(tgbot.NewMessage(chatID, "Вот что я умею:\n\n1) Ничего"))
|
||||
_, _ = bot.Send(tgbot.NewMessage(chatID, "Вот что я умею:\n\n1) Предлагать размяться"))
|
||||
case commands.Ping:
|
||||
_, _ = bot.Send(tgbot.NewMessage(chatID, "pong"))
|
||||
case commands.Go:
|
||||
msg := tgbot.NewMessage(chatID, "Давай немного разомнемся, отжимания")
|
||||
msg.ReplyMarkup = tgbot.NewReplyKeyboard(
|
||||
tgbot.NewKeyboardButtonRow(
|
||||
tgbot.NewKeyboardButton("1"),
|
||||
tgbot.NewKeyboardButton("2"),
|
||||
tgbot.NewKeyboardButton("3"),
|
||||
),
|
||||
)
|
||||
if _, err = bot.Send(msg); err == nil {
|
||||
state = userStateGo
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue