Browse Source

s/feedreader/rssbot/g

Because apparently "Feed Reader" is the name of a thing popular enough that we
don't want to step on toes, so let's call it the name of a less popular thing.
kegan/rssbot
Kegan Dougal 8 years ago
parent
commit
cd39219113
  1. 2
      src/github.com/matrix-org/go-neb/goneb.go
  2. 32
      src/github.com/matrix-org/go-neb/services/rssbot/rssbot.go

2
src/github.com/matrix-org/go-neb/goneb.go

@ -10,11 +10,11 @@ import (
_ "github.com/matrix-org/go-neb/realms/jira"
"github.com/matrix-org/go-neb/server"
_ "github.com/matrix-org/go-neb/services/echo"
_ "github.com/matrix-org/go-neb/services/feedreader"
_ "github.com/matrix-org/go-neb/services/giphy"
_ "github.com/matrix-org/go-neb/services/github"
_ "github.com/matrix-org/go-neb/services/guggy"
_ "github.com/matrix-org/go-neb/services/jira"
_ "github.com/matrix-org/go-neb/services/rssbot"
"github.com/matrix-org/go-neb/types"
_ "github.com/mattn/go-sqlite3"
"net/http"

32
src/github.com/matrix-org/go-neb/services/feedreader/feedreader.go → src/github.com/matrix-org/go-neb/services/rssbot/rssbot.go

@ -13,7 +13,7 @@ import (
"time"
)
const minPollingIntervalSeconds = (10 * 60) // 10min
const minPollingIntervalSeconds = 60 // 1 min (News feeds can be genuinely spammy)
type feedPoller struct{}
@ -24,9 +24,9 @@ func (p *feedPoller) OnPoll(s types.Service, cli *matrix.Client) {
"service_type": s.ServiceType(),
})
frService, ok := s.(*feedReaderService)
frService, ok := s.(*rssBotService)
if !ok {
logger.Error("FeedReader: OnPoll called without a Feed Service instance")
logger.Error("RSSBot: OnPoll called without a Feed Service instance")
return
}
now := time.Now().Unix() // Second resolution
@ -71,7 +71,7 @@ func (p *feedPoller) OnPoll(s types.Service, cli *matrix.Client) {
}
// Query the given feed, update relevant timestamps and return NEW items
func (p *feedPoller) queryFeed(s *feedReaderService, feedURL string) (*gofeed.Feed, []gofeed.Item, error) {
func (p *feedPoller) queryFeed(s *rssBotService, feedURL string) (*gofeed.Feed, []gofeed.Item, error) {
log.WithField("feed_url", feedURL).Info("Querying feed")
var items []gofeed.Item
fp := gofeed.NewParser()
@ -119,7 +119,7 @@ func (p *feedPoller) queryFeed(s *feedReaderService, feedURL string) (*gofeed.Fe
return feed, items, nil
}
func (p *feedPoller) updateFeedInfo(s *feedReaderService, feedURL string, nextPollTs, feedUpdatedTs int64) {
func (p *feedPoller) updateFeedInfo(s *rssBotService, feedURL string, nextPollTs, feedUpdatedTs int64) {
for u := range s.Feeds {
if u != feedURL {
continue
@ -131,7 +131,7 @@ func (p *feedPoller) updateFeedInfo(s *feedReaderService, feedURL string, nextPo
}
}
func (p *feedPoller) sendToRooms(s *feedReaderService, cli *matrix.Client, feedURL string, feed *gofeed.Feed, item gofeed.Item) error {
func (p *feedPoller) sendToRooms(s *rssBotService, cli *matrix.Client, feedURL string, feed *gofeed.Feed, item gofeed.Item) error {
logger := log.WithField("feed_url", feedURL).WithField("title", item.Title)
logger.Info("New feed item")
for _, roomID := range s.Feeds[feedURL].Rooms {
@ -150,7 +150,7 @@ func itemToHTML(feed *gofeed.Feed, item gofeed.Item) matrix.HTMLMessage {
))
}
type feedReaderService struct {
type rssBotService struct {
types.DefaultService
id string
serviceUserID string
@ -162,19 +162,19 @@ type feedReaderService struct {
} `json:"feeds"`
}
func (s *feedReaderService) ServiceUserID() string { return s.serviceUserID }
func (s *feedReaderService) ServiceID() string { return s.id }
func (s *feedReaderService) ServiceType() string { return "feedreader" }
func (s *feedReaderService) Poller() types.Poller { return &feedPoller{} }
func (s *rssBotService) ServiceUserID() string { return s.serviceUserID }
func (s *rssBotService) ServiceID() string { return s.id }
func (s *rssBotService) ServiceType() string { return "rssbot" }
func (s *rssBotService) Poller() types.Poller { return &feedPoller{} }
// Register will check the liveness of each RSS feed given. If all feeds check out okay, no error is returned.
func (s *feedReaderService) Register(oldService types.Service, client *matrix.Client) error {
func (s *rssBotService) Register(oldService types.Service, client *matrix.Client) error {
if len(s.Feeds) == 0 {
// this is an error UNLESS the old service had some feeds in which case they are deleting us :(
var numOldFeeds int
oldFeedService, ok := oldService.(*feedReaderService)
oldFeedService, ok := oldService.(*rssBotService)
if !ok {
log.WithField("service_id", oldService.ServiceID()).Error("Old service isn't a FeedReaderService")
log.WithField("service_id", oldService.ServiceID()).Error("Old service isn't a rssBotService")
} else {
numOldFeeds = len(oldFeedService.Feeds)
}
@ -196,7 +196,7 @@ func (s *feedReaderService) Register(oldService types.Service, client *matrix.Cl
return nil
}
func (s *feedReaderService) PostRegister(oldService types.Service) {
func (s *rssBotService) PostRegister(oldService types.Service) {
if len(s.Feeds) == 0 { // bye-bye :(
logger := log.WithFields(log.Fields{
"service_id": s.ServiceID(),
@ -212,7 +212,7 @@ func (s *feedReaderService) PostRegister(oldService types.Service) {
func init() {
types.RegisterService(func(serviceID, serviceUserID, webhookEndpointURL string) types.Service {
r := &feedReaderService{
r := &rssBotService{
id: serviceID,
serviceUserID: serviceUserID,
}
Loading…
Cancel
Save