Compare commits

...

2 Commits

Author SHA1 Message Date
ekzyis ca2ccc569d Fix parse error during game update 2024-10-16 05:21:24 +02:00
ekzyis 0a877f9f27 Fix API key env var 2024-10-16 05:06:55 +02:00
2 changed files with 10 additions and 6 deletions

View File

@ -1,3 +1,3 @@
SN_BASE_URL= SN_BASE_URL=
SN_API_TOKEN= SN_API_KEY=
SN_MEDIA_URL= SN_MEDIA_URL=

14
main.go
View File

@ -263,11 +263,12 @@ func parseGameStart(input string) (string, error) {
for _, line := range strings.Split(input, "\n") { for _, line := range strings.Split(input, "\n") {
line = strings.Trim(line, " ") line = strings.Trim(line, " ")
if !strings.HasPrefix(line, "@chess") { var found bool
if line, found = strings.CutPrefix(line, "@chess"); !found {
continue continue
} }
return strings.Trim(strings.ReplaceAll(line, "@chess", ""), " "), nil return strings.Trim(line, " "), nil
} }
return "", errors.New("failed to parse game start") return "", errors.New("failed to parse game start")
@ -278,15 +279,18 @@ func parseGameProgress(input string) (string, error) {
words := strings.Split(input, " ") words := strings.Split(input, " ")
if len(lines) == 1 && len(words) == 1 { if len(lines) == 1 && len(words) == 1 {
return strings.Trim(input, " "), nil return strings.Trim(strings.ReplaceAll(input, "@chess", ""), " "), nil
} }
for _, line := range strings.Split(input, "\n") { for _, line := range strings.Split(input, "\n") {
if !strings.Contains(line, "@chess") { line = strings.Trim(line, " ")
var found bool
if line, found = strings.CutPrefix(line, "@chess"); !found {
continue continue
} }
return strings.Trim(strings.ReplaceAll(line, "@chess", ""), " "), nil return strings.Trim(line, " "), nil
} }
return "", errors.New("failed to parse game update") return "", errors.New("failed to parse game update")