Skip to content

Commit

Permalink
feat: making view_once messages become spoilers (#63)
Browse files Browse the repository at this point in the history
* feat: making view_once messages become spoilers

* feat(telegram): add spoiler_as_viewonce configuration option
  • Loading branch information
RianFC authored Oct 17, 2024
1 parent c44f3c7 commit 9fe2a76
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 4 deletions.
2 changes: 2 additions & 0 deletions sample_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions state/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions utils/telegram.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{},
Expand Down Expand Up @@ -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)),
Expand Down Expand Up @@ -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{},
Expand Down Expand Up @@ -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)),
Expand Down
2 changes: 2 additions & 0 deletions whatsapp/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 9fe2a76

Please sign in to comment.