Adventures with Twitter Bots



Adventures with Twitter Bots

0 0


mensdaybot-talk

Slides for my lightning talk on MensDayBot at Codebar, April 2016

On Github richardwestenra / mensdaybot-talk

Adventures with Twitter Bots

Discuss my experience learning how to make a twitter bot.

Great learning project

The story begins a little over a year ago.

Annual event that celebrates women and helps promote feminist goals.

Thousands of men wailing "Wait why isn't there an International Men's Day?"

"I am uncomfortable when we are not about me!"

#Equality

Because of course the most important thing for us to think about on IWD is "what about the mens"?

So these complaints are pretty silly, but they seem even sillier when you consider that…

IMD exists, it's Nov 19th, as these men would know if they had bothered to google it.

Comedian Richard Herring

He is like a superhero and his powers are knowing when IMD is and telling people who don't know.

apps.twitter.com

Don't use your own account

Pro-tip for Gmail users:

username+modifier@gmail.com redirects to username@gmail.com

which is useful for creating multiple twitter accounts

github.com/rfreebern/simple-twitter-bot

Lots of twitter bot frameworks and examples on Github. Search.

I chose this one because it's in JavaScript and runs on Node.js

It uses Twit.js, a JS Twitter API library.

Twit.js

						// tweet 'hello world!'
Twit.post('statuses/update', { status: 'hello world!' },
function(error, data, response) {
  console.log(data);
});

// filter the twitter public stream by the word 'mango'.
var stream = Twit.stream('statuses/filter', { track: 'mango' });

stream.on('tweet', function (tweet) {
  console.log(tweet);
});
					

bot.js

						var keywords = [
    "international men's day",
    "international man's day",
    "international mens day",
    "international mans day",
    "national men's day",
    "national man's day",
    "national mens day",
    "national mans day"
];

var reply = "It's November 19th.";
					

bot.js

						function isValid(tweet) {
    // Don't reply to tweets mentioning November 19th:
    var november = hasKeyword(['November','Nov','19','19th'], tweet.text);
    // Don't reply to Richard Herring
    var richard = tweet.user.screen_name === 'Herring1967';
    // Don't reply to RTs
    var rt = tweet.retweeted_status !== undefined;

    return !november && !richard && !rt;
}
					

Heroku is a popular cloud hosting platform. They support most popular languages including JavaScript/Node.js.

You can deploy to using Git.

Bot can't detect sarcasm.

Express.js

A fast, minimalist Node.js web server framework

						// Express server:
var express = require('express');
var app = express();

app.set('port', (process.env.PORT || 5000));
app.use(express.static(__dirname + '/public'));
app.listen(app.get('port'), function() {
  console.log("Node app is running at localhost:" + app.get('port'));
});
					

2016

Twitter finally decided to put my bot down at the ripe old age of a year and a day.

Slides

richardwestenra.com/mensdaybot-talk

Resources

MensDayBot, Simple Twitter Bot and Twit on Github

How to set up a simple JS Twitter bot

Create a Twitter application

MensDayBot admin on Heroku

If you have any ideas to improve my bot then send me a PR.

I know Oliver wants to improve false-positive detection by cross-referencing twitter users against gamergate blocklists.

Thanks!

richardwestenra.com

twitter.com/richardwestenra

github.com/richardwestenra

Adventures with Twitter Bots Discuss my experience learning how to make a twitter bot. Great learning project