How i ended creating The Pinisher, the punisher's raspberry pi bot on Twitter

in #stories8 years ago (edited)

Actually I'm playing with the Twitter API and my Raspberry Pi. So i work on bots with python and javascript, no much success with the 1st but with nodejs i actually have 2 working projects.

Today i will show you the first of them.

How it started

I was testing stuff, creating a auto RT bot, how it should work ? Simple, it search for keyword and when a match is found, it got RT'ed.

Then shit happened. Oh, no problem with my code, but i learned something, and i will tell you it :

Internet is full of porn.

A bot is a bot, he doesn't make the difference between "rt to win the last phone" and "rt to win dirty pics".

I let you imagine how i was when, in the middle of the living room, with all the familly, i checked the bot account.

NSFW, NFSW EVERYWHERE.

raspberry twitter bot pinisher

At this moment i just call it quit. The bot did his job, i'm the one who fails. And also humanity for putting pictures of theirs ass as a contest's reward.

But 2 weeks later when i got more free time i get back on track. Added a filter, things seemed to be good. Guess what ? I was wrong.

What happened ?

I started my bot before going to bed. The day after i checked my bot's account.

What did i found ? YES YOU GUESSED IT, GOD DAMN PORN.

Guess what ? When you are upset you can be amazingly creative.

API Twitter

I got so mad that i checked all the twitter's API, and i found this, a "function" to report tweet's users. YEAH!

yeah

It took somethings like 10 lines MAX to get the stuff to work, and it was working well :)

punishing bot twitter punisher

Some code


The code is not spectacular but, i'm not a programmer, just the fact it works is amazing.

// Punish it
console.log("Punishing", searchItem.id);
API.reportUser(searchItem.user.id,
function success(){
// Block it
blockedUsers.push(searchItem.user.id);
API.blockUser(searchItem.user.id);

Here the tweet is selected, the user is reported as spam then our account block him. It also add it to a blacklist so the script doesn't spin his wheels trying to block someone who is already blocked.

// Report user
reportUser: function (userId, cb, errorHandler) {
request.post({url: 'https://api.twitter.com/1.1/users/report_spam.json?user_id=' + userId, oauth: oauth})
.then(function() {cb();})
.catch(function(err) {
if (errorHandler)
errorHandler(err);
else
console.error("An error occurred:", err.message);});}
Report function with API
// Block user
blockUser: function(userId)
{request.post({url: 'https://api.twitter.com/1.1/blocks/create.json?user_id=' + userId, oauth: oauth})
.then(callbacks.default)
.catch(function(err)
{console.error(err.message);});}
Blocking function using API

End

I'm not totally happy, first i think just one report is enough to make a different, but used my many account, aiming the same keyword, it should be fun.

blockeduser bot twitter pinisher

Second, we can't have a list of reported users, this is why i added the block function,so we can check who is blocked, meaning they have also been reported.

Code is open source, released under MIT, you can check it on Github.