Compare commits
No commits in common. "3ea158f25a696538b815d23ced2bef5e835f000f" and "35d7201500a23c08ed01dccf1052f7e258b8ea7a" have entirely different histories.
3ea158f25a
...
35d7201500
|
@ -1,13 +1,12 @@
|
||||||
FROM golang:1.10
|
FROM golang:1.8
|
||||||
|
|
||||||
RUN mkdir -p /go/src/app
|
RUN mkdir -p /go/src/app
|
||||||
WORKDIR /go/src/app
|
WORKDIR /go/src/app
|
||||||
|
|
||||||
ARG ROOT_IMPORT_PATH=github.com/icedream/embot
|
|
||||||
COPY . /go/src/app
|
COPY . /go/src/app
|
||||||
RUN \
|
RUN \
|
||||||
mkdir -p "$GOPATH/src/$(dirname "$ROOT_IMPORT_PATH")" &&\
|
mkdir -p "$GOPATH/src/github.com/icedream" &&\
|
||||||
ln -sf /go/src/app "$GOPATH/src/$ROOT_IMPORT_PATH" &&\
|
ln -sf /go/src/app "$GOPATH/src/github.com/icedream/embot" &&\
|
||||||
go-wrapper download &&\
|
go-wrapper download &&\
|
||||||
go-wrapper install
|
go-wrapper install
|
||||||
|
|
||||||
|
|
|
@ -50,7 +50,7 @@ func (m *AntiSpam) init() {
|
||||||
m.userTrackingMap = map[string][]time.Time{}
|
m.userTrackingMap = map[string][]time.Time{}
|
||||||
m.commandTrackingMap = map[string][]time.Time{}
|
m.commandTrackingMap = map[string][]time.Time{}
|
||||||
|
|
||||||
m.CommandCooldownDuration = 10 * time.Second
|
m.CommandCooldownDuration = 15 * time.Second
|
||||||
m.CommandRateLimitCount = 2
|
m.CommandRateLimitCount = 2
|
||||||
m.CommandRateLimitDuration = 1 * time.Minute
|
m.CommandRateLimitDuration = 1 * time.Minute
|
||||||
|
|
||||||
|
|
92
main.go
92
main.go
|
@ -23,11 +23,8 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
Competition_Testing_GermanLeague2 = 453
|
Competition_Testing = 453
|
||||||
Competition_Testing = 464
|
Competition_WorldChampionShip2018 = -1
|
||||||
Competition_WorldChampionShip2018 = 467
|
|
||||||
|
|
||||||
Competition = Competition_WorldChampionShip2018
|
|
||||||
|
|
||||||
day = 24 * time.Hour
|
day = 24 * time.Hour
|
||||||
week = 7 * day
|
week = 7 * day
|
||||||
|
@ -118,7 +115,7 @@ func main() {
|
||||||
|
|
||||||
updateTopics := func() {
|
updateTopics := func() {
|
||||||
// Get football data
|
// Get football data
|
||||||
if r, err := footballData.FixturesOfCompetition(Competition).Do(); err != nil {
|
if r, err := footballData.FixturesOfSoccerSeason(Competition_Testing).Do(); err != nil {
|
||||||
log.Print(err)
|
log.Print(err)
|
||||||
} else {
|
} else {
|
||||||
currentMatches := []*footballdata.Fixture{}
|
currentMatches := []*footballdata.Fixture{}
|
||||||
|
@ -414,11 +411,6 @@ func main() {
|
||||||
log.Printf("<%s @ %s> %s", event.Nick, target, msg)
|
log.Printf("<%s @ %s> %s", event.Nick, target, msg)
|
||||||
|
|
||||||
cmd := parseCommand(msg)
|
cmd := parseCommand(msg)
|
||||||
isCommand := !isChannel || strings.HasPrefix(cmd.Name, "!")
|
|
||||||
if !isCommand {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
log.Printf("Antispam check: %s, %s", event.Source, cmd.Name)
|
log.Printf("Antispam check: %s, %s", event.Source, cmd.Name)
|
||||||
if ok, duration := antispamInstance.Check(event.Source, cmd.Name); !ok {
|
if ok, duration := antispamInstance.Check(event.Source, cmd.Name); !ok {
|
||||||
conn.Noticef(sender, "Sorry, please try again %s.", humanize.Time(time.Now().Add(duration)))
|
conn.Noticef(sender, "Sorry, please try again %s.", humanize.Time(time.Now().Add(duration)))
|
||||||
|
@ -431,7 +423,7 @@ func main() {
|
||||||
updateTopicsChan <- nil
|
updateTopicsChan <- nil
|
||||||
|
|
||||||
case strings.EqualFold(cmd.Name, "!table"):
|
case strings.EqualFold(cmd.Name, "!table"):
|
||||||
if leagueTable, err := footballData.LeagueTableOfCompetition(Competition).Do(); err != nil {
|
if leagueTable, err := footballData.LeagueTableOfCompetition(Competition_Testing).Do(); err != nil {
|
||||||
if s, err := tplString("error", err); err != nil {
|
if s, err := tplString("error", err); err != nil {
|
||||||
log.Print(err)
|
log.Print(err)
|
||||||
} else {
|
} else {
|
||||||
|
@ -443,78 +435,20 @@ func main() {
|
||||||
header := []string{"Rank", "Team", "Games", "Goals", "Diff", "Points"}
|
header := []string{"Rank", "Team", "Games", "Goals", "Diff", "Points"}
|
||||||
data := [][]string{}
|
data := [][]string{}
|
||||||
|
|
||||||
// cast standing items to a new array with a more generic type
|
for _, standing := range leagueTable.Standing {
|
||||||
var standing []interface{}
|
|
||||||
if leagueTable.Standing != nil {
|
|
||||||
standing = make([]interface{}, len(leagueTable.Standing))
|
|
||||||
for i, v := range leagueTable.Standing {
|
|
||||||
standing[i] = v
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if standing == nil {
|
|
||||||
if leagueTable.Standings == nil {
|
|
||||||
conn.Noticef(sender, "Sorry, can't display league table at this moment.")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// expect a standing name to be input
|
|
||||||
if len(cmd.Arguments) < 1 {
|
|
||||||
conn.Noticef(sender, "You need to type in which standing you want to view the table of.")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// find matching standing (case-insensitive)
|
|
||||||
ok := false
|
|
||||||
for key, val := range leagueTable.Standings {
|
|
||||||
if strings.EqualFold(key, cmd.Arguments[0]) {
|
|
||||||
ok = true
|
|
||||||
standing = make([]interface{}, len(val))
|
|
||||||
for i, v := range val {
|
|
||||||
standing[i] = v
|
|
||||||
}
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if !ok {
|
|
||||||
conn.Noticef(sender, "Can not find requested standing for league table.")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, standing := range standing {
|
|
||||||
// HACK
|
|
||||||
var actualStanding footballdata.TeamLeagueStatistics
|
|
||||||
switch v := standing.(type) {
|
|
||||||
case footballdata.TeamLeagueStatisticsInStanding:
|
|
||||||
actualStanding = v.TeamLeagueStatistics
|
|
||||||
case footballdata.TeamLeagueStatisticsInStandings:
|
|
||||||
actualStanding = v.TeamLeagueStatistics
|
|
||||||
}
|
|
||||||
|
|
||||||
goalDiffPrefix := ""
|
goalDiffPrefix := ""
|
||||||
if actualStanding.GoalDifference > 0 {
|
if standing.GoalDifference > 0 {
|
||||||
goalDiffPrefix = "+"
|
goalDiffPrefix = "+"
|
||||||
} else {
|
} else {
|
||||||
goalDiffPrefix = ""
|
goalDiffPrefix = ""
|
||||||
}
|
}
|
||||||
|
|
||||||
// HACK - get team name from two diff fields
|
|
||||||
var teamName string
|
|
||||||
switch v := standing.(type) {
|
|
||||||
case footballdata.TeamLeagueStatisticsInStanding:
|
|
||||||
teamName = v.TeamName
|
|
||||||
case footballdata.TeamLeagueStatisticsInStandings:
|
|
||||||
teamName = v.Team
|
|
||||||
}
|
|
||||||
|
|
||||||
data = append(data, []string{
|
data = append(data, []string{
|
||||||
fmt.Sprintf("%d", actualStanding.Position),
|
fmt.Sprintf("%d", standing.Position),
|
||||||
teamName,
|
standing.TeamName,
|
||||||
fmt.Sprintf("%d", actualStanding.PlayedGames),
|
fmt.Sprintf("%d", standing.PlayedGames),
|
||||||
fmt.Sprintf("%d:%d", actualStanding.Goals, actualStanding.GoalsAgainst),
|
fmt.Sprintf("%d:%d", standing.Goals, standing.GoalsAgainst),
|
||||||
fmt.Sprintf("%s%d", goalDiffPrefix, actualStanding.GoalDifference),
|
fmt.Sprintf("%s%d", goalDiffPrefix, standing.GoalDifference),
|
||||||
fmt.Sprintf("%d", actualStanding.Points),
|
fmt.Sprintf("%d", standing.Points),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -542,7 +476,7 @@ func main() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case strings.EqualFold(cmd.Name, "!match"):
|
case strings.EqualFold(cmd.Name, "!match"):
|
||||||
/*if r, err := footballData.FixturesOfCompetition(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 {
|
||||||
log.Print(err)
|
log.Print(err)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit 12f2557ea80f4bbb1fee8642991e1af49901f1b1
|
Subproject commit 48a484dfcebd2d72bd73f76202b0f2393ccf5162
|
|
@ -1 +1 @@
|
||||||
Subproject commit 9f6ff22cfff829561052f5886ec80a2ac148b4eb
|
Subproject commit a3647f8e31d79543b2d0f0ae2fe5c379d72cedc0
|
|
@ -1 +1 @@
|
||||||
Subproject commit c679ae2cc0cb27ec3293fea7e254e47386f05d69
|
Subproject commit 05e8a0eda380579888eb53c394909df027f06991
|
|
@ -1 +1 @@
|
||||||
Subproject commit 5063e5f26097f6423c9de665079347c9473788da
|
Subproject commit 1b0acb5f2f1b615cfbd4b9f91abb14cb39a18769
|
Loading…
Reference in New Issue