package main import ( "fmt" "log" "time" "dim13.org/rss" irc "github.com/fluffle/goirc/client" ) var Feed = map[string]string{ "News": `https://www.linux.org.ru/section-rss.jsp?section=1`, "Forum": `https://www.linux.org.ru/section-rss.jsp?section=2`, "Gallery": `https://www.linux.org.ru/section-rss.jsp?section=3`, "Polls": `https://www.linux.org.ru/section-rss.jsp?section=5`, "OpenNET": `http://www.opennet.ru/opennews/opennews_all_noadv.rss`, "Undeadly": `http://undeadly.org/cgi?action=rss`, "Kernel": `https://www.kernel.org/feeds/kdist.xml`, } type News struct { Source string Item rss.Item } const timeOut = 5 * time.Minute var news = make(chan News) func ShowNews(conn *irc.Conn, _ *irc.Line) { for { n := <-news s := fmt.Sprintf("%v: %v - %v", n.Source, n.Item.Title, n.Item.Link) conn.Privmsg(*room, s) } } func init() { for k, v := range Feed { go func(c chan News, source, url string) { for { to := time.Now().Add(-timeOut) r, err := rss.Fetch(url) if err != nil { log.Println(err) } for _, i := range r.Channel.Items { if i.PubDate.After(to) { c <- News{source, i} } } time.Sleep(timeOut) } }(news, k, v) } }