Compare commits
No commits in common. "4565d7deaa31203d1433cdbb0921daf3aa348a25" and "bbd531ef5cef9095267961c2f50e6f21b8df2c7a" have entirely different histories.
4565d7deaa
...
bbd531ef5c
65
main.go
65
main.go
|
@ -1,18 +1,15 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"math"
|
"math"
|
||||||
"regexp"
|
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/olekukonko/tablewriter"
|
|
||||||
"github.com/thoj/go-ircevent"
|
"github.com/thoj/go-ircevent"
|
||||||
"gopkg.in/alecthomas/kingpin.v2"
|
"gopkg.in/alecthomas/kingpin.v2"
|
||||||
|
|
||||||
|
@ -21,17 +18,12 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
Competition_Testing = 453
|
SoccerSeason_EuropeanChampionShipsFrance2016 = 444
|
||||||
Competition_WorldChampionShip2018 = -1
|
|
||||||
|
|
||||||
day = 24 * time.Hour
|
day = 24 * time.Hour
|
||||||
week = 7 * day
|
week = 7 * day
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
|
||||||
rDiff = regexp.MustCompile("[\\+\\-]\\d+")
|
|
||||||
)
|
|
||||||
|
|
||||||
type versus struct {
|
type versus struct {
|
||||||
HomeTeam, AwayTeam string
|
HomeTeam, AwayTeam string
|
||||||
}
|
}
|
||||||
|
@ -111,7 +103,7 @@ func main() {
|
||||||
|
|
||||||
updateTopics := func() {
|
updateTopics := func() {
|
||||||
// Get football data
|
// Get football data
|
||||||
if r, err := footballData.FixturesOfSoccerSeason(Competition_Testing).Do(); err != nil {
|
if r, err := footballData.FixturesOfSoccerSeason(SoccerSeason_EuropeanChampionShipsFrance2016).Do(); err != nil {
|
||||||
log.Print(err)
|
log.Print(err)
|
||||||
} else {
|
} else {
|
||||||
currentMatches := []*footballdata.Fixture{}
|
currentMatches := []*footballdata.Fixture{}
|
||||||
|
@ -408,59 +400,6 @@ func main() {
|
||||||
switch {
|
switch {
|
||||||
case !isChannel && strings.HasPrefix(msg, "updatetopics"):
|
case !isChannel && strings.HasPrefix(msg, "updatetopics"):
|
||||||
updateTopicsChan <- nil
|
updateTopicsChan <- nil
|
||||||
case strings.HasPrefix(msg, "!table"):
|
|
||||||
if leagueTable, err := footballData.LeagueTableOfCompetition(Competition_Testing).Do(); err != nil {
|
|
||||||
if s, err := tplString("error", err); err != nil {
|
|
||||||
log.Print(err)
|
|
||||||
} else {
|
|
||||||
conn.Privmsg(target, s)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
log.Printf("%+v", leagueTable)
|
|
||||||
|
|
||||||
header := []string{"Rank", "Team", "Games", "Goals", "Diff", "Points"}
|
|
||||||
data := [][]string{}
|
|
||||||
|
|
||||||
for _, standing := range leagueTable.Standing {
|
|
||||||
goalDiffPrefix := ""
|
|
||||||
if standing.GoalDifference > 0 {
|
|
||||||
goalDiffPrefix = "+"
|
|
||||||
} else {
|
|
||||||
goalDiffPrefix = ""
|
|
||||||
}
|
|
||||||
data = append(data, []string{
|
|
||||||
fmt.Sprintf("%d", standing.Position),
|
|
||||||
standing.TeamName,
|
|
||||||
fmt.Sprintf("%d", standing.PlayedGames),
|
|
||||||
fmt.Sprintf("%d:%d", standing.Goals, standing.GoalsAgainst),
|
|
||||||
fmt.Sprintf("%s%d", goalDiffPrefix, standing.GoalDifference),
|
|
||||||
fmt.Sprintf("%d", standing.Points),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
buf := new(bytes.Buffer)
|
|
||||||
|
|
||||||
table := tablewriter.NewWriter(buf)
|
|
||||||
table.SetHeader(header)
|
|
||||||
table.SetAlignment(tablewriter.ALIGN_CENTER)
|
|
||||||
table.SetNewLine("\n")
|
|
||||||
table.SetBorder(true)
|
|
||||||
table.AppendBulk(data)
|
|
||||||
table.Render()
|
|
||||||
|
|
||||||
tableStr := rDiff.ReplaceAllStringFunc(buf.String(), func(s string) string {
|
|
||||||
switch s[0] {
|
|
||||||
case '+':
|
|
||||||
return fmt.Sprintf("\x0303%s\x03", s)
|
|
||||||
}
|
|
||||||
return fmt.Sprintf("\x0304%s\x03", s)
|
|
||||||
})
|
|
||||||
|
|
||||||
lines := strings.Split(tableStr, "\n")
|
|
||||||
for _, line := range lines {
|
|
||||||
conn.Privmsg(target, line)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
case strings.HasPrefix(msg, "!match"):
|
case strings.HasPrefix(msg, "!match"):
|
||||||
/*if r, err := footballData.FixturesOfSoccerSeason(SoccerSeason_EuropeanChampionShipsFrance2016).TimeFrame(1 * day).Do(); err != nil {
|
/*if r, err := footballData.FixturesOfSoccerSeason(SoccerSeason_EuropeanChampionShipsFrance2016).TimeFrame(1 * day).Do(); err != nil {
|
||||||
if s, err := tplString("error", err); err != nil {
|
if s, err := tplString("error", err); err != nil {
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit 48a484dfcebd2d72bd73f76202b0f2393ccf5162
|
Subproject commit 17cd8cd68efe4599201b997bf9bf945a72077755
|
Loading…
Reference in New Issue