diff options
author | Pratyush Desai | 2024-10-03 19:55:50 +0200 |
---|---|---|
committer | Pratyush Desai | 2024-10-03 19:55:50 +0200 |
commit | c4ff70da702f47e7d5499778ad791e0c8d9812aa (patch) | |
tree | ea1ae6f0e37a1c1c72626210047974842327b0c6 /wat/integration.go | |
parent | b6187e007792836c3c29d6925a3fa97cb23791bf (diff) | |
parent | 7ec49a9769d10dd66e1c30f579aba715ea8e7447 (diff) | |
download | watbot-c4ff70da702f47e7d5499778ad791e0c8d9812aa.tar.gz watbot-c4ff70da702f47e7d5499778ad791e0c8d9812aa.tar.bz2 watbot-c4ff70da702f47e7d5499778ad791e0c8d9812aa.zip |
Merge pull request 'Improve Jeopardy cashout message' (#24) from jeopardymsg into master
Reviewed-on: https://git.com.de/LibertaCasa/watbot/pulls/24
Diffstat (limited to 'wat/integration.go')
-rw-r--r-- | wat/integration.go | 40 |
1 files changed, 36 insertions, 4 deletions
diff --git a/wat/integration.go b/wat/integration.go index b4ff8e9..2b2329e 100644 --- a/wat/integration.go +++ b/wat/integration.go @@ -65,6 +65,23 @@ func (w *WatIntegration) Jeopardy(m *irc.Message, msgargs []string) { // 8. The result is an array like "[nick1:1000, nick2:2000]" finisherPrizes := strings.Split(strings.Replace(strings.Replace(strings.Replace(strings.Replace(strings.Join(msgargs[2:], " "), ") (", ";", -1), ": ", ":", -1), "(", "", 1), ")", "", 1), ";") fmt.Printf("Processing Jeopardy: %s\n", finisherPrizes) + var msg string + var many bool + fiprcount := len(finisherPrizes) + cashoutcount := 0 + // only a single winner + if fiprcount == 1 { + msg = "smartass %s :) gave u %d" + many = false + // multiple winners + } else if fiprcount > 1 { + msg = "gang of smartasses :) gave %s %d" + many = true + // no winners (should never get here) + } else { + fmt.Printf("Empty finishers, aborting Jeopardy processing") + return + } // iterate over the "$nick:$value" string elements for _, pair := range finisherPrizes { // turn the string element into an array, where the first entry is the nickname, and the second the value @@ -77,6 +94,10 @@ func (w *WatIntegration) Jeopardy(m *irc.Message, msgargs []string) { name := nameCoinPair[0] // Jeopardy prizes are quite a lot of $$$, make it a bit more sane coins = coins / 40 + if coins == 0 { + continue + } + cashoutcount += 1 // name = we assume the Jeopardy player name to match a Watbot player name // host = we could use some WHO logic to find the host, but assuming nickname lookup to be sufficient here // create = based on the above, maybe rather not create Watbot players based on only a nick? @@ -85,10 +106,21 @@ func (w *WatIntegration) Jeopardy(m *irc.Message, msgargs []string) { if player.Nick == "" { fmt.Printf("Player %s does not exist in Watbot, skipping cashout.\n", name) continue - } else { - w.bot.reply(m, fmt.Sprintf("smartass %s, gave u %d :)", player.Nick, coins)) - player.Coins += coins - w.db.Update(player) } + // fill previous format placeholders + msg = fmt.Sprintf(msg, player.Nick, coins) + if many { + // append additional ones for filling in the next loop iteration + msg = msg + ", %s %d" + } + player.Coins += coins + w.db.Update(player) + } + if many { + // remove format placeholders from last loop iteration + msg = strings.Replace(msg, ", %s %d", ".", 1) + } + if cashoutcount > 0 { + w.bot.reply(m, msg) } } |