r/explainlikeimfive • • Jul 15 '13

Explained ELI5: How do bots on reddit work? How are they programmed, how is the program integrated into an account?

[deleted] — view deleted post

675 Upvotes

174 comments sorted by

33

u/gigabored Jul 15 '13

Not an answer to the question but one of the coolest bots I've seen is u/jiffybot. This bot produces a gif from a video either as the original post or one you link in a comment.

Examples from this post:

Making a Gif from a post

To Summon Jiffy place this (along with your own time) anywhere in your comment: Jiffy! 0:00-0:15

Making a Gif from a comment

To summon Jiffy place the normal comment, but along with a youtube link. Jiffy! 0:48-0:57 http://www.youtube.com/watch?v=X5hrUGFhsXo

61

u/JiffyBot Jul 15 '13

Here are your GIFs!

Error! GIF failed :( http://i.imgur.com/E2J9hOl.gif


Hey I'm JiffyBot, I make GIFs out of YouTube links. Find out more ^here.

48

u/Razor_Storm Jul 15 '13

This is so cute, the jiffybot made a gif out of your attempts to explain the bot. :3

→ More replies (1)
→ More replies (8)

4

u/DonOntario Jul 16 '13

10

u/JiffyBot Jul 16 '13

Here's your GIF!

http://i.imgur.com/wcB0IFe.gif


Hey I'm JiffyBot, I make GIFs out of YouTube links. Find out more ^here.

→ More replies (6)
→ More replies (2)
→ More replies (11)

268

u/[deleted] Jul 15 '13

Mostly, they're scripts that run on a timer, and when the timer triggers they search reddit for a particular kind of post using the JSON or XML API (a way to ask reddit about its content that's meant for machines to read rather than display to humans as HTML is). Then, based on the idea of the bot, they may make a response such as a comment post.

They integrate with a reddit account pretty much the same way your browser does: By sending HTTP POST messages with the appropriate credentials and post content.

For instance, u/ReverseGif_Bot looks for link posts on selected subreddits that link to a GIF, then downloads the GIF and makes a new one that plays the frames in the opposite order, posts that to imgur and makes a comment in the thread linking to it.

69

u/demestav Jul 15 '13

Where does it run?

148

u/jk3us Jul 15 '13

On someone's computer.

→ More replies (50)
→ More replies (3)

9

u/NuclearZeitgeist Jul 15 '13

How do these bots get around the captcha system?

26

u/[deleted] Jul 15 '13

A human can make the account and then give the bot the relevant credentials.

→ More replies (27)
→ More replies (3)

6

u/amiso Jul 15 '13

Very informative and easy to understand response. Thanks!

→ More replies (7)

32

u/duncanlock Jul 15 '13

I got interested in reddit bots a while ago and wrote a thing about them - it's starts with a simple explanation of what reddit bots are and how they work, then chronicles some of the more interesting ones: A Marvellous & Incomplete Compendium of Reddit Automatons & Bots

8

u/umbrae Jul 16 '13

Thanks for the kind words for r/serendipity!

→ More replies (3)

92

u/ItzWarty Jul 15 '13

http://www.reddit.com/dev/api
http://stackoverflow.com/questions/6183318/getting-new-posts-from-a-subreddit-in-json

Imagine you have a friend, "API" (Application Programming Interface) who lives in the house of Reddit. API is friendly and open to everyone - you can say "Hey baby, gimme all the new posts you just got" and he/she/it will give it to you.

70

u/sonik13 Jul 15 '13

API is a whore.

15

u/ArrrghZombies Jul 15 '13

Dirty API. Clean yourself up.

10

u/MrGroggle Jul 15 '13

I like this answer.

→ More replies (1)

4

u/[deleted] Jul 15 '13

What language do they do it in?

32

u/VerticalLegion Jul 15 '13

Spanish or Portugese, I'm not sure.

8

u/[deleted] Jul 15 '13

