From 2a5af5a2647f5965af6a3375d0206581727c70cd Mon Sep 17 00:00:00 2001 From: Bohdan Horbeshko Date: Tue, 8 Feb 2022 13:49:49 -0500 Subject: [PATCH] Add `rawmessages` configuration option --- persistence/sessions.go | 17 ++++++++++++++--- telegram/commands.go | 1 + telegram/handlers.go | 2 +- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/persistence/sessions.go b/persistence/sessions.go index b42d3a3..cfea675 100644 --- a/persistence/sessions.go +++ b/persistence/sessions.go @@ -34,14 +34,16 @@ type SessionsMap struct { // Session is a key-values subtree type Session struct { - Login string `yaml:":login"` - Timezone string `yaml:":timezone"` - KeepOnline bool `yaml:":keeponline"` + Login string `yaml:":login"` + Timezone string `yaml:":timezone"` + KeepOnline bool `yaml:":keeponline"` + RawMessages bool `yaml:":rawmessages"` } var configKeys = []string{ "timezone", "keeponline", + "rawmessages", } var sessionDB *SessionsYamlDB @@ -110,6 +112,8 @@ func (s *Session) Get(key string) (string, error) { return s.Timezone, nil case "keeponline": return fromBool(s.KeepOnline), nil + case "rawmessages": + return fromBool(s.RawMessages), nil } return "", errors.New("Unknown session property") @@ -139,6 +143,13 @@ func (s *Session) Set(key string, value string) (string, error) { } s.KeepOnline = b return value, nil + case "rawmessages": + b, err := toBool(value) + if err != nil { + return "", err + } + s.RawMessages = b + return value, nil } return "", errors.New("Unknown session property") diff --git a/telegram/commands.go b/telegram/commands.go index e8586d8..2847ceb 100644 --- a/telegram/commands.go +++ b/telegram/commands.go @@ -83,6 +83,7 @@ var chatCommands = map[string]command{ var transportConfigurationOptions = map[string]configurationOption{ "timezone": configurationOption{"", "adjust timezone for Telegram user statuses (example: +02:00)"}, "keeponline": configurationOption{"", "always keep telegram session online and rely on jabber offline messages (example: true)"}, + "rawmessages": configurationOption{"", "do not add additional info (message id, origin etc.) to incoming messages (example: true)"}, } type command struct { diff --git a/telegram/handlers.go b/telegram/handlers.go index 0eedc66..43a2291 100644 --- a/telegram/handlers.go +++ b/telegram/handlers.go @@ -210,7 +210,7 @@ func (c *Client) updateNewMessage(update *client.UpdateNewMessage) { } } // OTR support (I do not know why would you need it, seriously) - if !strings.HasPrefix(text, "?OTR") { + if !(strings.HasPrefix(text, "?OTR") || c.Session.RawMessages) { var prefix strings.Builder prefix.WriteString(c.messageToPrefix(update.Message, c.formatContent(file, filename))) if text != "" {