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