Skip to content

Commit 4b8d69a

Browse files
leamirSouthclaws
authored andcommitted
Truncate long descriptions
1 parent 2b2b5f1 commit 4b8d69a

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

bot/commands/cmd_wiki.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@ const (
2626
algoliaInsights = false
2727
)
2828

29+
func truncateText(s string, max int) string {
30+
if max > len(s) {
31+
return s
32+
}
33+
return s[:strings.LastIndex(s[:max], " ")] + " ..."
34+
}
35+
2936
func (cm *CommandManager) commandWiki(
3037
interaction *discordgo.InteractionCreate,
3138
args map[string]*discordgo.ApplicationCommandInteractionDataOption,
@@ -123,7 +130,7 @@ func (cm *CommandManager) commandWiki(
123130
hitData["url_without_anchor"].(string),
124131
stringParts[len(stringParts)-3],
125132
stringParts[len(stringParts)-2],
126-
description,
133+
truncateText(description, 200),
127134
))
128135
}
129136

0 commit comments

Comments
 (0)