Add support for ReplaceNicks using regexp to replace nicks. Closes #269

This commit is contained in:
Wim 2017-11-20 23:27:27 +01:00
parent 98762a0235
commit cd4c9b194f
2 changed files with 21 additions and 6 deletions

View File

@ -59,6 +59,10 @@ type Protocol struct {
IgnoreMessages string // all protocols IgnoreMessages string // all protocols
Jid string // xmpp Jid string // xmpp
Login string // mattermost, matrix Login string // mattermost, matrix
MessageQueue int // IRC, size of message queue for flood control
MessageDelay int // IRC, time in millisecond to wait between messages
MessageLength int // IRC, max length of a message allowed
MessageFormat string // telegram
Muc string // xmpp Muc string // xmpp
Name string // all protocols Name string // all protocols
Nick string // all protocols Nick string // all protocols
@ -71,12 +75,9 @@ type Protocol struct {
NoTLS bool // mattermost NoTLS bool // mattermost
Password string // IRC,mattermost,XMPP,matrix Password string // IRC,mattermost,XMPP,matrix
PrefixMessagesWithNick bool // mattemost, slack PrefixMessagesWithNick bool // mattemost, slack
Protocol string //all protocols Protocol string // all protocols
ReplaceMessages [][]string // all messages ReplaceMessages [][]string // all protocols
MessageQueue int // IRC, size of message queue for flood control ReplaceNicks [][]string // all protocols
MessageDelay int // IRC, time in millisecond to wait between messages
MessageLength int // IRC, max length of a message allowed
MessageFormat string // telegram
RemoteNickFormat string // all protocols RemoteNickFormat string // all protocols
Server string // IRC,mattermost,XMPP,discord Server string // IRC,mattermost,XMPP,discord
ShowJoinPart bool // all protocols ShowJoinPart bool // all protocols

View File

@ -254,6 +254,20 @@ func (gw *Gateway) modifyUsername(msg config.Message, dest *bridge.Bridge) strin
if nick == "" { if nick == "" {
nick = gw.Config.General.RemoteNickFormat nick = gw.Config.General.RemoteNickFormat
} }
// loop to replace nicks
for _, outer := range br.Config.ReplaceNicks {
search := outer[0]
replace := outer[1]
// TODO move compile to bridge init somewhere
re, err := regexp.Compile(search)
if err != nil {
log.Errorf("regexp in %s failed: %s", msg.Account, err)
break
}
msg.Username = re.ReplaceAllString(msg.Username, replace)
}
if len(msg.Username) > 0 { if len(msg.Username) > 0 {
// fix utf-8 issue #193 // fix utf-8 issue #193
i := 0 i := 0