[perf] optimize string concatenation in resolveDiscordRefs

Co-authored-by: hobbyistlabs-coder <267281733+hobbyistlabs-coder@users.noreply.github.com>
This commit is contained in:
google-labs-jules[bot] 2026-03-13 08:45:07 +00:00
parent a9b93835e5
commit 48b96e4385

View file

@ -578,6 +578,11 @@ func (c *DiscordChannel) resolveDiscordRefs(s *discordgo.Session, text string, g
// 2. Expand Discord message links (max 3, same guild only)
matches := msgLinkRe.FindAllStringSubmatch(text, 3)
if len(matches) == 0 {
return text
}
var sb strings.Builder
sb.WriteString(text)
for _, m := range matches {
if len(m) < 4 {
continue
@ -595,10 +600,10 @@ func (c *DiscordChannel) resolveDiscordRefs(s *discordgo.Session, text string, g
if msg.Author != nil {
author = msg.Author.Username
}
text += fmt.Sprintf("\n[linked message from %s]: %s", author, msg.Content)
fmt.Fprintf(&sb, "\n[linked message from %s]: %s", author, msg.Content)
}
return text
return sb.String()
}
// stripBotMention removes the bot mention from the message content.