From 9fe2a76a60abec8aab73d71d8706052719c6c857 Mon Sep 17 00:00:00 2001 From: Rian Felipe Celestrino <39718272+RianFC@users.noreply.github.com> Date: Thu, 17 Oct 2024 15:08:40 -0300 Subject: [PATCH] feat: making view_once messages become spoilers (#63) * feat: making view_once messages become spoilers * feat(telegram): add spoiler_as_viewonce configuration option --- sample_config.yaml | 2 ++ state/config.go | 1 + utils/telegram.go | 8 ++++---- whatsapp/handlers.go | 2 ++ 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/sample_config.yaml b/sample_config.yaml index dc2aaf3..dc0243b 100644 --- a/sample_config.yaml +++ b/sample_config.yaml @@ -27,6 +27,8 @@ telegram: emoji_confirmation: true # Reacts to the message with a "👍" emoji instead of replying skip_startup_message: false # If set to true, then a message will NOT be sent to your Telegram DM when the bot starts + + spoiler_as_viewonce: True # If set to true, then all the spoiler files will be sent as view-once messages whatsapp: session_name: watgbridge # This will appear in your Linked Devices in mobile app diff --git a/state/config.go b/state/config.go index 95e3ea7..71c0e17 100644 --- a/state/config.go +++ b/state/config.go @@ -34,6 +34,7 @@ type Config struct { SilentConfirmation bool `yaml:"silent_confirmation"` EmojiConfirmation bool `yaml:"emoji_confirmation"` SkipStartupMessage bool `yaml:"skip_startup_message"` + SpoilerViewOnce bool `yaml:"spoiler_as_viewonce"` } `yaml:"telegram"` WhatsApp struct { diff --git a/utils/telegram.go b/utils/telegram.go index 267417c..ed775ce 100644 --- a/utils/telegram.go +++ b/utils/telegram.go @@ -304,7 +304,7 @@ func TgSendToWhatsApp(b *gotgbot.Bot, c *ext.Context, FileEncSHA256: uploadedImage.FileEncSHA256, FileSHA256: uploadedImage.FileSHA256, FileLength: proto.Uint64(uint64(len(imageBytes))), - ViewOnce: proto.Bool(msgToForward.HasProtectedContent), + ViewOnce: proto.Bool(msgToForward.HasProtectedContent || (msgToForward.HasMediaSpoiler && cfg.Telegram.SpoilerViewOnce)), Height: proto.Uint32(uint32(bestPhoto.Height)), Width: proto.Uint32(uint32(bestPhoto.Width)), ContextInfo: &waE2E.ContextInfo{}, @@ -385,7 +385,7 @@ func TgSendToWhatsApp(b *gotgbot.Bot, c *ext.Context, FileEncSHA256: uploadedVideo.FileEncSHA256, FileSHA256: uploadedVideo.FileSHA256, FileLength: proto.Uint64(uint64(len(videoBytes))), - ViewOnce: proto.Bool(msgToForward.HasProtectedContent), + ViewOnce: proto.Bool(msgToForward.HasProtectedContent || (msgToForward.HasMediaSpoiler && cfg.Telegram.SpoilerViewOnce)), Seconds: proto.Uint32(uint32(msgToForward.Video.Duration)), GifPlayback: proto.Bool(false), Height: proto.Uint32(uint32(msgToForward.Video.Height)), @@ -467,7 +467,7 @@ func TgSendToWhatsApp(b *gotgbot.Bot, c *ext.Context, FileEncSHA256: uploadedVideo.FileEncSHA256, FileSHA256: uploadedVideo.FileSHA256, FileLength: proto.Uint64(uint64(len(videoBytes))), - ViewOnce: proto.Bool(msgToForward.HasProtectedContent), + ViewOnce: proto.Bool(msgToForward.HasProtectedContent || (msgToForward.HasMediaSpoiler && cfg.Telegram.SpoilerViewOnce)), Seconds: proto.Uint32(uint32(msgToForward.VideoNote.Duration)), GifPlayback: proto.Bool(false), ContextInfo: &waE2E.ContextInfo{}, @@ -548,7 +548,7 @@ func TgSendToWhatsApp(b *gotgbot.Bot, c *ext.Context, FileEncSHA256: uploadedAnimation.FileEncSHA256, FileSHA256: uploadedAnimation.FileSHA256, FileLength: proto.Uint64(uint64(len(animationBytes))), - ViewOnce: proto.Bool(msgToForward.HasProtectedContent), + ViewOnce: proto.Bool(msgToForward.HasProtectedContent || (msgToForward.HasMediaSpoiler && cfg.Telegram.SpoilerViewOnce)), Height: proto.Uint32(uint32(msgToForward.Animation.Height)), Width: proto.Uint32(uint32(msgToForward.Animation.Width)), Seconds: proto.Uint32(uint32(msgToForward.Animation.Duration)), diff --git a/whatsapp/handlers.go b/whatsapp/handlers.go index 0cfecfe..ab243e2 100644 --- a/whatsapp/handlers.go +++ b/whatsapp/handlers.go @@ -499,6 +499,7 @@ func MessageFromOthersEventHandler(text string, v *events.Message, isEdited bool ReplyParameters: &gotgbot.ReplyParameters{ MessageId: replyToMsgId, }, + HasSpoiler: *imageMsg.ViewOnce, MessageThreadId: threadId, }) if sentMsg.MessageId != 0 { @@ -653,6 +654,7 @@ func MessageFromOthersEventHandler(text string, v *events.Message, isEdited bool ReplyParameters: &gotgbot.ReplyParameters{ MessageId: replyToMsgId, }, + HasSpoiler: *videoMsg.ViewOnce, MessageThreadId: threadId, }) if sentMsg.MessageId != 0 {