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
+23 -18
View File
@@ -14,6 +14,8 @@ func NewAnonymousQuestionsService(
const (
messageSentReply = "*Сообщение отправлено!*"
unsupportedMessageReply = "*Такое сообщение не поддерживается :(*"
newMessageNotification = "Новое анонимное сообщение!"
)
@@ -37,30 +39,33 @@ func (s *anonymousMessagesService) ServeMessages() error {
return
}
err := s.handleMessage(update.Message)
if err != nil {
s.errorsChan <- err
}
err = s.pingClient(update.FromChatID)
if err != nil {
s.errorsChan <- err
}
if update.Message.Sticker != nil {
err := s.api.SendMessage(update.FromChatID, Message{
Text: unsupportedMessageReply,
UseMarkdown: true,
})
if err != nil {
s.errorsChan <- err
}
return
}
func (s *anonymousMessagesService) pingClient(chatID int64) error {
return s.api.SendMessage(chatID, Message{
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 {
s.errorsChan <- err
}
err = s.api.SendMessage(update.FromChatID, Message{
Text: messageSentReply,
UseMarkdown: true,
})
if err != nil {
s.errorsChan <- err
}
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
Image *Image
Video *Video
Sticker *Sticker
}
type Image struct {
@@ -30,6 +31,11 @@ type Video struct {
FileID string
}
type Sticker struct {
FileID string
Emoji string
}
type Command int
const (
+12
View File
@@ -79,6 +79,7 @@ func (api *botAPI) hydrateMessage(msg *tgbotapi.Message) app.Message {
Text: text,
Image: api.hydrateImage(msg.Photo),
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{} {
photo := tgbotapi.NewInputMediaPhoto(tgbotapi.FileID(message.Image.FileID))
photo.Caption = message.Text