Implement !country/!team and alias !table to !group.

master
Icedream 2018-06-14 00:02:04 +02:00
parent 8d7e2a1ddc
commit 84f97318b5
Signed by: icedream
GPG Key ID: 1573F6D8EFE4D0CF
1 changed files with 70 additions and 1 deletions

71
main.go
View File

@ -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 <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 {
log.Print(err)