reddit

package
v1.31.9 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2021 License: MIT Imports: 38 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 seconds 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 faults 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 (
	FilterNSFWNone    = 0 // allow both nsfw and non nsfw content
	FilterNSFWIgnore  = 1 // only allow non-nsfw content
	FilterNSFWRequire = 2 // only allow nsfw content
)
View Source
const (
	// Max feeds per guild
	GuildMaxFeedsNormal  = 100
	GuildMaxFeedsPremium = 1000
)
View Source
const RedditLogoPNGB64 = `` /* 2110-byte string literal not displayed */

Variables

View Source
var DBSchemas = []string{`
CREATE TABLE IF NOT EXISTS reddit_feeds (
	id BIGSERIAL PRIMARY KEY,
	guild_id BIGINT NOT NULL,
	channel_id BIGINT NOT NULL,
	subreddit TEXT NOT NULL,

	-- 0 = none, 1 = ignore, 2 - whitelist
	filter_nsfw INT NOT NULL,
	min_upvotes INT NOT NULL,

	use_embeds BOOLEAN NOT NULL,
	slow BOOLEAN NOT NULL
);
`, `
CREATE INDEX IF NOT EXISTS redidt_feeds_guild_idx ON reddit_feeds(guild_id);
`, `
CREATE INDEX IF NOT EXISTS redidt_feeds_subreddit_idx ON reddit_feeds(subreddit);

`, `
ALTER TABLE reddit_feeds ADD COLUMN IF NOT EXISTS disabled BOOLEAN NOT NULL DEFAULT FALSE;
`}
View Source
var KeyLastScannedPostIDFast = "reddit_last_post_id"
View Source
var KeyLastScannedPostIDSlow = "reddit_slow_last_post_id"
View Source
var PageHTML string

Functions

func CreatePostMessage added in v1.4.1

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

func FindFeed added in v1.15.1

func FindFeed(feeds []*models.RedditFeed, id int64) *models.RedditFeed

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 CreateForm added in v1.15.1

type CreateForm struct {
	Subreddit  string `schema:"subreddit" valid:",1,100"`
	Slow       bool   `schema:"slow"`
	Channel    int64  `schema:"channel" valid:"channel,true`
	ID         int64  `schema:"id"`
	UseEmbeds  bool   `schema:"use_embeds"`
	NSFWMode   int    `schema:"nsfw_filter"`
	MinUpvotes int    `schema:"min_upvotes"`
}

type CtxKey

type CtxKey int
const (
	CurrentConfig CtxKey = iota
)

type KeyFastFeeds added in v1.25.0

type KeyFastFeeds string

type KeySlowFeeds added in v1.25.0

type KeySlowFeeds string

type LegacySubredditWatchItem added in v1.15.1

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

func FindLegacyWatchItem added in v1.15.1

func FindLegacyWatchItem(source []*LegacySubredditWatchItem, id int) *LegacySubredditWatchItem

func GetLegacyConfig added in v1.15.1

func GetLegacyConfig(key string) ([]*LegacySubredditWatchItem, error)

func (*LegacySubredditWatchItem) Remove added in v1.15.1

func (item *LegacySubredditWatchItem) Remove() error

func (*LegacySubredditWatchItem) Set added in v1.15.1

func (item *LegacySubredditWatchItem) Set() error

type Plugin

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

func (*Plugin) AddCommands added in v1.16.2

func (p *Plugin) AddCommands()

func (*Plugin) DisableFeed added in v1.19.0

func (p *Plugin) DisableFeed(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) LoadServerHomeWidget added in v1.17.0

func (p *Plugin) LoadServerHomeWidget(w http.ResponseWriter, r *http.Request) (web.TemplateData, error)

func (*Plugin) PluginInfo added in v1.17.0

func (p *Plugin) PluginInfo() *common.PluginInfo

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)

func (*Plugin) WebhookAvatar added in v1.16.2

func (p *Plugin) WebhookAvatar() string

type PostFetcher

type PostFetcher struct {
	Name                 string
	LastScannedPostIDKey string
	LastID               int64
	StopChan             chan *sync.WaitGroup
	// contains filtered or unexported fields
}

PostFetcher is responsible from fetching posts from reddit at a given interval and delay delay bieng it will make sure not to call the handler on posts newer than the given delay

func NewPostFetcher

func NewPostFetcher(redditClient *greddit.Client, slow bool, handler PostHandler) *PostFetcher

func (*PostFetcher) GetNewPosts

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

func (*PostFetcher) Run added in v1.15.1

func (p *PostFetcher) Run()

type PostHandler added in v1.15.1

type PostHandler interface {
	HandleRedditPosts(links []*greddit.Link)
}

func NewPostHandler added in v1.15.1

func NewPostHandler(slow bool) PostHandler

type PostHandlerImpl added in v1.15.1

type PostHandlerImpl struct {
	Slow bool
	// contains filtered or unexported fields
}

func (*PostHandlerImpl) FilterFeeds added in v1.15.1

func (p *PostHandlerImpl) FilterFeeds(feeds []*models.RedditFeed, post *reddit.Link) []*models.RedditFeed

func (*PostHandlerImpl) HandleRedditPosts added in v1.15.1

func (p *PostHandlerImpl) HandleRedditPosts(links []*reddit.Link)

type PubSubSubredditEventData added in v1.25.0

type PubSubSubredditEventData struct {
	Subreddit string `json:"subreddit"`
	Slow      bool   `json:"slow"`
}

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 UpdateForm added in v1.15.1

type UpdateForm struct {
	Channel    int64 `schema:"channel" valid:"channel,true`
	ID         int64 `schema:"id"`
	UseEmbeds  bool  `schema:"use_embeds"`
	NSFWMode   int   `schema:"nsfw_filter"`
	MinUpvotes int   `schema:"min_upvotes"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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