Add warning for stickers

This commit is contained in:
2024-08-07 14:35:17 +03:00
parent e886a22046
commit aabc012c6b
3 changed files with 45 additions and 22 deletions
+24 -19
View File
@@ -13,7 +13,9 @@ func NewAnonymousQuestionsService(
} }
const ( const (
messageSentReply = "*Сообщение отправлено!*" messageSentReply = "*Сообщение отправлено!*"
unsupportedMessageReply = "*Такое сообщение не поддерживается :(*"
newMessageNotification = "Новое анонимное сообщение!" newMessageNotification = "Новое анонимное сообщение!"
) )
@@ -37,30 +39,33 @@ func (s *anonymousMessagesService) ServeMessages() error {
return return
} }
err := s.handleMessage(update.Message) if update.Message.Sticker != nil {
err := s.api.SendMessage(update.FromChatID, Message{
Text: unsupportedMessageReply,
UseMarkdown: true,
})
if err != nil {
s.errorsChan <- err
}
return
}
notificationText := newMessageNotification + "\n\n" + update.Message.Text
err := s.api.SendMessageToOwner(Message{
Text: notificationText,
Image: update.Message.Image,
Video: update.Message.Video,
})
if err != nil { if err != nil {
s.errorsChan <- err s.errorsChan <- err
} }
err = s.pingClient(update.FromChatID) err = s.api.SendMessage(update.FromChatID, Message{
Text: messageSentReply,
UseMarkdown: true,
})
if err != nil { if err != nil {
s.errorsChan <- err s.errorsChan <- err
} }
}) })
} }
func (s *anonymousMessagesService) pingClient(chatID int64) error {
return s.api.SendMessage(chatID, Message{
Text: messageSentReply,
UseMarkdown: true,
})
}
func (s *anonymousMessagesService) handleMessage(message Message) error {
msgText := newMessageNotification + "\n\n" + message.Text
return s.api.SendMessageToOwner(Message{
Text: msgText,
Image: message.Image,
Video: message.Video,
})
}
+6
View File
@@ -20,6 +20,7 @@ type Message struct {
UseMarkdown bool UseMarkdown bool
Image *Image Image *Image
Video *Video Video *Video
Sticker *Sticker
} }
type Image struct { type Image struct {
@@ -30,6 +31,11 @@ type Video struct {
FileID string FileID string
} }
type Sticker struct {
FileID string
Emoji string
}
type Command int type Command int
const ( const (
+15 -3
View File
@@ -76,9 +76,10 @@ func (api *botAPI) hydrateMessage(msg *tgbotapi.Message) app.Message {
} }
return app.Message{ return app.Message{
Text: text, Text: text,
Image: api.hydrateImage(msg.Photo), Image: api.hydrateImage(msg.Photo),
Video: api.hydrateVideo(msg.Video), Video: api.hydrateVideo(msg.Video),
Sticker: api.hydrateSticker(msg.Sticker),
} }
} }
@@ -159,6 +160,17 @@ func (api *botAPI) hydrateVideo(video *tgbotapi.Video) *app.Video {
} }
} }
func (api *botAPI) hydrateSticker(sticker *tgbotapi.Sticker) *app.Sticker {
if sticker == nil {
return nil
}
return &app.Sticker{
FileID: sticker.FileID,
Emoji: sticker.Emoji,
}
}
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