5
0
mirror of https://github.com/cwinfo/matterbridge.git synced 2024-11-22 10:30:26 +00:00

Tidy up fetching of config values. (#616)

This commit is contained in:
Patrick Connolly 2018-12-01 07:24:07 +08:00 committed by Wim
parent f2088a687e
commit 47d29ecf63

View File

@ -233,14 +233,14 @@ func (gw *Gateway) handleMessage(msg config.Message, dest *bridge.Bridge) []*BrM
} }
// only relay join/part when configured // only relay join/part when configured
if msg.Event == config.EventJoinLeave && !gw.Bridges[dest.Account].GetBool("ShowJoinPart") { if msg.Event == config.EventJoinLeave && !dest.GetBool("ShowJoinPart") {
return brMsgIDs return brMsgIDs
} }
// only relay topic change when used in some way on other side // only relay topic change when used in some way on other side
if msg.Event == config.EventTopicChange && if msg.Event == config.EventTopicChange &&
!gw.Bridges[dest.Account].GetBool("ShowTopicChange") && dest.GetBool("ShowTopicChange") &&
!gw.Bridges[dest.Account].GetBool("SyncTopic") { dest.GetBool("SyncTopic") {
return brMsgIDs return brMsgIDs
} }
@ -252,7 +252,7 @@ func (gw *Gateway) handleMessage(msg config.Message, dest *bridge.Bridge) []*BrM
// Get the ID of the parent message in thread // Get the ID of the parent message in thread
var canonicalParentMsgID string var canonicalParentMsgID string
if msg.ParentID != "" && (gw.BridgeValues().General.PreserveThreading || dest.GetBool("PreserveThreading")) { if msg.ParentID != "" && dest.GetBool("PreserveThreading") {
canonicalParentMsgID = gw.FindCanonicalMsgID(msg.Protocol, msg.ParentID) canonicalParentMsgID = gw.FindCanonicalMsgID(msg.Protocol, msg.ParentID)
} }
@ -364,14 +364,11 @@ func (gw *Gateway) ignoreMessage(msg *config.Message) bool {
func (gw *Gateway) modifyUsername(msg config.Message, dest *bridge.Bridge) string { func (gw *Gateway) modifyUsername(msg config.Message, dest *bridge.Bridge) string {
br := gw.Bridges[msg.Account] br := gw.Bridges[msg.Account]
msg.Protocol = br.Protocol msg.Protocol = br.Protocol
if gw.BridgeValues().General.StripNick || dest.GetBool("StripNick") { if dest.GetBool("StripNick") {
re := regexp.MustCompile("[^a-zA-Z0-9]+") re := regexp.MustCompile("[^a-zA-Z0-9]+")
msg.Username = re.ReplaceAllString(msg.Username, "") msg.Username = re.ReplaceAllString(msg.Username, "")
} }
nick := dest.GetString("RemoteNickFormat") nick := dest.GetString("RemoteNickFormat")
if nick == "" {
nick = gw.BridgeValues().General.RemoteNickFormat
}
// loop to replace nicks // loop to replace nicks
for _, outer := range br.GetStringSlice2D("ReplaceNicks") { for _, outer := range br.GetStringSlice2D("ReplaceNicks") {
@ -409,10 +406,7 @@ func (gw *Gateway) modifyUsername(msg config.Message, dest *bridge.Bridge) strin
} }
func (gw *Gateway) modifyAvatar(msg config.Message, dest *bridge.Bridge) string { func (gw *Gateway) modifyAvatar(msg config.Message, dest *bridge.Bridge) string {
iconurl := gw.BridgeValues().General.IconURL iconurl := dest.GetString("IconURL")
if iconurl == "" {
iconurl = dest.GetString("IconURL")
}
iconurl = strings.Replace(iconurl, "{NICK}", msg.Username, -1) iconurl = strings.Replace(iconurl, "{NICK}", msg.Username, -1)
if msg.Avatar == "" { if msg.Avatar == "" {
msg.Avatar = iconurl msg.Avatar = iconurl