From a91af5b68a9cd9af90890bdf50aa4d0d78a83cc4 Mon Sep 17 00:00:00 2001 From: Fedorov Vladimir Date: Thu, 14 Sep 2023 02:20:02 +0700 Subject: [PATCH] add ping --- cmd/butler/main.go | 5 ++-- internal/services/bot/bot_ping/bot.go | 35 +++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 internal/services/bot/bot_ping/bot.go diff --git a/cmd/butler/main.go b/cmd/butler/main.go index f55deae..5912c22 100644 --- a/cmd/butler/main.go +++ b/cmd/butler/main.go @@ -4,13 +4,13 @@ import ( "context" "os" - "github.com/joho/godotenv" - "git.3crabs.ru/VLADIMIR/butler/internal/modules/messenger/telegram" "git.3crabs.ru/VLADIMIR/butler/internal/modules/storage/postgres" "git.3crabs.ru/VLADIMIR/butler/internal/services/bot" "git.3crabs.ru/VLADIMIR/butler/internal/services/bot/bot_all" + "git.3crabs.ru/VLADIMIR/butler/internal/services/bot/bot_ping" "git.3crabs.ru/VLADIMIR/butler/internal/services/listener" + "github.com/joho/godotenv" ) func main() { @@ -35,6 +35,7 @@ func main() { messengerTelegram, []bot.IBot{ bot_all.NewBotAll(messengerTelegram, storage), + bot_ping.NewBotPing(messengerTelegram), }, ) ctx := context.Background() diff --git a/internal/services/bot/bot_ping/bot.go b/internal/services/bot/bot_ping/bot.go new file mode 100644 index 0000000..21ef7d3 --- /dev/null +++ b/internal/services/bot/bot_ping/bot.go @@ -0,0 +1,35 @@ +package bot_ping + +import ( + "context" + "strings" + + "git.3crabs.ru/VLADIMIR/butler/internal/modules/messenger" + "git.3crabs.ru/VLADIMIR/butler/internal/services/bot" +) + +type botPing struct { + messenger messenger.IMessenger +} + +func NewBotPing( + messenger messenger.IMessenger, +) bot.IBot { + return &botPing{ + messenger: messenger, + } +} + +func (bot *botPing) Process(ctx context.Context, msg *messenger.Message) error { + if !strings.Contains(msg.Text, "/ping") { + return nil + } + bot.messenger.SendMessage( + ctx, + &messenger.Message{ + ChatID: msg.ChatID, + Text: "pong", + }, + ) + return nil +}