Browse Source

fixed stream from botnet, now runs Ok

master
arnaucode 6 years ago
parent
commit
68e19c6d5b
4 changed files with 33 additions and 26 deletions
  1. BIN
      build/echo-botnet
  2. BIN
      echo-botnet
  3. +3
    -6
      main.go
  4. +30
    -20
      streamTweets.go

BIN
build/echo-botnet


BIN
echo-botnet


+ 3
- 6
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 {

+ 30
- 20
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
}

Loading…
Cancel
Save