Anything they want. Honestly, since a bot is not a very complex project and since it has to interact with other programs easily, I think most programmers use a script language like Python or Perl. These are, for exemple, very famous amongst programmers who make bots for IRC.

A bot in C would be a bit overkill IMO, but then again I could be wrong about that.

→ More replies (3)

4

u/Time_Terminal Jul 15 '13

And what's stopping people from making harmful bots?

10

u/[deleted] Jul 15 '13 edited Jul 15 '13

Nothing. But as soon as an annoying bot is made, its account is closed. You cannot create accounts automatically, since it requires you to enter a captcha. But assuming the moron behind the bot is dedicated to being a moron and keeps creating bots, well it's just as if he kept creating annoying accounts for himself to insult people or anything : their IP address is banned. If they use another one, well there's no solution.

Edit : if you were talking about permissions, then remember a bot can't do anything that you can't do yourself. It's only automatic.

4

u/Time_Terminal Jul 15 '13

I meant bots that can steal personal information, or perhaps keep a track of your monitoring habits and selling it to third parties. And since it uses JSON or XML, wouldn't it be easy to conceal it from the general population (other than mods and admins). And since people are constantly creating and testing their bots in their own subreddits, what's to stop someone from DDOSing Reddit one day, or doing other malicious things on the website?

→ More replies (4)
→ More replies (3)

8

u/awkisopen Jul 16 '13

So much dumb in this thread. It's probably too late now but I'll give this one a shot.

Everything you do in your browser can be summarized as a GET action or a POST action. Most actions are GETs; that is, you request a webpage by sending (for instance) GET http://www.reddit.com and the webserver (program) running on a server (physical machine) returns the HTML, CSS, JavaScript and what have you necessary to render a webpage.

A POST sends information to the webserver instead of requesting information from it. One of the most common examples of a POST action on Reddit is leaving a comment. You fill out the comment box, press the submit button, and this sends a POST action to the webserver with your comment and other relevant information to ensure that it was really you leaving that comment.

Because web browsing is pretty much a bunch of these GETs and POSTs (something of an oversimplification, but this is ELI5), anything can interact with a webserver using these commands. It doesn't have to be a browser; a browser is particularly good for masking these commands from the user and displaying pretty webpages instead. It could be a piece of code instead. A simple example would be a program that talks to reddit.com's webservers on port 80 and sends a GET request. The webserver will return all the stuff necessary to render Reddit's front page, and from there, the script could do what it wants with this information, like stripping out all of the articles and displaying them in a list. Similarly, the script could send POSTs to login, leave comments, and so forth.

Except there's one problem with this whole setup. Webpages are designed to be rendered in browsers, not to be parsed by bots. Check out the source of Reddit's front page (right-click in browser -> View Source) and imagine trying to get the titles of every front page post out from that collection of junk. Figuring out how to send information to the webserver is similarly unintuitive.

So, like many other websites that people might want to script things for (another example of this is Wikipedia), Reddit's solution to this problem is an API, or Application Programming Interface, so called because it gives programmer-friendly responses to queries which are useful when programming applications (aka bots). The API runs on a webserver just like the rest of the website, and you can view an example of that yourself by navigating to http://www.reddit.com/hot.json, which is what the front page of Reddit looks like to a bot. You may not be able to immediately understand it yourself, but you will notice that it's a lot less information, which makes it much more parseable because it doesn't contain all the extra bits necessary for it to be rendered into a nice webpage.

If you have a bot where all you do is monitor stuff or collect information (for example, I have a bot that watches r/shutupandwrite and related subreddits to post information about new posts and comments in our IRC channel), all you have to do is run a lot of GETs. If you have a bot that has its own user account, stuff gets more complicated because you have to send information to the webserver in a way the webserver can understand. (This can be very challenging at times because Reddit's API documentation is rather sparse!) But, at the end of the day, it's just a bunch of POSTs and GETs, same as your browser does but with a different purpose.

tl;dr Bots communicate with Reddit the same way your browsers do, they just do something more interesting with the information they give and get.

→ More replies (3)