reddit-watcher
TypeScript icon, indicating that this package has built-in type declarations

2.0.0Β β€’Β PublicΒ β€’Β Published

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();

Package Sidebar

Install

npm i reddit-watcher

Weekly Downloads

1

Version

2.0.0

License

MIT

Unpacked Size

629 kB

Total Files

34

Last publish

Collaborators

  • einnjo