forked from lug/matterbridge
		
	Compare commits
	
		
			17 Commits
		
	
	
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
|   | 7811c330db | ||
|   | 9bcd131e66 | ||
|   | c791423dd5 | ||
|   | 80bdf38388 | ||
|   | 9d9cb32f4e | ||
|   | 87229bab13 | ||
|   | f065e9e4d5 | ||
|   | 3812693111 | ||
|   | dd3c572256 | ||
|   | c5dfe40326 | ||
|   | ef278301e3 | ||
|   | 2888fd64b0 | ||
|   | 27c0f37e49 | ||
|   | 0774f6a5e7 | ||
|   | 4036d4459b | ||
|   | ee643de5b6 | ||
|   | 8c7549a09e | 
| @@ -42,7 +42,7 @@ Accounts to one of the supported bridges | ||||
| # Installing | ||||
| ## Binaries | ||||
| Binaries can be found [here] (https://github.com/42wim/matterbridge/releases/) | ||||
| * Latest stable release [v0.12.0](https://github.com/42wim/matterbridge/releases/latest) | ||||
| * Latest stable release [v0.13.0](https://github.com/42wim/matterbridge/releases/latest) | ||||
|  | ||||
| ## Building | ||||
| Go 1.6+ is required. Make sure you have [Go](https://golang.org/doc/install) properly installed, including setting up your [GOPATH] (https://golang.org/doc/code.html#GOPATH) | ||||
|   | ||||
| @@ -100,7 +100,7 @@ func (b *Bridge) joinChannels(channels map[string]config.ChannelInfo, exists map | ||||
| 				log.Debugf("using key %s for channel %s", channel.Options.Key, channel.Name) | ||||
| 				mychannel = mychannel + " " + channel.Options.Key | ||||
| 			} | ||||
| 			err := b.JoinChannel(channel.Name) | ||||
| 			err := b.JoinChannel(mychannel) | ||||
| 			if err != nil { | ||||
| 				return err | ||||
| 			} | ||||
|   | ||||
| @@ -52,12 +52,14 @@ 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 | ||||
| 	Protocol               string //all protocols | ||||
| 	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 | ||||
| 	RemoteNickFormat       string // all protocols | ||||
| 	Server                 string // IRC,mattermost,XMPP,discord | ||||
| @@ -69,6 +71,7 @@ type Protocol struct { | ||||
| 	UseAPI                 bool   // mattermost, slack | ||||
| 	UseSASL                bool   // IRC | ||||
| 	UseTLS                 bool   // IRC | ||||
| 	UseFirstName           bool   // telegram | ||||
| } | ||||
|  | ||||
| type ChannelOptions struct { | ||||
|   | ||||
| @@ -140,6 +140,7 @@ func (b *bdiscord) messageCreate(s *discordgo.Session, m *discordgo.MessageCreat | ||||
| 		m.Message.Content = b.replaceRoleMentions(m.Message.Content) | ||||
| 	} | ||||
| 	m.Message.Content = b.stripCustomoji(m.Message.Content) | ||||
| 	m.Message.Content = b.replaceChannelMentions(m.Message.Content) | ||||
| 	b.Remote <- config.Message{Username: username, Text: m.ContentWithMentionsReplaced(), Channel: channelName, | ||||
| 		Account: b.Account, Avatar: "https://cdn.discordapp.com/avatars/" + m.Author.ID + "/" + m.Author.Avatar + ".jpg"} | ||||
| } | ||||
| @@ -158,12 +159,14 @@ func (b *bdiscord) getNick(user *discordgo.User) string { | ||||
| 	b.Lock() | ||||
| 	defer b.Unlock() | ||||
| 	if _, ok := b.userMemberMap[user.ID]; ok { | ||||
| 		if b.userMemberMap[user.ID].Nick != "" { | ||||
| 			// only return if nick is set | ||||
| 			return b.userMemberMap[user.ID].Nick | ||||
| 		if b.userMemberMap[user.ID] != nil { | ||||
| 			if b.userMemberMap[user.ID].Nick != "" { | ||||
| 				// only return if nick is set | ||||
| 				return b.userMemberMap[user.ID].Nick | ||||
| 			} | ||||
| 			// otherwise return username | ||||
| 			return user.Username | ||||
| 		} | ||||
| 		// otherwise return username | ||||
| 		return user.Username | ||||
| 	} | ||||
| 	// if we didn't find nick, search for it | ||||
| 	b.userMemberMap[user.ID], err = b.c.GuildMember(b.guildID, user.ID) | ||||
| @@ -211,6 +214,25 @@ func (b *bdiscord) replaceRoleMentions(text string) string { | ||||
| 	return text | ||||
| } | ||||
|  | ||||
| func (b *bdiscord) replaceChannelMentions(text string) string { | ||||
| 	var err error | ||||
| 	re := regexp.MustCompile("<#[0-9]+>") | ||||
| 	text = re.ReplaceAllStringFunc(text, func(m string) string { | ||||
| 		channel := b.getChannelName(m[2 : len(m)-1]) | ||||
| 		// if at first don't succeed, try again | ||||
| 		if channel == "" { | ||||
| 			b.Channels, err = b.c.GuildChannels(b.guildID) | ||||
| 			if err != nil { | ||||
| 				return "#unknownchannel" | ||||
| 			} | ||||
| 			channel = b.getChannelName(m[2 : len(m)-1]) | ||||
| 			return channel | ||||
| 		} | ||||
| 		return channel | ||||
| 	}) | ||||
| 	return text | ||||
| } | ||||
|  | ||||
| func (b *bdiscord) stripCustomoji(text string) string { | ||||
| 	// <:doge:302803592035958784> | ||||
| 	re := regexp.MustCompile("<(:.*?:)[0-9]+>") | ||||
|   | ||||
| @@ -46,6 +46,9 @@ func New(cfg config.Protocol, account string, c chan config.Message) *Birc { | ||||
| 	if b.Config.MessageQueue == 0 { | ||||
| 		b.Config.MessageQueue = 30 | ||||
| 	} | ||||
| 	if b.Config.MessageLength == 0 { | ||||
| 		b.Config.MessageLength = 400 | ||||
| 	} | ||||
| 	return b | ||||
| } | ||||
|  | ||||
| @@ -111,6 +114,9 @@ func (b *Birc) Send(msg config.Message) error { | ||||
| 		b.Command(&msg) | ||||
| 	} | ||||
| 	for _, text := range strings.Split(msg.Text, "\n") { | ||||
| 		if len(text) > b.Config.MessageLength { | ||||
| 			text = text[:b.Config.MessageLength] + " <message clipped>" | ||||
| 		} | ||||
| 		if len(b.Local) < b.Config.MessageQueue { | ||||
| 			if len(b.Local) == b.Config.MessageQueue-1 { | ||||
| 				text = text + " <message clipped>" | ||||
|   | ||||
| @@ -1,10 +1,12 @@ | ||||
| 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 { | ||||
| @@ -101,8 +103,13 @@ 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) | ||||
| 	}) | ||||
|   | ||||
| @@ -89,9 +89,6 @@ func (b *Bslack) JoinChannel(channel string) error { | ||||
|  | ||||
| func (b *Bslack) Send(msg config.Message) error { | ||||
| 	flog.Debugf("Receiving %#v", msg) | ||||
| 	if msg.Account == b.Account { | ||||
| 		return nil | ||||
| 	} | ||||
| 	nick := msg.Username | ||||
| 	message := msg.Text | ||||
| 	channel := msg.Channel | ||||
|   | ||||
| @@ -76,11 +76,11 @@ func (b *Btelegram) Send(msg config.Message) error { | ||||
| } | ||||
|  | ||||
| func (b *Btelegram) handleRecv(updates <-chan tgbotapi.Update) { | ||||
| 	username := "" | ||||
| 	text := "" | ||||
| 	channel := "" | ||||
| 	for update := range updates { | ||||
| 		var message *tgbotapi.Message | ||||
| 		username := "" | ||||
| 		channel := "" | ||||
| 		text := "" | ||||
| 		// handle channels | ||||
| 		if update.ChannelPost != nil { | ||||
| 			message = update.ChannelPost | ||||
| @@ -98,9 +98,14 @@ func (b *Btelegram) handleRecv(updates <-chan tgbotapi.Update) { | ||||
| 			message.Text = message.Text + b.Config.EditSuffix | ||||
| 		} | ||||
| 		if message.From != nil { | ||||
| 			username = message.From.FirstName | ||||
| 			if b.Config.UseFirstName { | ||||
| 				username = message.From.FirstName | ||||
| 			} | ||||
| 			if username == "" { | ||||
| 				username = message.From.UserName | ||||
| 				if username == "" { | ||||
| 					username = message.From.FirstName | ||||
| 				} | ||||
| 			} | ||||
| 			text = message.Text | ||||
| 			channel = strconv.FormatInt(message.Chat.ID, 10) | ||||
|   | ||||
| @@ -119,7 +119,7 @@ func (b *Bxmpp) handleXmpp() error { | ||||
| 			var channel, nick string | ||||
| 			if v.Type == "groupchat" { | ||||
| 				s := strings.Split(v.Remote, "@") | ||||
| 				if len(s) == 2 { | ||||
| 				if len(s) >= 2 { | ||||
| 					channel = s[0] | ||||
| 				} | ||||
| 				s = strings.Split(s[1], "/") | ||||
|   | ||||
							
								
								
									
										34
									
								
								changelog.md
									
									
									
									
									
								
							
							
						
						
									
										34
									
								
								changelog.md
									
									
									
									
									
								
							| @@ -1,3 +1,27 @@ | ||||
| # v0.13.0 | ||||
| ## New features | ||||
| * irc: Limit message length. ```MessageLength=400``` | ||||
|   Maximum length of message sent to irc server. If it exceeds <message clipped> will be add to the message. | ||||
| * irc: Add NOPINGNICK option.  | ||||
|   The string "{NOPINGNICK}" (case sensitive) will be replaced by the actual nick / username, but with a ZWSP inside the nick, so the irc user with the same nick won't get pinged.    | ||||
|   See https://github.com/42wim/matterbridge/issues/175 for more information | ||||
|  | ||||
| ## Bugfix | ||||
| * slack: Fix sending to different channels on same account (slack). Closes #177 | ||||
| * telegram: Fix incorrect usernames being sent. Closes #181 | ||||
|  | ||||
|  | ||||
| # v0.12.1 | ||||
| ## New features | ||||
| * telegram: Add UseFirstName option (telegram). Closes #144 | ||||
| * matrix: Add NoHomeServerSuffix. Option to disable homeserver on username (matrix). Closes #160. | ||||
|  | ||||
| ## Bugfix | ||||
| * xmpp: Add Compatibility for Cisco Jabber (xmpp) (#166) | ||||
| * irc: Fix JoinChannel argument to use IRC channel key (#172) | ||||
| * discord: Fix possible crash on nil (discord) | ||||
| * discord: Replace long ids in channel metions (discord). Fixes #174 | ||||
|  | ||||
| # v0.12.0 | ||||
| ## Changes | ||||
| * general: edited messages are now being sent by default on discord/mattermost/telegram/slack. See "New Features" | ||||
| @@ -6,10 +30,15 @@ | ||||
| * general: add support for edited messages.  | ||||
|   Add new keyword EditDisable (false/true), default false. Which means by default edited messages will be sent to other bridges. | ||||
|   Add new keyword EditSuffix , default "". You can change this eg to "(edited)", this will be appended to every edit message. | ||||
|  | ||||
| ## Enhancements | ||||
| * mattermost: support mattermost v3.9.x | ||||
| * general: Add support for HTTP{S}_PROXY env variables (#162) | ||||
| * discord: Strip custom emoji metadata (discord). Closes #148 | ||||
|  | ||||
| ## Bugfix | ||||
| * slack: Ignore error on private channel join (slack) Fixes #150  | ||||
| * mattermost: fix crash on reconnects when server is down. Closes #163 | ||||
| * irc: Relay messages starting with ! (irc). Closes #164 | ||||
|  | ||||
| # v0.11.0 | ||||
| ## New features | ||||
| * general: reusing the same account on multiple gateways now also reuses the connection. | ||||
| @@ -18,6 +47,7 @@ | ||||
| * telegram:  Support edited messages (telegram). See #141 | ||||
| * mattermost: Add support for showing/hiding join/leave messages from mattermost. Closes #147 | ||||
| * mattermost: Reconnect on session removal/timeout (mattermost) | ||||
| * mattermost: Support mattermost v3.8.x | ||||
| * irc:  Rejoin channel when kicked (irc). | ||||
|  | ||||
| ## Bugfix | ||||
|   | ||||
| @@ -192,9 +192,10 @@ func (gw *Gateway) handleMessage(msg config.Message, dest *bridge.Bridge) { | ||||
| 		return | ||||
| 	} | ||||
| 	originchannel := msg.Channel | ||||
| 	origmsg := msg | ||||
| 	for _, channel := range gw.DestChannelFunc(&msg, *dest) { | ||||
| 		// do not send to ourself | ||||
| 		if channel.ID == getChannelID(msg) { | ||||
| 		if channel.ID == getChannelID(origmsg) { | ||||
| 			continue | ||||
| 		} | ||||
| 		log.Debugf("Sending %#v from %s (%s) to %s (%s)", msg, msg.Account, originchannel, dest.Account, channel.Name) | ||||
| @@ -233,6 +234,7 @@ func (gw *Gateway) modifyUsername(msg *config.Message, dest *bridge.Bridge) { | ||||
| 	if nick == "" { | ||||
| 		nick = dest.Config.RemoteNickFormat | ||||
| 	} | ||||
| 	nick = strings.Replace(nick, "{NOPINGNICK}", msg.Username[:1]+""+msg.Username[1:], -1) | ||||
| 	nick = strings.Replace(nick, "{NICK}", msg.Username, -1) | ||||
| 	nick = strings.Replace(nick, "{BRIDGE}", br.Name, -1) | ||||
| 	nick = strings.Replace(nick, "{PROTOCOL}", br.Protocol, -1) | ||||
|   | ||||
| @@ -12,7 +12,7 @@ import ( | ||||
| ) | ||||
|  | ||||
| var ( | ||||
| 	version = "0.12.0" | ||||
| 	version = "0.13.0" | ||||
| 	githash string | ||||
| ) | ||||
|  | ||||
|   | ||||
| @@ -48,10 +48,15 @@ MessageDelay=1300 | ||||
|  | ||||
| #Maximum amount of messages to hold in queue. If queue is full  | ||||
| #messages will be dropped.  | ||||
| #<clipped> will be add to the message that fills the queue. | ||||
| #<message clipped> will be add to the message that fills the queue. | ||||
| #OPTIONAL (default 30) | ||||
| MessageQueue=30 | ||||
|  | ||||
| #Maximum length of message sent to irc server. If it exceeds | ||||
| #<message clipped> will be add to the message. | ||||
| #OPTIONAL (default 400) | ||||
| MessageLength=400 | ||||
|  | ||||
| #Nicks you want to ignore.  | ||||
| #Messages from those users will not be sent to other bridges. | ||||
| #OPTIONAL | ||||
| @@ -61,6 +66,7 @@ IgnoreNicks="ircspammer1 ircspammer2" | ||||
| #The string "{NICK}" (case sensitive) will be replaced by the actual nick / username. | ||||
| #The string "{BRIDGE}" (case sensitive) will be replaced by the sending bridge | ||||
| #The string "{PROTOCOL}" (case sensitive) will be replaced by the protocol used by the bridge | ||||
| #The string "{NOPINGNICK}" (case sensitive) will be replaced by the actual nick / username, but with a ZWSP inside the nick, so the irc user with the same nick won't get pinged. See https://github.com/42wim/matterbridge/issues/175 for more information | ||||
| #OPTIONAL (default empty) | ||||
| RemoteNickFormat="[{PROTOCOL}] <{NICK}> " | ||||
|  | ||||
| @@ -451,6 +457,12 @@ Token="Yourtokenhere" | ||||
| #See https://core.telegram.org/bots/api#html-style | ||||
| MessageFormat="" | ||||
|  | ||||
| #If enabled use the "First Name" as username. If this is empty use the Username | ||||
| #If disabled use the "Username" as username. If this is empty use the First Name  | ||||
| #If all names are empty, username will be "unknown" | ||||
| #OPTIONAL (default false) | ||||
| UseFirstName=false | ||||
|  | ||||
| #Disable sending of edits to other bridges | ||||
| #OPTIONAL (default false) | ||||
| EditDisable=false | ||||
| @@ -554,6 +566,11 @@ Server="https://matrix.org" | ||||
| Login="yourlogin" | ||||
| Password="yourpass" | ||||
|  | ||||
| #Whether to send the homeserver suffix. eg ":matrix.org" in @username:matrix.org | ||||
| #to other bridges, or only send "username".(true only sends username) | ||||
| #OPTIONAL (default false) | ||||
| NoHomeServerSuffix=false | ||||
|  | ||||
| #Whether to prefix messages from other bridges to matrix with the sender's nick.  | ||||
| #Useful if username overrides for incoming webhooks isn't enabled on the  | ||||
| #matrix server. If you set PrefixMessagesWithNick to true, each message  | ||||
| @@ -657,7 +674,8 @@ enable=true | ||||
|     #             see (https://www.linkedin.com/pulse/telegram-bots-beginners-marco-frau) | ||||
|     #hipchat    - id_channel (see https://www.hipchat.com/account/xmpp for the correct channel) | ||||
|     #rocketchat - #channel (# is required) | ||||
|     #matrix     - #channel:server (eg #yourchannel:matrix.org) | ||||
|     #matrix     - #channel:server (eg #yourchannel:matrix.org)  | ||||
|     #           - encrypted rooms are not supported in matrix | ||||
|     #REQUIRED | ||||
|     channel="#testing" | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user