In the last post I showed you how to create a #ggautoblocker clone using a bit of python, blocktogether.org and ElasticSearch. That was mostly a joke to demonstrate to “GamerGate” people who are trying to censor blocking tools on Twitter that they cannot succeed. So I was surprised when a few people signed up and even more surprised when they wanted a whitelist added to that blocker. It now has a whitelist and should only block earnest “GamerGate” people, not those criticizing them, so go sign up and use it.
However there is a flaw, pretty much all these tools rely on a central system that you hand your credentials over to and trust to block accounts for you. They are potentially a bit slow as a result, blocktogether.org for example sometimes spends hours between updates of the #WombleBot. Unless it has already blocked all of “GamerGate” or other group attacking you on Twitter there is little help there. In the world of cloud IT, is it not possible to have your own block bot, one that you control? The answer is yes, and this is my first (very hacky) attempt at it, using Heroku …
What does it do?
- It runs on your own Heroku dyno that you can create and use for free, lots of people currently use them for ebooks Twitter accounts. (Like your own little application server running 24/7)
- Anyone who is not your friend on Twitter @’s you it will mute them by default on install, it uses the Twitter streaming API so it takes under a second to mute someone @’ing you. You can turn this off, or switch to block, at any time. Being dogpiled? Turn it on, when it’s over turn it off and unblock/unmute any false positives.
- It DMs all the tweets from people it has muted or blocked to an account of your choice, yours or a friend who will monitor any abuse to you and undo any false positives.
How do I use it?
- Install it, instructions below.
- By default it will start muting any unsolicited mentions from Twitter users. To control it, “@yourself PersonalBotOff”, “@yourself PersonalBotMute”, “@yourself PersonalBotBlock” will flick between the three modes.
- Check your DMs, anyone accidentally muted or blocked you can undo it and the bot will not re-block or mute them. (As long as it is not restarted, future versions could persist to a database)
That’s it! A personal blocking bot that you control – future versions could have more intelligent blocking algorithms. They could block on content of the tweet, block based on keywords in the profile of the person @’ing you, I personally find “egalitarian”, “libertarian” etc. to be quite good indicators a block is in order, YMMV. The code is open source so anyone can change it and add to it.
If you do not have a Linux machine you can use (Possibly OSX, not tested) and you are not at all technical then you might struggle, this has not been tested deploying on Windows but it is likely not too hard. If stuck, complete step one below (Plus step two, point 2) and ask a friend (Or me email@example.com) to set this up for you, you will need to give the person you ask the keys to the application you create and your Heroku login. So make sure you trust them.
Step One. Create a Twitter application; (You will need a phone number associated with your Twitter account to create an application)
- Go to apps.twitter.com, select “Create New App” at the top right of the page. Fill out the values, like this.
- Go to the permissions section and make sure direct messages are allowed, like this. Click on “Update Settings”.
- Go to Keys and Access tokens, select the Generate Access Token and Secret at the bottom of the page. You should then have a page that looks like this. Check the permissions includes DMs, revisit (2) if not…
- Keep a note of the keys somewhere safe, or leave the browser window open. You’ll need them in the next section, or to give to the person setting the bot up for you.
Step Two. Set up your local environment**
- Have a read of the “Getting Started” section in Heroku, https://devcenter.heroku.com/articles/getting-started-with-python#introduction
- Follow the setup for creating a Heroku account
- Install Python, optional, no need to install Virtualenv unless you want to try the whole tutorial
- In part two, “Set up”, there are instructions for installing Heroku Toolbelt. Afterwards, login to Heroku on the command line.
** This is primarily for Linux, however Windows has support for Heroku. You’ll just need to extract the commands from the setup.sh ran in the next section and manually issue them.
Step Three. Download, configure and deploy the application on Heroku
- Install git, if you don’t have it already!
- Find a directory to place the code, run >git clone https://github.com/sjwomble/PersonalBlockBot
- Go into the directory, cd PersonalBlockBot and run >./setup.sh **
- Enter the values for name, Twitter app keys (Step One above), account name to track and send DMs to. Then the code will push all the settings and code to Heroku and start the bot!
- Try >heroku logs –tail in the directory once you’ve deployed it. You should see it initialize, load friends lists etc and if anyone @’s you it will log it. Any errors contact me.
** If you are translating this to Windows, you need to create the app, set up the environment variables then push to Heroku. That’s it!
Step Four. Use the bot.
- If you want to stop it muting everyone you don’t know who @’s you, issue a tweet to yourself like, @sjwomble PersonalBotOff
- To switch to blocking, @sjwomble PersonalBotBlock
- To switch to mute, @sjwomble PersonalBotMute **
- Check your DMs, is it sending you one for every person blocked or muted with a link to the tweet?
- Check the Heroku console, https://dashboard.heroku.com/apps, you can delete the app and check the various settings
** If you need to re-issue the same command, either delete the old tweet or add some random text to the end. Twitter sometimes gets upset it you tweet the same tweet over and over…
Good luck, let me know if you have any issues with it. I’ve only done some pretty basic testing and it is not an example of the best coding, exactly … Updates to code and instructions welcome!