summaryrefslogtreecommitdiffstats
path: root/wat
diff options
context:
space:
mode:
authorGeorg Pfuetzenreuter2024-10-01 20:55:33 +0200
committerGeorg Pfuetzenreuter2024-10-02 20:03:56 +0200
commit89ed59a9c71e4b21e462a5c7746a8decc41dc487 (patch)
treeb04127246cf8950a881904771bb2249aebb385c4 /wat
parentd06e724f067deb55b8009b62be8e300fe79d1961 (diff)
downloadwatbot-89ed59a9c71e4b21e462a5c7746a8decc41dc487.tar.gz
watbot-89ed59a9c71e4b21e462a5c7746a8decc41dc487.tar.bz2
watbot-89ed59a9c71e4b21e462a5c7746a8decc41dc487.zip
Explain Jeopardy finishers parsing
Elaborate as the convoluted logic can be difficult to understand. Signed-off-by: Georg Pfuetzenreuter <mail@georg-pfuetzenreuter.net>
Diffstat (limited to 'wat')
-rw-r--r--wat/integration.go11
1 files changed, 11 insertions, 0 deletions
diff --git a/wat/integration.go b/wat/integration.go
index 833b9a3..b4ff8e9 100644
--- a/wat/integration.go
+++ b/wat/integration.go
@@ -54,9 +54,20 @@ func (w *WatIntegration) HandleIntegration(m *irc.Message, msgargs []string) boo
func (w *WatIntegration) Jeopardy(m *irc.Message, msgargs []string) {
// hey, I avoided regex!
+ // 1. Starts parsing an array of message arguments containing "Top finishers: (nick1: 1000) (nick2: 2000)", where
+ // the "($nick: $value)" pairs can contain arbitrary nicknames + integer values and can repeat one to any amount of times
+ // 2. Join the array on spaces to a string, but skip the first two elements to remove "Top" and "finishers:"
+ // 3. Replace ") (" in the string with ";" - the semicolon is chosen as a temporary delimiter because it does not conflict with any other characters in the message
+ // 4. Replace ": " in the string with ":"
+ // 5. Replace "(" in the string with "" (relevant for the first nick/value pair)
+ // 6. Replace ")" in the string with "" (relevant for the last nick/value pair)
+ // 7. Now, we have a string like "nick1:1000;nick2:2000" - split it back into an array on ";"
+ // 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)
+ // 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
nameCoinPair := strings.Split(pair, ":")
coins, err := strconv.ParseUint(nameCoinPair[1], 10, 64)
if err != nil {