Skip to content

Allows you to watch πŸ‘€, filter πŸ•΅, and act πŸš€ on new reddit comments.

Notifications You must be signed in to change notification settings

einnjo/reddit-watcher

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

15 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Reddit Watcher

Allows you to watch πŸ‘€, filter πŸ•΅, and act πŸš€ on new reddit comments.

  • Uses nanoevents for emitting events.
  • Supports re-auth on token expiration and backoff on rate limits.

Usage

npm install reddit-watcher
import { CommentWatcher, Reddit, Comment, Event } from 'reddit-watcher';

// Initialize the reddit API client.
const reddit = new Reddit({
  user: 'YOUR_REDDIT_APP_USER',
  secret: 'YOUR_REDDIT_APP_SECRET',
  userAgent: 'your_app_name (by /u/your_reddit_username)',
});

// Create a new watcher.
const watcher = new CommentWatcher({
  reddit,

  // Optional subreddit, default is "all"
  subreddit: 'movies',

  // Optional filter for comments
  filter: (comment: Comment) => comment.nsfw === false,

  // Optional, default is false.
  // Uses pagination to only request new comments
  //
  // Without it you can get many duplicate comments between calls
  // in less active subreddits.
  //
  // In more active subreddits it's recommended to disable it,
  // otherwise the watcher will lag behind quickly.
  usePagination: true,

  // Optional, default is 0.
  // Limits how frequently Reddit's API will be called.
  //
  // On less active subreddits, with a minTimeBetweenRequests of 0
  // you'll be performing too many requests and getting few new comments
  // in return.
  minTimeBetweenRequests: 1000 * 60,
});

watcher.on(Event.COMMENTS, (comments: Comment[]) => {
  for (const comment of comments) {
    console.log(`[${comment.subreddit}] ${comment.author} - ${comment.body}`);
  }
});

// Watch him as he goes.
watcher.start();

About

Allows you to watch πŸ‘€, filter πŸ•΅, and act πŸš€ on new reddit comments.

Resources

Stars

Watchers

Forks

Packages

No packages published