Add ticker symbol voting (e.g. QPL3++, TMP2--)
Extend vote detection to recognize game ticker symbols alongside the existing thisgame++/-- syntax. Each symbol maps to a specific game so users can vote for any game by its stock-style ticker. The matched ticker is sent to the API via a new optional `ticker` field in the vote request. Made-with: Cursor
This commit is contained in:
@@ -1,23 +1,42 @@
|
||||
package jackbox
|
||||
|
||||
import "strings"
|
||||
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
|
||||
// Returns (true, "up") for thisgame++
|
||||
// Returns (true, "down") for thisgame--
|
||||
// Returns (false, "") for non-vote messages
|
||||
func DetectVote(text string) (isVote bool, voteType string) {
|
||||
// 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"
|
||||
return true, "up", ""
|
||||
}
|
||||
|
||||
|
||||
if strings.Contains(lower, "thisgame--") {
|
||||
return true, "down"
|
||||
return true, "down", ""
|
||||
}
|
||||
|
||||
return false, ""
|
||||
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user