Refactor to use strings.Builder
Anirudh Oppiliappan x@icyphox.sh
Wed, 29 Dec 2021 17:47:50 +0530
1 files changed,
6 insertions(+),
8 deletions(-)
jump to
M
plugins/tell.go
→
plugins/tell.go
@@ -133,16 +133,14 @@ })
// Formatted tells in a slice, for joining into a string // later. - tellsFmtd := []string{} + tellsFmtd := strings.Builder{} for _, tell := range tells { - tellsFmtd = append( - tellsFmtd, - fmt.Sprintf( - "%s sent you a message %s: %s", - tell.From, humanize.Time(tell.Time), tell.Message, - ), + s := fmt.Sprintf( + "%s sent you a message %s: %s\n", + tell.From, humanize.Time(tell.Time), tell.Message, ) + tellsFmtd.WriteString(s) } - return strings.Join(tellsFmtd, "\n"), &IsPrivateNotice{To: tells[0].To} + return tellsFmtd.String(), &IsPrivateNotice{To: tells[0].To} } }