avoiding reply to other bots of the botnet, and readme explanation
arnaucode idoctnef@openmailbox.org
Sun, 23 Apr 2017 20:20:45 +0200
7 files changed,
67 insertions(+),
6 deletions(-)
M
README.md
→
README.md
@@ -1,1 +1,47 @@
# projectFlock + +a twitter botnet with bots replying tweets with text generated by Markov chains + +##### generating text with Markov chains +The algorithm calculates the probabilities of Markov chains, analyzing a considerable amount of text, for the examples, I've done it with the book "The Critique of Pure Reason", by Immanuel Kant (http://www.gutenberg.org/cache/epub/4280/pg4280.txt). + +#### Replying tweets with Markov chains +When the botnet is up working, the bots start streaming all the twitter new tweets containing the configured keywords. Each bot takes a tweet, analyzes the containing words, and generates a reply using the Markov chains previously calculated, and posts the tweet as reply. + +In the following examples, the bots ("andreimarkov", "dodecahedron", "projectNSA") are replying some people. + + + + + + + + + + +configuration file example (flockConfig.json): +``` +[{ + "title": "account1", + "consumer_key": "xxxxxxxxxxxxx", + "consumer_secret": "xxxxxxxxxxxxx", + "access_token_key": "xxxxxxxxxxxxx", + "access_token_secret": "xxxxxxxxxxxxx" + }, + { + "title": "account2", + "consumer_key": "xxxxxxxxxxxxx", + "consumer_secret": "xxxxxxxxxxxxx", + "access_token_key": "xxxxxxxxxxxxx", + "access_token_secret": "xxxxxxxxxxxxx" + }, + { + "title": "account3", + "consumer_key": "xxxxxxxxxxxxx", + "consumer_secret": "xxxxxxxxxxxxx", + "access_token_key": "xxxxxxxxxxxxx", + "access_token_secret": "xxxxxxxxxxxxx" + } +] + +```
M
optionMarkovFlockBotnet.go
→
optionMarkovFlockBotnet.go
@@ -11,11 +11,18 @@
"github.com/dghubble/go-twitter/twitter" ) -func isRT(text string) bool { - tweetWords := strings.Split(text, " ") +func isRT(tweet *twitter.Tweet) bool { + tweetWords := strings.Split(tweet.Text, " ") for i := 0; i < len(tweetWords); i++ { if tweetWords[i] == "RT" { - c.Red(text) + return true + } + } + return false +} +func isFromBot(flock Flock, tweet *twitter.Tweet) bool { + for i := 0; i < len(flock.ScreenNames); i++ { + if flock.ScreenNames[i] == tweet.User.ScreenName { return true } }@@ -40,11 +47,11 @@ fmt.Println(tweet.ID)
replyTweet(flockUser, "@"+tweet.User.ScreenName+" "+generatedText, tweet.ID) waitTime(1) } -func startStreaming(states []State, flockUser *twitter.Client, botScreenName string, keywords []string) { +func startStreaming(states []State, flock Flock, flockUser *twitter.Client, botScreenName string, keywords []string) { // Convenience Demux demultiplexed stream messages demux := twitter.NewSwitchDemux() demux.Tweet = func(tweet *twitter.Tweet) { - if isRT(tweet.Text) == false { + if isRT(tweet) == false && isFromBot(flock, tweet) == false { processTweet(states, flockUser, botScreenName, keywords, tweet) } }@@ -101,7 +108,8 @@ switch answer {
case "y": fmt.Println("ok, you are sure") for i := 0; i < len(flock.Clients); i++ { - go startStreaming(states, flock.Clients[i], flock.ScreenNames[i], keywords) + go startStreaming(states, flock, flock.Clients[i], flock.ScreenNames[i], keywords) + waitSeconds(35) } break default:
M
waitTime.go
→
waitTime.go
@@ -13,3 +13,10 @@ fmt.Println("waiting " + strconv.Itoa(minutes) + " min to avoid twitter api limitation")
fmt.Println(time.Now().Local()) time.Sleep(timeToSleep) } +func waitSeconds(seconds int) { + //wait to avoid the twitter api limitation + timeToSleep := time.Duration(seconds) * time.Second + fmt.Println("waiting " + strconv.Itoa(seconds) + " seconds") + fmt.Println(time.Now().Local()) + time.Sleep(timeToSleep) +}