parseReactionValue converts a reaction value from YAML to a string. YAML parsers may return +1 and -1 as integers, so this function handles both string and numeric types.
(value any)
| 40 | // YAML parsers may return +1 and -1 as integers, so this function handles |
| 41 | // both string and numeric types. |
| 42 | func parseReactionValue(value any) (string, error) { |
| 43 | reactionsLog.Printf("Parsing reaction value: type=%T, value=%v", value, value) |
| 44 | |
| 45 | switch v := value.(type) { |
| 46 | case string: |
| 47 | reactionsLog.Printf("Parsed string reaction: %s", v) |
| 48 | return v, nil |
| 49 | case int: |
| 50 | result, err := intToReactionString(int64(v)) |
| 51 | if err != nil { |
| 52 | reactionsLog.Printf("Failed to parse int reaction: %v", err) |
| 53 | } |
| 54 | return result, err |
| 55 | case int64: |
| 56 | result, err := intToReactionString(v) |
| 57 | if err != nil { |
| 58 | reactionsLog.Printf("Failed to parse int64 reaction: %v", err) |
| 59 | } |
| 60 | return result, err |
| 61 | case uint64: |
| 62 | if v == 1 { |
| 63 | reactionsLog.Print("Parsed uint64 reaction: +1") |
| 64 | return "+1", nil |
| 65 | } |
| 66 | reactionsLog.Printf("Invalid uint64 reaction value: %d", v) |
| 67 | return "", fmt.Errorf("invalid reaction value '%d': must be one of %v", v, getValidReactions()) |
| 68 | case float64: |
| 69 | // YAML may parse +1 and -1 as float64 |
| 70 | if v == 1.0 { |
| 71 | reactionsLog.Print("Parsed float64 reaction: +1") |
| 72 | return "+1", nil |
| 73 | } |
| 74 | if v == -1.0 { |
| 75 | reactionsLog.Print("Parsed float64 reaction: -1") |
| 76 | return "-1", nil |
| 77 | } |
| 78 | reactionsLog.Printf("Invalid float64 reaction value: %f", v) |
| 79 | return "", fmt.Errorf("invalid reaction value '%v': must be one of %v", v, getValidReactions()) |
| 80 | default: |
| 81 | reactionsLog.Printf("Invalid reaction type: %T", value) |
| 82 | return "", fmt.Errorf("invalid reaction type: expected string, got %T", value) |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | // parseReactionConfig parses reaction configuration from frontmatter. |
| 87 | // Supported formats: |