Giter VIP home page Giter VIP logo

snoostorm's Introduction

Snoostorm

Snoostorm is an event-based wrapped around snoowrap. It handles polling for you so you can design Reddit bots and applications to more easily react to new comments, messages, and other events on the site.

Install

You can install snoostorm from NPM. As snoostorm is implemented in TypeScript, types come preinstalled with the package.

npm install snoostorm
yarn add snoostorm

Usage

Let's get started with a simple example.

import { InboxStream, CommentStream, SubmissionStream } from "snoostorm";
import Snoowrap from "snoowrap";

const creds = require("./credentials.json");

const client = new Snoowrap(creds);

// Options object is a Snoowrap Listing object, but with subreddit and pollTime options
const comments = new CommentStream(client, {
  subreddit: "AskReddit",
  limit: 10,
  pollTime: 2000,
});
comments.on("item", console.log);

const submissions = new SubmissionStream(client, {
  subreddit: "AskReddit",
  limit: 10,
  pollTime: 2000,
});
submissions.on("item", console.log);

const inbox = new InboxStream(client);
inbox.on("item", console.log);

inbox.end();
inbox.on("end", () => console.log("And now my watch has ended"));

Custom Polls

Out of the box, snoostorm supports the following objects:

  • Comments
  • Submissions
  • Inbox
  • Modmail

If you would like to poll another object in snoowrap, you can implement your own Poll easily. For example, here is an implementation that will poll for new friends:

import { Poll } from "snoostorm"

export interface FriendStreamOptions {
  pollTime?: number;
}

export class FriendStream extends Poll<Snoowrap.RedditUser> {
  constructor(
    client: Snoowrap,
    options: FriendStreamOptions = { pollTime: 2000 }
  ) {
    super({
      frequency: options.pollTime,
      get: () => client.getFriends(),
      identifier: "name",
    });
  }
}

const friends = new FriendStream(client);

friends.on("item", (item) => {
  console.log("New Friend!", item.name);
});

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.