diff --git a/main.go b/main.go index 5f202a5..32dce77 100644 --- a/main.go +++ b/main.go @@ -430,7 +430,76 @@ func main() { case !isChannel && strings.EqualFold(cmd.Name, "updatetopics"): updateTopicsChan <- nil - case strings.EqualFold(cmd.Name, "!table"): + case strings.EqualFold(cmd.Name, "!country"), + strings.EqualFold(cmd.Name, "!team"): + teamList, err := footballData.TeamsOfCompetition(Competition).Do() + if err != nil { + conn.Noticef(sender, "Sorry, can't display team information at this moment.") + log.Print(err) + } + + // find correct team + name := strings.Join(cmd.Arguments, " ") + for _, competitionTeam := range teamList.Teams { + if strings.EqualFold(competitionTeam.Name, name) || + // strings.EqualFold(team.Code, name) || + strings.EqualFold(competitionTeam.ShortName, name) { + // found matching team + if competitionTeam.Id == 0 { + conn.Noticef(sender, "Sorry, something went horribly wrong here.") + log.Print("Returned team ID of a team in competition was 0...") + } + + fixtures, err := footballData.FixturesOfTeam(competitionTeam.Id). + // Season(Competition). + Do() + if err != nil { + conn.Noticef(sender, "Sorry, could not fetch fixtures information at this moment.") + log.Print(err) + return + } + outputs := []string{} + for _, fixture := range fixtures.Fixtures { + homeTeam := fixture.HomeTeamName + awayTeam := fixture.AwayTeamName + var vs string + switch fixture.Status { + case footballdata.FixtureStatus_InPlay, + footballdata.FixtureStatus_Canceled, + footballdata.FixtureStatus_Finished: + // finished, display score + vs = fmt.Sprintf("%d:%d", + fixture.Result.GoalsHomeTeam, + fixture.Result.GoalsAwayTeam) + default: + // upcoming, display time + vs = fmt.Sprintf("[%s]", + fixture.Date.Format("Jan 02 @ 15:04 MST")) + } + outputs = append(outputs, + fmt.Sprintf("%s %s %s", + homeTeam, vs, awayTeam)) + } + + conn.Privmsg(target, strings.Join(outputs, " | ")) + + return + } + } + + conn.Noticef(sender, "Sorry, I don't know this team.") + + // Not implemented - football-data api data not reliable enough? + case strings.EqualFold(cmd.Name, "!player"): + // TODO + conn.Noticef(sender, "Sorry, this isn't implemented yet.") + + // Currently implemented: + // - !group / !group (for example !group a) + // Not implemented yet: + // - !group + case strings.EqualFold(cmd.Name, "!group"), + strings.EqualFold(cmd.Name, "!table"): if leagueTable, err := footballData.LeagueTableOfCompetition(Competition).Do(); err != nil { if s, err := tplString("error", err); err != nil { log.Print(err)