Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/user/config-file-glossary.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
**************
Expand Down
1 change: 1 addition & 0 deletions env.example
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ SHOW_NICK_MESSAGE=false
SHOW_LEAVE_MESSAGE=false
LEAVE_MESSAGE_ALLOW_LIST=""
SHOW_DISCONNECT_MESSAGE=true
QUOTE_NICKNAME=false


################################################################################
Expand Down
1 change: 1 addition & 0 deletions internal/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 8 additions & 1 deletion internal/handlers/irc/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package irc

import (
"fmt"
"html"
"regexp"
"strings"

Expand Down Expand Up @@ -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 = "<blockquote>" + html.EscapeString(ircNicknameFormatted) + "</blockquote>\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]) {
Expand Down
3 changes: 3 additions & 0 deletions internal/handlers/telegram/telegram.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down