From de70ca6e9160befc1fcea526a27acbbf9a7853a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D0=BB=D0=B0=D0=B4=D0=B8=D0=BC=D0=B8=D1=80=20=D0=A4?= =?UTF-8?q?=D0=B5=D0=B4=D0=BE=D1=80=D0=BE=D0=B2?= Date: Sun, 3 Apr 2022 17:19:32 +0700 Subject: [PATCH] add /start and /ping commands --- commands/command.go | 8 ++++++++ main.go | 10 ++++++++++ 2 files changed, 18 insertions(+) create mode 100644 commands/command.go diff --git a/commands/command.go b/commands/command.go new file mode 100644 index 0000000..05cdddb --- /dev/null +++ b/commands/command.go @@ -0,0 +1,8 @@ +package commands + +type Command string + +const ( + Start = Command("/start") + Ping = Command("/ping") +) diff --git a/main.go b/main.go index 78b1dde..a1cdebc 100644 --- a/main.go +++ b/main.go @@ -2,6 +2,7 @@ package main import ( "errors" + "git.user-penguin.space/vladimir/all_tg_bot/commands" tgbot "github.com/go-telegram-bot-api/telegram-bot-api" "github.com/umputun/go-flags" "log" @@ -16,6 +17,7 @@ const ( type Opts struct { Token string `short:"t" long:"token" description:"Telegram api token"` + Name string `short:"n" long:"name" description:"Telegram bot name" default:"@butler_tg_bot"` } var opts Opts @@ -59,5 +61,13 @@ func run() { if strings.Contains(strings.ToLower(text), tag) { _, _ = bot.Send(tgbot.NewMessage(chatID, allUsers)) } + + command := commands.Command(strings.Replace(text, opts.Name, "", 1)) + switch command { + case commands.Start: + _, _ = bot.Send(tgbot.NewMessage(chatID, "Здравствуйте, я ваш дворецкий.")) + case commands.Ping: + _, _ = bot.Send(tgbot.NewMessage(chatID, "pong")) + } } }