package jackbox import ( "regexp" "strings" ) // tickerVoteRe matches a ticker symbol (2-4 uppercase alphanumeric chars) // immediately followed by ++ or --. var tickerVoteRe = regexp.MustCompile(`(?i)\b([A-Z0-9]{2,4})(\+\+|--)`) // DetectVote checks if a message contains a vote and returns the vote type // and optional ticker symbol. // // For "thisgame++" / "thisgame--": returns (true, "up"/"down", "") // For "QPL3++" / "tmp2--": returns (true, "up"/"down", "QPL3"/"TMP2") // For non-vote messages: returns (false, "", "") func DetectVote(text string) (isVote bool, voteType string, ticker string) { lower := strings.ToLower(text) if strings.Contains(lower, "thisgame++") { return true, "up", "" } if strings.Contains(lower, "thisgame--") { return true, "down", "" } if m := tickerVoteRe.FindStringSubmatch(text); m != nil { sym := strings.ToUpper(m[1]) if _, ok := LookupTicker(sym); ok { if m[2] == "++" { return true, "up", sym } return true, "down", sym } } return false, "", "" } // IsRelayedMessage checks if a message is relayed from another chat // Returns true if the message has [irc] or [kosmi] prefix func IsRelayedMessage(text string) bool { lower := strings.ToLower(text) return strings.HasPrefix(lower, "[irc]") || strings.HasPrefix(lower, "[kosmi]") }