diff --git a/build/echo-botnet b/build/echo-botnet index 1b1640a..d7eecdc 100755 Binary files a/build/echo-botnet and b/build/echo-botnet differ diff --git a/echo-botnet b/echo-botnet index 1b1640a..d7eecdc 100755 Binary files a/echo-botnet and b/echo-botnet differ diff --git a/main.go b/main.go index b540bbe..a48c8d7 100644 --- a/main.go +++ b/main.go @@ -3,7 +3,6 @@ package main import ( "fmt" "log" - "strconv" "time" "github.com/fatih/color" @@ -34,15 +33,13 @@ func main() { } var i int for { - color.Red(strconv.Itoa(i)) sinceTweeted := time.Unix(botnet[i].SinceTweeted, 0) elapsed := time.Since(sinceTweeted) - fmt.Println(elapsed) if elapsed.Seconds() > 60 { - log.Println("starting to use bot: " + botnet[i].Title) - startStreaming(botnet[i]) + color.Blue("starting to use bot: " + botnet[i].Title) + startStreaming(&botnet[i]) } else { - log.Println("bot: " + botnet[i].Title + " not used due bot is in waiting time") + //log.Println("bot: " + botnet[i].Title + " not used due bot is in waiting time") } i++ if i > len(botnet)-1 { diff --git a/streamTweets.go b/streamTweets.go index 9b158b5..47b7beb 100644 --- a/streamTweets.go +++ b/streamTweets.go @@ -51,22 +51,9 @@ func replyTweet(client *twitter.Client, text string, inReplyToStatusID int64) { log.Println("tweet posted: " + tweet.Text) } -func startStreaming(bot Bot) { +func startStreaming(bot *Bot) { // Convenience Demux demultiplexed stream messages demux := twitter.NewSwitchDemux() - demux.Tweet = func(tweet *twitter.Tweet) { - if isRT(tweet) == false && isFromBotnet(tweet) == false { - //processTweet(botnetUser, botScreenName, keywords, tweet) - log.Println("[bot @" + bot.Title + "] - New tweet detected:") - log.Println(tweet.Text) - reply := getRandomReplyFromReplies(replies) - log.Println("reply: " + reply + ", to: @" + tweet.User.ScreenName /* + ". tweet ID: " + tweet.ID*/) - - //replyTweet(bot, "@"+tweet.User.ScreenName+" "+reply, tweet.ID) - color.Green("replying tweet!") - bot.SinceTweeted = time.Now().Unix() - } - } fmt.Println("Starting Stream...") // FILTER @@ -77,10 +64,33 @@ func startStreaming(bot Bot) { stream, err := bot.Client.Streams.Filter(filterParams) check(err) // Receive messages until stopped or stream quits - demux.HandleChan(stream.Messages) - /*for message := range stream.Messages { - demux.Handle(message) - log.Println("stopping stream") - stream.Stop() - }*/ + for message := range stream.Messages { + demux.All(message) + switch msg := message.(type) { + case *twitter.Tweet: + r := handleTweet(msg, bot) + if r { + log.Println("stopping stream") + stream.Stop() + } + default: + } + } +} + +func handleTweet(tweet *twitter.Tweet, bot *Bot) bool { + r := false + if isRT(tweet) == false && isFromBotnet(tweet) == false { + //processTweet(botnetUser, botScreenName, keywords, tweet) + log.Println("[bot @" + bot.Title + "] - New tweet detected:") + log.Println(tweet.Text) + reply := getRandomReplyFromReplies(replies) + log.Println("reply: " + reply + ", to: @" + tweet.User.ScreenName /* + ". tweet ID: " + tweet.ID*/) + + //replyTweet(bot, "@"+tweet.User.ScreenName+" "+reply, tweet.ID) + color.Green("@" + bot.Title + " replying tweet!") + bot.SinceTweeted = time.Now().Unix() + r = true + } + return r }