fixed stream from botnet, now runs Ok
arnaucode idoctnef@openmailbox.org
Sat, 12 Aug 2017 16:10:58 +0200
4 files changed,
33 insertions(+),
26 deletions(-)
M
main.go
→
main.go
@@ -3,7 +3,6 @@
import ( "fmt" "log" - "strconv" "time" "github.com/fatih/color"@@ -34,15 +33,13 @@ color.Cyan(bot.Title)
} 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 {
M
streamTweets.go
→
streamTweets.go
@@ -51,22 +51,9 @@ }
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 @@ }
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 }