From 9e0f20af33986ea2765bcf5e5efae5189cad3b8e Mon Sep 17 00:00:00 2001 From: Daniel Aberger Date: Sun, 24 Apr 2016 13:22:14 +0200 Subject: [PATCH] minor tweaks to ts3 and twitch module --- modules/ts3.go | 24 +++++++++++++----------- modules/twitch.go | 39 ++++++++++++++++++++++----------------- 2 files changed, 35 insertions(+), 28 deletions(-) diff --git a/modules/ts3.go b/modules/ts3.go index 374f7db..2fef5fe 100644 --- a/modules/ts3.go +++ b/modules/ts3.go @@ -74,19 +74,21 @@ func loop() { } } func ts3HandleMessage(payload *WebhookPayload) { - log.Println("TS3 users requested by " + payload.UserName) - users, _ := getUsers() - var s string - i := 0 - s += "Current users on TS3 Server:\n" - for u, _ := range users { - i++ - s += "- " + u - if i != len(users) { - s += "\n" + if payload.TriggerWord == "/ts" || payload.TriggerWord == "!ts" { + log.Println("TS3 users requested by " + payload.UserName) + users, _ := getUsers() + var s string + i := 0 + s += "Current users on TS3 Server:\n" + for u, _ := range users { + i++ + s += "- " + u + if i != len(users) { + s += "\n" + } } + SayCh <- GeneratePayload("@"+payload.UserName, ":poop:", s, botname) } - SayCh <- GeneratePayload("@"+payload.UserName, ":poop:", s, botname) } func getUsers() (u map[string]bool, e error) { diff --git a/modules/twitch.go b/modules/twitch.go index 4069cd1..46488bb 100644 --- a/modules/twitch.go +++ b/modules/twitch.go @@ -113,13 +113,15 @@ type TwitchStreamObject struct { } var ( - twitch = map[string]bool{ + announceChannel string + twitch = map[string]bool{ "rocketbeanstv": false, "blizzard": false, "ea": false, "warcraft": false, "starcraft": false, "bobross": false, + "pixelj0ckey": false, } twitchapiurlstreams = "https://api.twitch.tv/kraken/streams/" twitchapiurlchannels = "https://api.twitch.tv/kraken/channels/" @@ -127,6 +129,7 @@ var ( func init() { MsgHandlers["twitch"] = twitchHandleMessage + announceChannel = ModParams["twitchchannel"] log.Println("Initializing twitch module") go pollStreamData() } @@ -137,7 +140,7 @@ func twitchHandleMessage(payload *WebhookPayload) { return } switch tok[0] { - case "!twitch": + case "!twitch" || "/twitch": switch len(tok) { case 1: onlinestreams := 0 @@ -155,7 +158,7 @@ func twitchHandleMessage(payload *WebhookPayload) { } } if onlinestreams == 0 { - SayCh <- GeneratePayload("@"+payload.UserName, "", "All streams offline", "Twitch_Bot") + SayCh <- GeneratePayload(payload.ChannelName, "", "All streams offline", "Twitch_Bot") } case 2: streamname := tok[1] @@ -175,21 +178,23 @@ func twitchHandleMessage(payload *WebhookPayload) { } func pollStreamData() { - time.Sleep(10 * time.Second) - for { - for streamname, _ := range twitch { - var so TwitchStreamObject - var co TwitchChannelObject - so = getTwitchStreamObject(streamname) - if so.Stream.Game != "" && !twitch[streamname] { - co = getTwitchChannelObject(streamname) - twitchSendMsg(co, so) - twitch[streamname] = true - } else if so.Stream.Game == "" && twitch[streamname] { - twitch[streamname] = false + if announceChannel != "" { + time.Sleep(10 * time.Second) + for { + for streamname, _ := range twitch { + var so TwitchStreamObject + var co TwitchChannelObject + so = getTwitchStreamObject(streamname) + if so.Stream.Game != "" && !twitch[streamname] { + co = getTwitchChannelObject(streamname) + twitchSendMsg(co, so) + twitch[streamname] = true + } else if so.Stream.Game == "" && twitch[streamname] { + twitch[streamname] = false + } } + time.Sleep(180 * time.Second) } - time.Sleep(180 * time.Second) } } @@ -232,7 +237,7 @@ func getTwitchChannelObject(streamname string) TwitchChannelObject { } func twitchSendMsg(tcobj TwitchChannelObject, tso TwitchStreamObject) { - SayCh <- GeneratePayload("#wgs-service", + SayCh <- GeneratePayload(announceChannel, "", "*"+tso.Stream.Channel.DisplayName+ "*\n*Title:* "+tcobj.Status+