soccer-bot/util.go

40 lines
1.0 KiB
Go
Raw Normal View History

2017-08-08 16:32:45 +00:00
package main
import (
"regexp"
"strings"
"github.com/icedream/go-footballdata"
)
const (
runeIrcBold = '\x02'
runeIrcColor = '\x03'
runeIrcReset = '\x0f'
runeIrcReverse = '\x16'
runeIrcItalic = '\x1d'
runeIrcUnderline = '\x1f'
)
var (
rxIrcColor = regexp.MustCompile(string(runeIrcColor) + "([0-9]*(,[0-9]*)?)")
)
func stripIrcFormatting(text string) string {
text = strings.Replace(text, string(runeIrcBold), "", -1)
text = strings.Replace(text, string(runeIrcReset), "", -1)
text = strings.Replace(text, string(runeIrcReverse), "", -1)
text = strings.Replace(text, string(runeIrcItalic), "", -1)
text = strings.Replace(text, string(runeIrcUnderline), "", -1)
text = rxIrcColor.ReplaceAllLiteralString(text, "")
return text
}
func fixturesMap(fixtures []footballdata.Fixture) map[versus]footballdata.Fixture {
retval := make(map[versus]footballdata.Fixture)
for _, fixture := range fixtures {
retval[versus{fixture.HomeTeamName, fixture.AwayTeamName}] = fixture
}
return retval
}