⚡ [perf] optimize string concatenation in resolveDiscordRefs
Co-authored-by: hobbyistlabs-coder <267281733+hobbyistlabs-coder@users.noreply.github.com>
This commit is contained in:
parent
a9b93835e5
commit
48b96e4385
1 changed files with 7 additions and 2 deletions
|
|
@ -578,6 +578,11 @@ func (c *DiscordChannel) resolveDiscordRefs(s *discordgo.Session, text string, g
|
||||||
|
|
||||||
// 2. Expand Discord message links (max 3, same guild only)
|
// 2. Expand Discord message links (max 3, same guild only)
|
||||||
matches := msgLinkRe.FindAllStringSubmatch(text, 3)
|
matches := msgLinkRe.FindAllStringSubmatch(text, 3)
|
||||||
|
if len(matches) == 0 {
|
||||||
|
return text
|
||||||
|
}
|
||||||
|
var sb strings.Builder
|
||||||
|
sb.WriteString(text)
|
||||||
for _, m := range matches {
|
for _, m := range matches {
|
||||||
if len(m) < 4 {
|
if len(m) < 4 {
|
||||||
continue
|
continue
|
||||||
|
|
@ -595,10 +600,10 @@ func (c *DiscordChannel) resolveDiscordRefs(s *discordgo.Session, text string, g
|
||||||
if msg.Author != nil {
|
if msg.Author != nil {
|
||||||
author = msg.Author.Username
|
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.
|
// stripBotMention removes the bot mention from the message content.
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue