streams

package
v1.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 26, 2020 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package streams provides robust event streams from Reddit.

This package is not abstract. If you are looking for a simpler, high level interface, see graw.

The streams provided by this package will not be deterred like naive implementations by a post getting caught in the spam filter, removed by mods, the author being shadowbanned, or an author deleting their post. These streams are in it to win it.

All of the streams provisioned by this package depend on an api handle from the reddit package, and two control channels: one kill signal and one error feed.

The kill channel can be shared by multiple streams as long as you signal kill by close()ing the channel. Sending data over it will kill an arbitrary one of the streams sharing the channel but not all of them.

The error channel will return issues which may be intermittent. They are not wrapped, so you can check them against the definitions in the reddit package and choose to wait when Reddit is busy or the connection faults, instead of failing.

If there is a problem setting up the stream, such as the endpoint being invalid, that will be caught in the initial construction of the stream; you don't need to worry about that on the error channel.

These streams will consume "intervals" of the Reddit handle given to them. Since the reddit handlers are rate limited and do not allow bursts, there is essentially a schedule on which they execute requests, and the executions will be divided roughly evenly between the goroutines sharing the handle. E.g. if you create two user streams which depend on a handle with a rate limit of 5 seconds, each of them will be unblocked once every 10 seconds (ish), since they each consume one interval, and the interval is 5 seconds.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CommentReplies

func CommentReplies(
	bot reddit.Bot,
	kill <-chan bool,
	errs chan<- error,
) (
	<-chan *reddit.Message,
	error,
)

CommentReplies returns a stream of replies to comments made by the bot's account. This stream consumes one interval of the handle.

func CustomFeeds

func CustomFeeds(
	scanner reddit.Scanner,
	kill <-chan bool,
	errs chan<- error,
	user string,
	feeds ...string,
) (
	<-chan *reddit.Post,
	error,
)

CustomFeeds returns a stream of new posts from the requested custom feeds.

Be aware that these posts are new and will not have comments. If you are interested in comment trees, save their permalinks and fetch them later.

func Mentions

func Mentions(
	bot reddit.Bot,
	kill <-chan bool,
	errs chan<- error,
) (
	<-chan *reddit.Message,
	error,
)

Mentions returns a stream of mentions of the bot's username anywhere on Reddit. It consumes one interval of the handle. Note, that a username mention which can reach the inbox in any other way (as a pm, or a reply), will not come through the mention stream because Reddit labels it differently.

func Messages

func Messages(
	bot reddit.Bot,
	kill <-chan bool,
	errs chan<- error,
) (
	<-chan *reddit.Message,
	error,
)

Messages returns a stream of messages sent to the bot's inbox. It consumes one interval of the handle.

func PostReplies

func PostReplies(
	bot reddit.Bot,
	kill <-chan bool,
	errs chan<- error,
) (
	<-chan *reddit.Message,
	error,
)

PostReplies returns a stream of top level replies to posts made by the bot's account. This stream consumes one interval of the handle.

func SubredditComments

func SubredditComments(
	scanner reddit.Scanner,
	kill <-chan bool,
	errs chan<- error,
	subreddits ...string,
) (
	<-chan *reddit.Comment,
	error,
)

SubredditComments returns a stream of new comments from the requested subreddits. This stream monitors the combination listing of all subreddits using Reddit's "+" feature e.g. /r/golang+rust. This will consume one interval of the handle per call, so it is best to gather all the subreddits needed and invoke this function once.

Be aware that these comments are new, and will not have reply trees. If you are interested in comment trees, save the permalinks of their parent posts and fetch them later once they may have had activity.

func Subreddits

func Subreddits(
	scanner reddit.Scanner,
	kill <-chan bool,
	errs chan<- error,
	subreddits ...string,
) (
	<-chan *reddit.Post,
	error,
)

Subreddits returns a stream of new posts from the requested subreddits. This stream monitors the combination listing of all subreddits using Reddit's "+" feature e.g. /r/golang+rust. This will consume one interval of the handle per call, so it is best to gather all the subreddits needed and invoke this function once.

Be aware that these posts are new and will not have comments. If you are interested in comment trees, save their permalinks and fetch them later.

func User

func User(
	scanner reddit.Scanner,
	kill <-chan bool,
	errs chan<- error,
	user string,
) (
	<-chan *reddit.Post,
	<-chan *reddit.Comment,
	error,
)

User returns a stream of new posts and comments made by a user. Each user stream consumes one interval of the handle.

Types

This section is empty.

Directories

Path Synopsis
internal
monitor
Package monitor tracks a listing feed on Reddit.
Package monitor tracks a listing feed on Reddit.
rsort
Package rsort provides tools for sorting Reddit elements.
Package rsort provides tools for sorting Reddit elements.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL