summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2016-12-20 23:11:53 +0100
committerDimitri Sokolyuk <demon@dim13.org>2016-12-20 23:11:53 +0100
commitd3203ad6128ec64ce5422e7609b71f518bc9a01a (patch)
tree86fd69b8d41f5b4bd1e10f32dc42718961232598
parent5fe432b7c1d6d626699e8091005a0de788d8168a (diff)
Watch news
-rw-r--r--main.go2
-rw-r--r--rss.go44
2 files changed, 23 insertions, 23 deletions
diff --git a/main.go b/main.go
index 9dcf9d6..1abe5e1 100644
--- a/main.go
+++ b/main.go
@@ -23,7 +23,7 @@ func main() {
c.HandleFunc(irc.CONNECTED, func(conn *irc.Conn, line *irc.Line) {
conn.Join(*room)
- ShowNews(conn, *room)
+ go ShowNews(conn, *room)
})
c.HandleFunc(irc.KICK, func(conn *irc.Conn, line *irc.Line) {
diff --git a/rss.go b/rss.go
index 0a49952..1d9d9db 100644
--- a/rss.go
+++ b/rss.go
@@ -89,32 +89,32 @@ func (n News) String() string {
return s
}
+func (f Feed) Watch(news chan News) {
+ ticker := time.NewTicker(f.Every)
+ defer ticker.Stop()
+ for t := range ticker.C {
+ r, err := rss.Fetch(f.URL)
+ if err != nil {
+ log.Println(f.Name, err)
+ return
+ }
+ last := t.Add(-f.Every)
+ for _, i := range r.Channel.Items {
+ if i.PubDate.After(last) {
+ news <- News{f, i}
+ }
+ }
+ }
+}
+
func ShowNews(conn *irc.Conn, room string) {
news := make(chan News)
for _, f := range Feeds {
- go func(f Feed) {
- ticker := time.NewTicker(f.Every)
- defer ticker.Stop()
- for t := range ticker.C {
- r, err := rss.Fetch(f.URL)
- if err != nil {
- log.Println(f.Name, err)
- return
- }
- to := t.Add(-f.Every)
- for _, i := range r.Channel.Items {
- if i.PubDate.After(to) {
- news <- News{f, i}
- }
- }
- }
- }(f)
+ go f.Watch(news)
}
- go func() {
- for n := range news {
- conn.Notice(room, n.String())
- }
- }()
+ for n := range news {
+ conn.Notice(room, n.String())
+ }
}