Merge pull request #142 from velour/twitchfix

twitch: check gameID instead of title
This commit is contained in:
Chris Sexton 2019-02-05 21:16:57 -05:00 committed by GitHub
commit 86e662b181
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 17 deletions

View File

@ -23,8 +23,8 @@ type TwitchPlugin struct {
}
type Twitcher struct {
name string
game string
name string
gameID string
}
func (t Twitcher) URL() string {
@ -62,8 +62,8 @@ func New(b bot.Bot) *TwitchPlugin {
for _, twitcherName := range p.config.GetArray("Twitch."+ch+".Users", []string{}) {
if _, ok := p.twitchList[twitcherName]; !ok {
p.twitchList[twitcherName] = &Twitcher{
name: twitcherName,
game: "",
name: twitcherName,
gameID: "",
}
}
}
@ -95,7 +95,7 @@ func (p *TwitchPlugin) serveStreaming(w http.ResponseWriter, r *http.Request) {
}
status := "NO."
if twitcher.game != "" {
if twitcher.gameID != "" {
status = "YES."
}
context := map[string]interface{}{"Name": twitcher.name, "Status": status}
@ -207,26 +207,27 @@ func (p *TwitchPlugin) checkTwitch(channel string, twitcher *Twitcher, alwaysPri
}
games := s.Data
game := ""
gameID, title := "", ""
if len(games) > 0 {
game = games[0].Title
gameID = games[0].GameID
title = games[0].Title
}
streamWord := p.config.Get("Twitch.StreamWord", "streaming")
if alwaysPrintStatus {
if game == "" {
if gameID == "" {
p.Bot.Send(bot.Message, channel, fmt.Sprintf("%s is not %s.", twitcher.name, streamWord))
} else {
p.Bot.Send(bot.Message, channel, fmt.Sprintf("%s is %s %s at %s", twitcher.name, streamWord, game, twitcher.URL()))
p.Bot.Send(bot.Message, channel, fmt.Sprintf("%s is %s %s at %s", twitcher.name, streamWord, title, twitcher.URL()))
}
} else if game == "" {
if twitcher.game != "" {
} else if gameID == "" {
if twitcher.gameID != "" {
p.Bot.Send(bot.Message, channel, fmt.Sprintf("%s just stopped %s.", twitcher.name, streamWord))
}
twitcher.game = ""
twitcher.gameID = ""
} else {
if twitcher.game != game {
p.Bot.Send(bot.Message, channel, fmt.Sprintf("%s is %s %s at %s", twitcher.name, streamWord, game, twitcher.URL()))
if twitcher.gameID != gameID {
p.Bot.Send(bot.Message, channel, fmt.Sprintf("%s is %s %s at %s", twitcher.name, streamWord, title, twitcher.URL()))
}
twitcher.game = game
twitcher.gameID = gameID
}
}

View File

@ -35,8 +35,8 @@ func makeTwitchPlugin(t *testing.T) (*TwitchPlugin, *bot.MockBot) {
assert.NotNil(t, c)
c.twitchList["drseabass"] = &Twitcher{
name: "drseabass",
game: "",
name: "drseabass",
gameID: "",
}
return c, mb