Reddit-Snooper - Reddit bot framework for Nodejs
Simple to use
Reddit-snooper is designed to a simple but powerful interface to talk to Reddit. Reddit represents all of its objects in JSON natively which makes javascipt a good choice for building a bot.
snooperwatcher
Table of Contents
Setup and Configuration
Installing reddit-snooper
npm install reddit-snooper --save
Library usage and configuration
var Snooper =snooper =// credential information is not needed for snooper.watcherusername: 'reddit_username'password: 'reddit password'app_id: 'reddit api app id'api_secret: 'reddit api secret'user_agent: 'OPTIONAL user agent for your bot'automatic_retries: true // automatically handles condition when reddit says 'you are doing this too much'api_requests_per_minuite: 60 // api requests will be spread out in order to play nicely with Reddit
API setup
All you need to get up and running is obtain an api_id and an api_secret. Both can be created on the Reddit app console
- Create (or log into) a reddit account
- Navigate to the authorized applications console
- Select 'create another app...' at the bottom
- Fill in the name, description and click on 'script', put in anything for the redirect uri, its not needed and you can change it later if you want to
- Copy down the 'secret' that is your api_secret, the 14 character string by the name of your app is your app_id
- Use these values and your credentials to configure the snooper
Reddit Watcher (snooper.watcher)
Reddit watchers are event emitters that trigger when new things happen on the website, Right now you can watch for:
- new comments across the website or on a specific subreddit
- new posts across the website or on a specific subreddit
- post or comment is gilded (website or subreddit)
- new posts reaching the first x pages of different listings (hot, top_24, top_day, controversial, rising) across the website or subreddit
notify when a new comment is posted
snooperwatcher // blank argument or 'all' looks at the entire website
notify when a new post is posted
snooperwatcher // blank argument or 'all' looks at the entire website
notify when something is gilded
snooperwatcher // blank argument or 'all' looks at the entire website
notify when a new post reaches a specific listing (eg. the front page)
let options =listing: 'hot' // 'hot' OR 'rising' OR 'controversial' OR 'top_day' OR 'top_hour' OR 'top_month' OR 'top_year' OR 'top_all'limit: 50 // how many posts you want to watch? if any of these spots get overtaken by a new post an event will be emitted, 50 is 2 pagessnooperwatcher
examples (full programs in the examples folder)
unexpected factorial bot
snooperwatcher// when you are done// commentWatcher.close()
repost all gilded comments with over 1000 ups to r/bestof (please dont do this)
snooperwatcher
RemindMe! bot
// also coming soon, this is really easy to implement with setTimeout
download all gifs that make it to the front 2 pages of hot on r/gifs
this is different than just downloading the front 2 pages since it also triggers an event when the front 2 pages change
snooperwatcher
download all pics that are posted to r/pics
// start watching for new posts to r/picssnooperwatcher
Reddit API (snooper.api)
Snooper's api component is an agnostic wrapper around Reddit's rest API that handles retries, rate limit throttling and Reddit's different response codes.
In order to use the api head over to the Reddit API Documentation. All of the api methods use one of the 5 HTTP methods (GET, POST, PATCH, PUT, DELETE) which map to the 5 different snooper.api methods.
// endpoint: api endpoint ex: 'api/v1/me' or '/api/v1/me/karma/' (listed on api documentation)// data: JSON data, dependent on the request which is specified in the docs// NOTE: the function .get is used for api calls that use HTTP GET, you can find the method each api endpiont uses on (you guessed it) the reddit api docs// HTTP GETsnooperapi// HTTP POSTsnooperapi// HTTP PATCHsnooperapi// HTTP PUTsnooperapi// HTTP DELETEsnooperapi// gets an api tokensnooperapi
Note: new accounts get little to no posting privileges (1 comment or post per 5 minutes or more) if you dont have any karma. If you just want to play around with the api I recommend using an active account.
basic api usage
check how much karma your bot has
snooperapi
post a comment
snooperapi
I highly doubt your bot is over 18 years of age
snooperapi
activate turbo mode doubling performance (kidding)
snooperapi
Coming Soon
- Support for multiple accounts
- Convenience methods for commonly used api requests
- Object model for api items (User, Subreddit, Post, Comment, etc.)
- Watchers for everything
- private messages
- replies
- new post reaching the front page (configurable to different pages/ # of pages)