r/explainlikeimfive • u/this_is_fucked • Nov 06 '13
Explained ELI5: How do Reddit "bots" work?
I'm sure it can't be as complicated as I imagine....
276
Upvotes
r/explainlikeimfive • u/this_is_fucked • Nov 06 '13
I'm sure it can't be as complicated as I imagine....
9
u/jokul Nov 06 '13
what did you imagine?
122
u/[deleted] Nov 06 '13
Reddit has an API (Application Programming Interface). This makes it easy to 'talk' to reddit using the programming language of your choice. Using the API, you can do things like retrieving all the comments in this thread, or post a response.
For example, if I wanted to make a bot to translate imperial units (feet, inches, gallons, etc) into metric, I could write a program that asks reddit for all the comments in a thread, and look through each comment for something like "150 lbs". After that, I do my conversion and post a response using the API.
98
u/shaggorama Nov 06 '13 edited Nov 06 '13
Hi,
I'm the developer of /u/videolinkbot and a mod at /r/botwatch. I was going to post as the bot, but unfortunately it's banned in this sub so you get to meet the man behind the curtain. In any event, I'll explain how bots work in general by talking about a simple bot that has currently retired, /u/linkfixerbot (LFB). This was not my bot, but I coded a clone as a demonstration of how bots work.
A reddit bot can be thought of as being comprised of two components: a component that scans reddit to determine when its "services" are required, and another component that performs the main function of the bot.
LFB regularly queried /r/all/comments, which is a feed of all new comments posted to reddit in the order they are authored. The bot checks each new comment to see if it contains a broken reddit link. If the bot found such a broken link, it would reply to the comment with the fixed link. This "reply" is possible because the bot has a user account on reddit, just like any other user.
Here's the source code for my LinkFixerBot clone. Even if you don't know programming, you should be able to review the code and get a sense of how the bot works. It's written in a language called "python" which reads almost like pseudo-code (i.e. normal English commands).
Let me know if you have any other questions about the LinkFixerClone code, VideoLinkBot, or reddit bots in general!
EDIT1: Regarding the "Where does the code run?" questions: Yes, you're intuitions are correct, the code needs to run somewhere. Since I kicked it off a year or so ago, VLB has been running on my old laptop, so basically my laptop. It's very cheap to run, the overhead is basically just a request to reddit (max 1 request every 2 seconds) which pulls in a JSON response (i.e. some text) and the bot also queries youtube and similar websites for the titles of videos. Since I'm able to have a computer always on, I never felt the need to run it on an external server. The benefit of running the bot "in the cloud" would be that if the bot encountered a bug or something, I could fix it without coming home. At present, if the bot encounters any problems, the bot is in trouble until I'm at the computer because I'm too lazy to set up SSH or anything like that.
So in summary: VLB just runs on a laptop in my bedroom.
24
u/chuckeyman Nov 06 '13
Many Bots are humans who have made a novelty account to impersonate bots.
4
u/yiterium Nov 06 '13
A program could search a thread for a combination of words or numbers like coca cola invented santa claus for their commercials in their 90's marketing, and when it gets a match, it makes a post.
4
u/stealth_Mountain Nov 06 '13
Like others have mentioned, people write programs that talk to Reddit through the use of it's API.
This bot in particular is written in Python and uses the Python Reddit API Wrapper, or PRAW for short.
As far as functionality, every 2 seconds (the maximum allowed by Reddit's API) this bot checks the most recent comments on reddit.com/comments for the phrase "sneak peak" when it finds one, it replies to the comment with the correction, "I think you mean sneak peek", then adds the comment to a list to make sure the same comment is not replied to twice.
4
u/czsquared Nov 06 '13
i recognized some words in these responses, most of them. some even made sentences that i could almost understand.
2
u/AlekRivard Mar 23 '14
I think someone made a bot of me... I promise it was not me, I have no idea how programming works.
/u/AlekRivardBot
2
u/[deleted] Mar 23 '14
ghandi
2
u/imgurtranscriber Nov 07 '13
1: Cut a hole in a box
2: Put your junk in that box
3: "Make her open the box.
.. and that's the way you do it!
1
u/kerkypasterino Jan 08 '14
Jiffy! 2:16-2:18 http://www.youtube.com/watch?v=gyXkaO0DxB8
-2
u/basedongods Nov 07 '13
Wat
0
u/[deleted] Jan 15 '14
[deleted] — view deleted comment
0
u/[deleted] Nov 06 '13
[deleted] — view deleted comment