feat: add prediction and omit empty Buy/Sell

This commit is contained in:
ytshih committed 2026-09-07 09:04:34 +08:00
1 parent 521588f992
commit ba63c5deb0
5 files changed
+99 -54

No files matched your search

+17 -15
View File
@@ -63,9 +63,10 @@ func (d *discordOutput) Send(ctx context.Context, rep report.Report) error {
}
}
embeds := buildRecommendationEmbeds(rep.Recommendations)
if err := d.postEmbeds(ctx, embeds); err != nil {
return fmt.Errorf("discord: send recommendation embeds: %w", err)
if embeds := buildRecommendationEmbeds(rep.Recommendations); len(embeds) > 0 {
if err := d.postEmbeds(ctx, embeds); err != nil {
return fmt.Errorf("discord: send recommendation embeds: %w", err)
}
}
return nil
}
@@ -113,9 +114,10 @@ const (
// embed's `description`.
const discordDescriptionLimit = 4096
// buildRecommendationEmbeds renders the buy and sell recommendations as two
// separate Discord embeds (always both, even when one or both lists are
// empty, so "nothing to report" is stated explicitly rather than omitted).
// buildRecommendationEmbeds renders the buy and sell recommendations as
// separate Discord embeds, one per non-empty list. If there are no
// recommendations at all, it returns nil and no message is sent — an empty
// buy/sell call isn't worth a Discord notification.
func buildRecommendationEmbeds(recs []report.Recommendation) []map[string]any {
var buyLines, sellLines []string
for _, r := range recs {
@@ -127,21 +129,21 @@ func buildRecommendationEmbeds(recs []report.Recommendation) []map[string]any {
}
}
return []map[string]any{
recommendationEmbed("🟢 Buy", colorBuy, buyLines, "No buy recommendations today."),
recommendationEmbed("🔴 Sell", colorSell, sellLines, "No sell recommendations today."),
var embeds []map[string]any
if len(buyLines) > 0 {
embeds = append(embeds, recommendationEmbed("🟢 Buy", colorBuy, buyLines))
}
if len(sellLines) > 0 {
embeds = append(embeds, recommendationEmbed("🔴 Sell", colorSell, sellLines))
}
return embeds
}
func recommendationEmbed(title string, color int, lines []string, emptyText string) map[string]any {
description := emptyText
if len(lines) > 0 {
description = truncateForDescription(strings.Join(lines, "\n"))
}
func recommendationEmbed(title string, color int, lines []string) map[string]any {
return map[string]any{
"title": title,
"color": color,
"description": description,
"description": truncateForDescription(strings.Join(lines, "\n")),
}
}