From e886a22046d2afb1ccc7c6ff90fbce95e468e5f0 Mon Sep 17 00:00:00 2001 From: nightnoryu Date: Sun, 4 Aug 2024 11:26:45 +0300 Subject: [PATCH] Add info command & fix mentions with underscores --- pkg/app/anonymousmessagesservice.go | 7 +++++-- pkg/app/botapi.go | 7 ++++--- pkg/app/commandhandler.go | 4 +++- pkg/infrastructure/botapi.go | 17 +++++++++++++---- 4 files changed, 25 insertions(+), 10 deletions(-) diff --git a/pkg/app/anonymousmessagesservice.go b/pkg/app/anonymousmessagesservice.go index 6ad0ccf..0b6050e 100644 --- a/pkg/app/anonymousmessagesservice.go +++ b/pkg/app/anonymousmessagesservice.go @@ -14,7 +14,7 @@ func NewAnonymousQuestionsService( const ( messageSentReply = "*Сообщение отправлено!*" - newMessageNotification = "*Новое анонимное сообщение!*" + newMessageNotification = "Новое анонимное сообщение!" ) type AnonymousMessagesService interface { @@ -50,7 +50,10 @@ func (s *anonymousMessagesService) ServeMessages() error { } func (s *anonymousMessagesService) pingClient(chatID int64) error { - return s.api.SendMessage(chatID, Message{Text: messageSentReply}) + return s.api.SendMessage(chatID, Message{ + Text: messageSentReply, + UseMarkdown: true, + }) } func (s *anonymousMessagesService) handleMessage(message Message) error { diff --git a/pkg/app/botapi.go b/pkg/app/botapi.go index 41826c9..ae999da 100644 --- a/pkg/app/botapi.go +++ b/pkg/app/botapi.go @@ -16,9 +16,10 @@ type MessageUpdate struct { } type Message struct { - Text string - Image *Image - Video *Video + Text string + UseMarkdown bool + Image *Image + Video *Video } type Image struct { diff --git a/pkg/app/commandhandler.go b/pkg/app/commandhandler.go index 04b8538..957bf52 100644 --- a/pkg/app/commandhandler.go +++ b/pkg/app/commandhandler.go @@ -22,7 +22,9 @@ func (h *commandHandler) HandleCommand(update MessageUpdate) error { var msgText string switch *update.Command { case StartCommand: - msgText = "Жду твоих вопросов!" + msgText = "Жду твоих вопросов!!\nОтветы будут в канале @meme_me_a_meme (>ᴗ•)" + case InfoCommand: + msgText = "Бот привязан к каналу @meme_me_a_meme, так что ответы ищи там!!\nНа данный момент поддерживаются текст, фото и видео („• ᴗ •„)" case UnknownCommand: msgText = "Неизвестная команда!" } diff --git a/pkg/infrastructure/botapi.go b/pkg/infrastructure/botapi.go index f5da364..8020b1d 100644 --- a/pkg/infrastructure/botapi.go +++ b/pkg/infrastructure/botapi.go @@ -11,7 +11,6 @@ import ( const ( updateTimeoutInSeconds = 60 - messageParseMode = tgbotapi.ModeMarkdown startCommand = "start" infoCommand = "info" @@ -88,7 +87,10 @@ func (api *botAPI) sendTextMessage(chatID int64, message app.Message) error { chatID, message.Text, ) - msg.ParseMode = messageParseMode + + if message.UseMarkdown { + msg.ParseMode = tgbotapi.ModeMarkdown + } _, err := api.bot.Send(msg) return errors.WithStack(err) @@ -160,7 +162,10 @@ func (api *botAPI) hydrateVideo(video *tgbotapi.Video) *app.Video { func (api *botAPI) preparePhotos(message app.Message) []interface{} { photo := tgbotapi.NewInputMediaPhoto(tgbotapi.FileID(message.Image.FileID)) photo.Caption = message.Text - photo.ParseMode = messageParseMode + + if message.UseMarkdown { + photo.ParseMode = tgbotapi.ModeMarkdown + } var photos []interface{} photos = append(photos, photo) @@ -171,6 +176,10 @@ func (api *botAPI) preparePhotos(message app.Message) []interface{} { func (api *botAPI) prepareVideo(message app.Message) []interface{} { video := tgbotapi.NewInputMediaVideo(tgbotapi.FileID(message.Video.FileID)) video.Caption = message.Text - video.ParseMode = messageParseMode + + if message.UseMarkdown { + video.ParseMode = tgbotapi.ModeMarkdown + } + return []interface{}{video} }