Thumbnail

rani/matterbridge.git

Clone URL: https://git.buni.party/rani/matterbridge.git

commit 6549ca493a0be504ab7eb439d330104738e53c44 Author: Wim <wim@42.be> Date: Fri May 12 23:04:58 2017 +0000 Add NoHomeServerSuffix. Option to disable homeserver on username (matrix). Closes #160. diff --git a/bridge/config/config.go b/bridge/config/config.go index a08ae00..6f34131 100644 --- a/bridge/config/config.go +++ b/bridge/config/config.go @@ -526 +527 @@ type Protocol struct {   NickServNick string // IRC   NickServPassword string // IRC   NicksPerRow int // mattermost, slack + NoHomeServerSuffix bool // matrix   NoTLS bool // mattermost   Password string // IRC,mattermost,XMPP,matrix   PrefixMessagesWithNick bool // mattemost, slack diff --git a/bridge/matrix/matrix.go b/bridge/matrix/matrix.go index add7e40..628e8d9 100644 --- a/bridge/matrix/matrix.go +++ b/bridge/matrix/matrix.go @@ -110 +112 @@  package bmatrix    import ( + "regexp" + "sync" +   "github.com/42wim/matterbridge/bridge/config"   log "github.com/Sirupsen/logrus"   matrix "github.com/matrix-org/gomatrix" - "sync"  )    type Bmatrix struct { @@ -1018 +10313 @@ func (b *Bmatrix) handlematrix() error {   flog.Debugf("Unknown room %s", ev.RoomID)   return   } + username := ev.Sender[1:] + if b.Config.NoHomeServerSuffix { + re := regexp.MustCompile("(.*?):.*") + username = re.ReplaceAllString(username, `$1`) + }   flog.Debugf("Sending message from %s on %s to gateway", ev.Sender, b.Account) - b.Remote <- config.Message{Username: ev.Sender, Text: ev.Content["body"].(string), Channel: channel, Account: b.Account} + b.Remote <- config.Message{Username: username, Text: ev.Content["body"].(string), Channel: channel, Account: b.Account}   }   flog.Debugf("Received: %#v", ev)   })