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 +}