From 68bb06342693e41ad50a9c2293bb4cc4e6ffd3f0 Mon Sep 17 00:00:00 2001 From: davidramiro Date: Mon, 23 Dec 2024 14:10:27 +0100 Subject: [PATCH] feat: handle photo captions --- go.mod | 2 +- go.sum | 4 ++-- internal/adapters/handler/command.go | 6 +++++- internal/core/domain/command.go | 2 +- main.go | 1 + 5 files changed, 10 insertions(+), 5 deletions(-) diff --git a/go.mod b/go.mod index c44ec95..a5b92c9 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module hsbot go 1.22 require ( - github.com/go-telegram/bot v1.12.0 + github.com/go-telegram/bot v1.12.1 github.com/gofrs/uuid/v5 v5.3.0 github.com/liushuangls/go-anthropic/v2 v2.13.0 github.com/rs/zerolog v1.33.0 diff --git a/go.sum b/go.sum index 47715a5..59201fb 100644 --- a/go.sum +++ b/go.sum @@ -7,8 +7,8 @@ github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHk github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0= github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA= github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM= -github.com/go-telegram/bot v1.12.0 h1:5i4lLLOldfv45egxb8m3XDelXU6SBryg3aHFMvmKoFs= -github.com/go-telegram/bot v1.12.0/go.mod h1:i2TRs7fXWIeaceF3z7KzsMt/he0TwkVC680mvdTFYeM= +github.com/go-telegram/bot v1.12.1 h1:2CSwMd+g71/XrmuSpvEjLtsmkfL/s63PdnLboGJQxtw= +github.com/go-telegram/bot v1.12.1/go.mod h1:i2TRs7fXWIeaceF3z7KzsMt/he0TwkVC680mvdTFYeM= github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= github.com/gofrs/uuid/v5 v5.3.0 h1:m0mUMr+oVYUdxpMLgSYCZiXe7PuVPnI94+OMeVBNedk= github.com/gofrs/uuid/v5 v5.3.0/go.mod h1:CDOjlDMVAtN56jqyRUZh58JT31Tiw7/oQyEXZV+9bD8= diff --git a/internal/adapters/handler/command.go b/internal/adapters/handler/command.go index dd251b3..66215ff 100644 --- a/internal/adapters/handler/command.go +++ b/internal/adapters/handler/command.go @@ -24,12 +24,16 @@ func (h *CommandHandler) Handle(ctx context.Context, b *bot.Bot, update *models. return } + if update.Message.Photo != nil { + update.Message.Text = update.Message.Caption + } + log.Debug().Str("message", update.Message.Text).Msg("registering chat command handler") cmd := domain.ParseCommand(update.Message.Text) commandHandler, err := h.commandRegistry.Get(cmd) if err != nil { - log.Debug().Str("commands", cmd).Msg("no handler for commands") + log.Debug().Str("command", cmd).Msg("no handler for command") return } diff --git a/internal/core/domain/command.go b/internal/core/domain/command.go index 46c5866..2a19945 100644 --- a/internal/core/domain/command.go +++ b/internal/core/domain/command.go @@ -62,5 +62,5 @@ func ParseCommandArgs(args string) string { func ParseCommand(args string) string { command := strings.Split(args, " ") - return command[0] + return strings.ToLower(command[0]) } diff --git a/main.go b/main.go index d669837..521dd06 100644 --- a/main.go +++ b/main.go @@ -89,6 +89,7 @@ func main() { commandHandler := handler.NewCommandHandler(commandRegistry, handlerTimeout) b.RegisterHandler(bot.HandlerTypeMessageText, "/", bot.MatchTypePrefix, commandHandler.Handle) + b.RegisterHandler(bot.HandlerTypePhotoCaption, "/", bot.MatchTypePrefix, commandHandler.Handle) log.Info().Msg("bot listening") b.Start(ctx)