feeds

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2022 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrAlreadySubscribed = errors.New("already_subscribed")

Error returned when we're already subscribed

Functions

This section is empty.

Types

type Feeds

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

Feeds is an object that manages feeds and subscriptions

func (*Feeds) AddFeed

func (f *Feeds) AddFeed(url string, tx *sqlx.Tx) (*models.Feed, error)

AddFeed adds a new feed The transaction is optional

func (*Feeds) AddSubscription

func (f *Feeds) AddSubscription(url string, chatId int64) (*Post, error)

AddSubscription subscribes a chat to a feed, adding the feed if required

func (*Feeds) DeleteSubscription

func (f *Feeds) DeleteSubscription(feedId int64, chatId int64) error

DeleteSubscription removes a subscription to a feed If this is the last subscription to a feed, remove the feed too

func (*Feeds) GetFeedByURL

func (f *Feeds) GetFeedByURL(url string, tx *sqlx.Tx) (*models.Feed, error)

GetFeedByURL returns a feed from its URL, or 0 if it's not present The transaction is optional

func (*Feeds) Init

func (f *Feeds) Init(ctx context.Context) (err error)

Init the object

func (*Feeds) ListSubscriptions

func (f *Feeds) ListSubscriptions(chatId int64) ([]models.Feed, error)

ListSubscriptions lists all subscriptions for a chat

func (*Feeds) QueueUpdate

func (f *Feeds) QueueUpdate()

QueueUpdate queues an update of the feeds

func (*Feeds) RequestDockerFeed

func (f *Feeds) RequestDockerFeed(feed *models.Feed) (posts *gofeed.Feed, err error)

RequestDockerFeed requests a "feed" containing the latest tags for an image on Docker Hub

func (*Feeds) RequestFeed

func (f *Feeds) RequestFeed(feed *models.Feed) (posts *gofeed.Feed, err error)

RequestFeed requests a feed of any kind

func (*Feeds) RequestMetadata

func (f *Feeds) RequestMetadata(post *Post)

RequestMetadata requests the web page to get the title, description, and image from the page's metadata itself This method updates the value of the post argument as a side effect Errors are logged only and then ignored

func (*Feeds) RequestRSSFeed

func (f *Feeds) RequestRSSFeed(feed *models.Feed) (posts *gofeed.Feed, err error)

RequestRSSFeed requests a RSS feed and parses it with gofeed We're using this rather than gofeed.ParseURL to have more control on the request

func (*Feeds) SetUpdateChan

func (f *Feeds) SetUpdateChan(ch chan<- UpdateMessage)

SetUpdateChan sets the channel to use for notify the bot of new messages for subscribers

type Post

type Post struct {
	Title string
	Link  string
	Date  time.Time
	Photo string
}

Post represents a post in the feed

type UpdateMessage

type UpdateMessage struct {
	Feed   *models.Feed
	Post   Post
	ChatId int64
}

UpdateMessage is the message that needs to be sent to subscribers for new posts

Jump to

Keyboard shortcuts

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