Skip to content

Commit

Permalink
Properly handle kibitz and whispers
Browse files Browse the repository at this point in the history
Earlier kibitzes were handles as personal tells. Now kibitz and whispers
are appropriately handled as group tells.
  • Loading branch information
Free Chess Club Dev committed Jan 20, 2022
1 parent 939b56c commit 6e06252
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ var (
gameEndRE *regexp.Regexp
chTellRE *regexp.Regexp
pTellRE *regexp.Regexp
kibitzRE *regexp.Regexp
toldMsgRE *regexp.Regexp
)

Expand Down Expand Up @@ -47,10 +48,13 @@ func init() {
chTellRE = regexp.MustCompile(`(?s)^([a-zA-Z]+)(?:\([A-Z\*]+\))*\(([0-9]+)\):\s+(.*)`)

// private tell
pTellRE = regexp.MustCompile(`(?s)^([a-zA-Z]+)(?:[\(\[][A-Z0-9\*\-]+[\)\]])* (?:tells you|says|kibitzes):\s+(.*)`)
pTellRE = regexp.MustCompile(`(?s)^([a-zA-Z]+)(?:[\(\[][A-Z0-9\*\-]+[\)\]])* (?:tells you|says):\s+(.*)`)

// kibitz/whispers
kibitzRE = regexp.MustCompile(`(?s)^([a-zA-Z]+)(?:\([A-Z0-9\*\-]+\))*\[([0-9]+)\] (?:kibitzes|whispers):\s+(.*)`)

// told status
toldMsgRE = regexp.MustCompile(`\(told .+\)`)
toldMsgRE = regexp.MustCompile(`\((?:told|kibitzed) .+\)`)
}

func style12ToFEN(b []byte) string {
Expand Down Expand Up @@ -226,6 +230,17 @@ func decodeMessages(msg []byte) []interface{} {
}
}

matches = kibitzRE.FindSubmatch(msg)
if matches != nil && len(matches) > 3 {
return []interface{}{
&ChannelTell{
Channel: "Game " + string(matches[2][:]),
User: string(matches[1][:]),
Message: string(bytes.Replace(matches[3][:], []byte("\n"), []byte{}, -1)),
},
}
}

return []interface{}{
&Message{
Message: string(msg),
Expand Down

0 comments on commit 6e06252

Please sign in to comment.