reddit

package
v1.13.3 Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2019 License: MIT Imports: 25 Imported by: 0

README

Reddit plugin for YAGPDB

How the feed works

Uses the same method mee6 uses for reliable cost effective scanning of all reddit posts.

works by by manually checking 100 ids per couple of second via the /api/info.json?id=t3_id1,t3_id2 etc route.

It then updates the cursor to the highest returned post id, continuing from that next call.

I don't believe this method has any bad parts at this moment, it seems to be more than enough even at a 5 second interval, unlike the polling of /all/new this does not appear to have any limitations on old posts and also shows absolutely all posts.

Redis layout:

reddit_last_post_id id of last post processed

global_subreddit_watch:sub Type: hash Key: {{guild}}:{{watchid}} Value: SubredditWatchItem

guild_subreddit_watch:guildid Type: hash Key: {{watchid}} Value: SubredditWatchItem

watchid is a per guild increasing id for items

Documentation

Index

Constants

View Source
const (
	// Max feeds per guild
	GuildMaxFeedsNormal  = 100
	GuildMaxFeedsPremium = 1000
)

Variables

View Source
var (
	ClientID           = os.Getenv("YAGPDB_REDDIT_CLIENTID")
	ClientSecret       = os.Getenv("YAGPDB_REDDIT_CLIENTSECRET")
	RedirectURI        = os.Getenv("YAGPDB_REDDIT_REDIRECT")
	RefreshToken       = os.Getenv("YAGPDB_REDDIT_REFRESHTOKEN")
	UseDiscordSpoilers = os.Getenv("YAGPDB_REDDIT_USE_DISCORD_SPOILERS") != ""
)
View Source
var KeyLastScannedPostID = "reddit_last_post_id"

Functions

func CreatePostMessage added in v1.4.1

func CreatePostMessage(post *reddit.Link) (string, *discordgo.MessageEmbed)

func HandleModify

func HandleModify(w http.ResponseWriter, r *http.Request) interface{}

func HandleNew

func HandleNew(w http.ResponseWriter, r *http.Request) interface{}

func HandleReddit

func HandleReddit(w http.ResponseWriter, r *http.Request) interface{}

func HandleRemove

func HandleRemove(w http.ResponseWriter, r *http.Request) interface{}

func MaxFeedForCtx added in v1.6.0

func MaxFeedForCtx(ctx context.Context) int

func RegisterPlugin

func RegisterPlugin()

func UserAgent

func UserAgent() string

Types

type CtxKey

type CtxKey int
const (
	CurrentConfig CtxKey = iota
)

type Form

type Form struct {
	Subreddit string `schema:"subreddit" valid:",1,100"`
	Channel   string `schema:"channel" valid:"channel,false`
	ID        int    `schema:"id"`
	UseEmbeds bool   `schema:"use_embeds"`
}

type Plugin

type Plugin struct {
	// contains filtered or unexported fields
}

func (*Plugin) HandleMQueueError

func (p *Plugin) HandleMQueueError(elem *mqueue.QueuedElement, err error)

Remove feeds if they don't point to a proper channel

func (*Plugin) InitWeb

func (p *Plugin) InitWeb()

func (*Plugin) Name

func (p *Plugin) Name() string

func (*Plugin) RemoveGuild

func (p *Plugin) RemoveGuild(g int64) error

func (*Plugin) StartFeed

func (p *Plugin) StartFeed()

func (*Plugin) StopFeed

func (p *Plugin) StopFeed(wg *sync.WaitGroup)

type PostFetcher

type PostFetcher struct {
	LastID int64
	// contains filtered or unexported fields
}

func NewPostFetcher

func NewPostFetcher(redditClient *reddit.Client) *PostFetcher

func (*PostFetcher) GetNewPosts

func (p *PostFetcher) GetNewPosts() ([]*reddit.Link, error)

func (*PostFetcher) InitCursor

func (p *PostFetcher) InitCursor() (int64, error)

type RatelimitWindow added in v1.13.1

type RatelimitWindow struct {
	T      time.Time
	ID     int64
	Guilds map[int64]int
}

type Ratelimiter added in v1.13.1

type Ratelimiter struct {
	Windows []*RatelimitWindow
	// contains filtered or unexported fields
}

func NewRatelimiter added in v1.13.1

func NewRatelimiter() *Ratelimiter

func (*Ratelimiter) CheckIncrement added in v1.13.1

func (r *Ratelimiter) CheckIncrement(t time.Time, guildID int64, limit int) bool

func (*Ratelimiter) FullGC added in v1.13.1

func (r *Ratelimiter) FullGC(t time.Time)

func (*Ratelimiter) GC added in v1.13.1

func (r *Ratelimiter) GC(t time.Time) bool

func (*Ratelimiter) RunGCLoop added in v1.13.1

func (r *Ratelimiter) RunGCLoop()

type RedditIdSlice

type RedditIdSlice []string

func (RedditIdSlice) Len

func (r RedditIdSlice) Len() int

Len is the number of elements in the collection.

func (RedditIdSlice) Less

func (r RedditIdSlice) Less(i, j int) bool

Less reports whether the element with index i should sort before the element with index j.

func (RedditIdSlice) Swap

func (r RedditIdSlice) Swap(i, j int)

Swap swaps the elements with indexes i and j.

type SubredditWatchItem

type SubredditWatchItem struct {
	Sub       string `json:"sub"`
	Guild     string `json:"guild"`
	Channel   string `json:"channel"`
	ID        int    `json:"id"`
	UseEmbeds bool   `json:"use_embeds"`
}

func FindWatchItem

func FindWatchItem(source []*SubredditWatchItem, id int) *SubredditWatchItem

func GetConfig

func GetConfig(key string) ([]*SubredditWatchItem, error)

func (*SubredditWatchItem) Remove

func (item *SubredditWatchItem) Remove() error

func (*SubredditWatchItem) Set

func (item *SubredditWatchItem) Set() error

Jump to

Keyboard shortcuts

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