diff --git a/docs/user/config-file-glossary.rst b/docs/user/config-file-glossary.rst index 21beffc..00f8bf0 100644 --- a/docs/user/config-file-glossary.rst +++ b/docs/user/config-file-glossary.rst @@ -171,6 +171,9 @@ Telegram settings ``SHOW_DISCONNECT_MESSAGE=true`` Sends a message to Telegram when the bot disconnects from the IRC side. +``QUOTE_NICKNAME=false`` + Place IRC nickname in a blockquote section of the message to Telegram, instead of inline message prefix. + ************** Imgur settings ************** diff --git a/env.example b/env.example index c9282e7..554e81e 100644 --- a/env.example +++ b/env.example @@ -75,6 +75,7 @@ SHOW_NICK_MESSAGE=false SHOW_LEAVE_MESSAGE=false LEAVE_MESSAGE_ALLOW_LIST="" SHOW_DISCONNECT_MESSAGE=true +QUOTE_NICKNAME=false ################################################################################ diff --git a/internal/config.go b/internal/config.go index 4d22cc9..ddc78c6 100644 --- a/internal/config.go +++ b/internal/config.go @@ -65,6 +65,7 @@ type TelegramSettings struct { ShowNickMessage bool `env:"SHOW_NICK_MESSAGE" envDefault:"false"` ShowDisconnectMessage bool `env:"SHOW_DISCONNECT_MESSAGE" envDefault:"false"` MaxMessagePerMinute int `env:"MAX_MESSAGE_PER_MINUTE" envDefault:"20"` + QuoteNick bool `env:"QUOTE_NICKNAME" envDefault:"false"` } // ImgurSettings includes settings related to Imgur uploading for Telegram photos diff --git a/internal/handlers/irc/handlers.go b/internal/handlers/irc/handlers.go index be77130..5289d25 100644 --- a/internal/handlers/irc/handlers.go +++ b/internal/handlers/irc/handlers.go @@ -2,6 +2,7 @@ package irc import ( "fmt" + "html" "regexp" "strings" @@ -129,7 +130,13 @@ func messageHandler(c ClientInterface) func(*girc.Client, girc.Event) { // Strips out ACTION word from text formatted = "* " + e.Source.Name + msg[7:len(msg)-1] } else { - formatted = c.IRCSettings().Prefix + e.Source.Name + c.IRCSettings().Suffix + " " + e.Params[1] + if c.TgSettings().QuoteNick { + ircNicknameFormatted := c.IRCSettings().Prefix + e.Source.Name + c.IRCSettings().Suffix + ircMessageNoHtml := regexp.MustCompile(`<.*?>`).ReplaceAllString(e.Params[1], "") + formatted = "
" + html.EscapeString(ircNicknameFormatted) + "
\n" + html.EscapeString(strings.NewReplacer(">", "", "<", "").Replace(ircMessageNoHtml)) + } else { + formatted = c.IRCSettings().Prefix + e.Source.Name + c.IRCSettings().Suffix + " " + e.Params[1] + } } if hasNoForwardPrefix(c, e.Params[1]) { diff --git a/internal/handlers/telegram/telegram.go b/internal/handlers/telegram/telegram.go index 1479f86..fa4b5b1 100644 --- a/internal/handlers/telegram/telegram.go +++ b/internal/handlers/telegram/telegram.go @@ -33,6 +33,9 @@ SendMessage sends a message to the Telegram channel specified in the settings func (tg *Client) SendMessage(msg string) { newMsg := tgbotapi.NewMessage(tg.Settings.ChatID, "") newMsg.Text = msg + if tg.Settings.QuoteNick { + newMsg.ParseMode = "HTML" + } if _, err := tg.api.Send(newMsg); err != nil { var attempts int = 0