Fixed bug where looks for attending status in 1st line, but not always there

This commit is contained in:
Harry Culpan 2024-01-21 01:01:38 -05:00
parent 1bbbbd0dd3
commit 3e1e091356
2 changed files with 12 additions and 6 deletions

1
.gitignore vendored
View file

@ -14,6 +14,7 @@ awp-cli
awp-cli.* awp-cli.*
players.json players.json
.DS_Store .DS_Store
.vscode
# air-related stuff # air-related stuff
tmp tmp

View file

@ -15,13 +15,17 @@ import (
func isAttending(body string) string { func isAttending(body string) string {
body = strings.ToLower(body) body = strings.ToLower(body)
lines := strings.Fields(body) lines := strings.Fields(body)
if strings.Contains(lines[0], "yes") {
for _, l := range lines {
line := strings.Trim(l, " \t\r\n")
if strings.HasPrefix(line, "yes") {
return "yes" return "yes"
} else if strings.Contains(lines[0], "no") { } else if strings.HasPrefix(line, "no") {
return "no" return "no"
} else {
return "unknown"
} }
}
return "unknown"
} }
// checkCmd represents the check command // checkCmd represents the check command
@ -41,6 +45,7 @@ will attend the next session.`,
if len(emails) == 0 { if len(emails) == 0 {
log.Default().Println("No new emails") log.Default().Println("No new emails")
} else { } else {
log.Default().Println("Reading new emails")
session, err := data.ReadSessionData() session, err := data.ReadSessionData()
if err != nil { if err != nil {
log.Default().Println(err) log.Default().Println(err)