add go
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Владимир Фёдоров 2023-03-11 16:34:31 +07:00
parent 36b8707404
commit 954263fc0d
2 changed files with 29 additions and 2 deletions

View File

@ -6,4 +6,5 @@ const (
Start = Command("/start") Start = Command("/start")
Help = Command("/help") Help = Command("/help")
Ping = Command("/ping") Ping = Command("/ping")
Go = Command("/go")
) )

30
main.go
View File

@ -14,8 +14,16 @@ import (
const ( const (
version = "v0.1.1" version = "v0.1.1"
userStateNone = userState("None")
userStateGo = userState("Go")
) )
var (
state = userStateNone
)
type userState string
type Opts struct { type Opts struct {
Token string `short:"t" long:"token" description:"Telegram api token"` 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"` 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 text := update.Message.Text
chatID := update.Message.Chat.ID 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)) command := commands.Command(strings.Replace(text, opts.Name, "", 1))
switch command { switch command {
case commands.Start: case commands.Start:
_, _ = bot.Send(tgbot.NewMessage(chatID, fmt.Sprintf("Здорова, я Валера (%s), твой тренер (%d).", version, chatID))) _, _ = bot.Send(tgbot.NewMessage(chatID, fmt.Sprintf("Здорова, я Валера (%s), твой тренер (%d).", version, chatID)))
case commands.Help: case commands.Help:
_, _ = bot.Send(tgbot.NewMessage(chatID, "Вот что я умею:\n\n1) Ничего")) _, _ = bot.Send(tgbot.NewMessage(chatID, "Вот что я умею:\n\n1) Предлагать размяться"))
case commands.Ping: case commands.Ping:
_, _ = bot.Send(tgbot.NewMessage(chatID, "pong")) _, _ = 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
}
} }
} }
} }