bugfix: don't modifiy original message in Gateway.SendMessage()

This commit is contained in:
adbenitez 2023-04-13 10:46:13 -04:00
parent 56e7bd01ca
commit 28db5c80d6

View File

@ -323,7 +323,7 @@ func (gw *Gateway) ignoreFilesComment(extra map[string][]interface{}, igMessages
return false return false
} }
func (gw *Gateway) modifyUsername(msg *config.Message, dest *bridge.Bridge) string { func (gw *Gateway) modifyUsername(msg *config.Message, dest *bridge.Bridge) {
if 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, "")
@ -369,16 +369,15 @@ func (gw *Gateway) modifyUsername(msg *config.Message, dest *bridge.Bridge) stri
gw.logger.Errorf("modifyUsernameTengo error: %s", err) gw.logger.Errorf("modifyUsernameTengo error: %s", err)
} }
nick = strings.ReplaceAll(nick, "{TENGO}", tengoNick) nick = strings.ReplaceAll(nick, "{TENGO}", tengoNick)
return nick msg.Username = nick
} }
func (gw *Gateway) modifyAvatar(msg *config.Message, dest *bridge.Bridge) string { func (gw *Gateway) modifyAvatar(msg *config.Message, dest *bridge.Bridge) {
iconurl := dest.GetString("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
} }
return msg.Avatar
} }
func (gw *Gateway) modifyMessage(msg *config.Message) { func (gw *Gateway) modifyMessage(msg *config.Message) {
@ -461,8 +460,8 @@ func (gw *Gateway) SendMessage(
} }
msg.Channel = channel.Name msg.Channel = channel.Name
msg.Avatar = gw.modifyAvatar(rmsg, dest) gw.modifyAvatar(&msg, dest)
msg.Username = gw.modifyUsername(rmsg, dest) gw.modifyUsername(&msg, dest)
// exclude file delete event as the msg ID here is the native file ID that needs to be deleted // exclude file delete event as the msg ID here is the native file ID that needs to be deleted
if msg.Event != config.EventFileDelete { if msg.Event != config.EventFileDelete {