Compare commits
2 Commits
8d7e2a1ddc
...
13eec0fb33
Author | SHA1 | Date |
---|---|---|
|
13eec0fb33 | |
|
84f97318b5 |
76
main.go
76
main.go
|
@ -430,9 +430,79 @@ 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 <Group name> (for example !group a)
|
||||
// Not implemented yet:
|
||||
// - !group <Country name>
|
||||
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 {
|
||||
var s string
|
||||
if s, err = tplString("error", err); err != nil {
|
||||
log.Print(err)
|
||||
} else {
|
||||
conn.Privmsg(target, s)
|
||||
|
@ -492,7 +562,7 @@ func main() {
|
|||
actualStanding = v.TeamLeagueStatistics
|
||||
}
|
||||
|
||||
goalDiffPrefix := ""
|
||||
var goalDiffPrefix string
|
||||
if actualStanding.GoalDifference > 0 {
|
||||
goalDiffPrefix = "+"
|
||||
} else {
|
||||
|
|
Loading…
Reference in New Issue