snoostorm-es6

es6 fork of snoostorm

Usage no npm install needed!

<script type="module">
  import snoostormEs6 from 'https://cdn.skypack.dev/snoostorm-es6';
</script>

README

snoostorm-es6

event-based wrapper around snoowrap
fork of SnooStorm

usage

setup:

'use strict';

const snoowrap = require('snoowrap');
const snoostorm = require('snoostorm-es6');

const options = {
    userAgent: "<user agent>",
    clientSecret: "<client secret>",
    clientId: "<client id>",
    username: "<username>",
    password: "<password>"
};

const r = new snoowrap(options);
const s = new snoostorm(r);

comment streaming

const comments = s.Stream("comment", {
  subreddit: "all",
  results: 100, // defaults to 25, max is 100
  pollTime: 5000
});

comments.on("item", item => {
  console.log(item);
});

submission streaming

const submissions = s.Stream("submission", {
  subreddit: "asoiaf",
  pollTime: 10000
});

submissions.on("item", item => {
  console.log(item.title);
});

inbox streaming

// filter one of "inbox" (default), "unread", "messages", "comments", "selfreply", or "mentions"
const mentions = s.Stream("inbox", {
  filter: "mentions"
});

mentions.on("item", item => {
  console.log(item.author.name);
});

error handling

comments.on("error", e => {
  console.log(e); // stop breaking the rate-limit
});

ending a stream

comments.on("end", () => {
  console.log("your one hour comment stream has ended.");
});

setTimeout(() => {
  comments.emit("end");
}, 3600000);