Ok time to get political. I hate many things that Trump tweets these days and would love to reply to each tweet personally, but have neither time not desire to read his delusions. Fortunately in these modern times robots take many of our jobs. And this looked like a perfect job for a bot. Similarly to the bot described in the previous post it will be IFTTT + Scriptr combo. But this time in reverse, here’s intended flow:
- Twitter service at IFTTT detects when @realDonaldTrump tweets
- It triggers Maker service that makes HTTP request to Scriptr code
- Scriptr code generates random insult and posts a reply to Trump’s tweet
Here’s what IFTTT applet looks like:
It’s pretty straightforward – once Trump tweets – HTTP request is made. And here’s the insult-generating twitter-replying code that runs on Scriptr at receiving end:
function getRandomInt(min, max) { return Math.floor(Math.random() * (max - min + 1)) + min; } var tw = require("twitter"); var http = require("http"); var user = request.parameters.user.trim(); var insult = http.request({"url": "http://autoinsult.datahamster.com/scripts/webinsult.server.php?xajax=generate_insult&xajaxargs[]=" + getRandomInt(0,3)}).body; insult = insult.substring(insult.indexOf('[CDATA[') + 7); insult = insult.substring(0,insult.indexOf(']]')); var response = tw.callApi("https://api.twitter.com/1.1/statuses/user_timeline.json", "GET", {"screen_name":user,"count":"1"}); var id_str = JSON.parse(response.result)[0].id_str; var text = "@" + user + " " + insult; tw.callApi("https://api.twitter.com/1.1/statuses/update.json", "POST", {"status":text,"in_reply_to_status_id":id_str});
First we retreive twitter username passed from IFTTT request (line 08). Then we make API call to generate random insult (Lines 10-12). It’s the same service that’s behind http://autoinsult.datahamster.com/ and used by Autoinsult for Pebble app. It is capable of generating unlimited number of insults in 4 different styles and is really inventive. Service returns back XML, but since it’s fairly simple I treat it as a string to extract insult text. Next we’re making twitter API call to get latest tweet for user in question (line 14) and extract tweet ID (line 16). And finally we compose reply message message (line 18) and post reply (line 20). And the result is spectacular:
You can see bot in action at https://twitter.com/emojiDonalTrump. I also use this account to post translation of Trump tweets to emoji, so you will see mix of emojified Trump and replies to real Trump.