Add info command & fix mentions with underscores

This commit is contained in:
2024-08-04 11:26:45 +03:00
parent 4a47b83226
commit e886a22046
4 changed files with 25 additions and 10 deletions
+5 -2
View File
@@ -14,7 +14,7 @@ func NewAnonymousQuestionsService(
const ( const (
messageSentReply = "*Сообщение отправлено!*" messageSentReply = "*Сообщение отправлено!*"
newMessageNotification = "*Новое анонимное сообщение!*" newMessageNotification = "Новое анонимное сообщение!"
) )
type AnonymousMessagesService interface { type AnonymousMessagesService interface {
@@ -50,7 +50,10 @@ func (s *anonymousMessagesService) ServeMessages() error {
} }
func (s *anonymousMessagesService) pingClient(chatID int64) 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 { func (s *anonymousMessagesService) handleMessage(message Message) error {
+4 -3
View File
@@ -16,9 +16,10 @@ type MessageUpdate struct {
} }
type Message struct { type Message struct {
Text string Text string
Image *Image UseMarkdown bool
Video *Video Image *Image
Video *Video
} }
type Image struct { type Image struct {
+3 -1
View File
@@ -22,7 +22,9 @@ func (h *commandHandler) HandleCommand(update MessageUpdate) error {
var msgText string var msgText string
switch *update.Command { switch *update.Command {
case StartCommand: case StartCommand:
msgText = "Жду твоих вопросов!" msgText = "Жду твоих вопросов!!\nОтветы будут в канале @meme_me_a_meme (>ᴗ•)"
case InfoCommand:
msgText = "Бот привязан к каналу @meme_me_a_meme, так что ответы ищи там!!\nНа данный момент поддерживаются текст, фото и видео („• ᴗ •„)"
case UnknownCommand: case UnknownCommand:
msgText = "Неизвестная команда!" msgText = "Неизвестная команда!"
} }
+13 -4
View File
@@ -11,7 +11,6 @@ import (
const ( const (
updateTimeoutInSeconds = 60 updateTimeoutInSeconds = 60
messageParseMode = tgbotapi.ModeMarkdown
startCommand = "start" startCommand = "start"
infoCommand = "info" infoCommand = "info"
@@ -88,7 +87,10 @@ func (api *botAPI) sendTextMessage(chatID int64, message app.Message) error {
chatID, chatID,
message.Text, message.Text,
) )
msg.ParseMode = messageParseMode
if message.UseMarkdown {
msg.ParseMode = tgbotapi.ModeMarkdown
}
_, err := api.bot.Send(msg) _, err := api.bot.Send(msg)
return errors.WithStack(err) 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{} { func (api *botAPI) preparePhotos(message app.Message) []interface{} {
photo := tgbotapi.NewInputMediaPhoto(tgbotapi.FileID(message.Image.FileID)) photo := tgbotapi.NewInputMediaPhoto(tgbotapi.FileID(message.Image.FileID))
photo.Caption = message.Text photo.Caption = message.Text
photo.ParseMode = messageParseMode
if message.UseMarkdown {
photo.ParseMode = tgbotapi.ModeMarkdown
}
var photos []interface{} var photos []interface{}
photos = append(photos, photo) photos = append(photos, photo)
@@ -171,6 +176,10 @@ func (api *botAPI) preparePhotos(message app.Message) []interface{} {
func (api *botAPI) prepareVideo(message app.Message) []interface{} { func (api *botAPI) prepareVideo(message app.Message) []interface{} {
video := tgbotapi.NewInputMediaVideo(tgbotapi.FileID(message.Video.FileID)) video := tgbotapi.NewInputMediaVideo(tgbotapi.FileID(message.Video.FileID))
video.Caption = message.Text video.Caption = message.Text
video.ParseMode = messageParseMode
if message.UseMarkdown {
video.ParseMode = tgbotapi.ModeMarkdown
}
return []interface{}{video} return []interface{}{video}
} }