diff options
author | Dimitri Sokolyuk <demon@dim13.org> | 2015-07-21 17:06:35 +0200 |
---|---|---|
committer | Dimitri Sokolyuk <demon@dim13.org> | 2015-07-21 17:06:35 +0200 |
commit | f22db3b8ba23c66dce23602c5e948aa7b6d5af31 (patch) | |
tree | 71eb4a2b0a636b739cea9f857b632fcf898be97e /rss.go | |
parent | 612217ce228a955bae03b2b5f0552abbc84c9f03 (diff) |
Split a bit
Diffstat (limited to 'rss.go')
-rw-r--r-- | rss.go | 52 |
1 files changed, 52 insertions, 0 deletions
@@ -0,0 +1,52 @@ +package main + +import ( + "fmt" + + "dim13.org/rss" + irc "github.com/fluffle/goirc/client" +) + +type RSS struct{ Command } + +func (v RSS) Handle(conn *irc.Conn, line *irc.Line) { + news, err := rss.Fetch(v.Arg) + if err != nil { + conn.Privmsg(line.Target(), err.Error()) + return + } + if line.Public() && len(news.Channel.Items) > 3 { + news.Channel.Items = news.Channel.Items[:3] + } + for n, i := range news.Channel.Items { + s := fmt.Sprintf("%2d. %v - %v", n+1, i.Title, i.Link) + conn.Privmsg(line.Target(), s) + } +} + +func init() { + Register("news", &RSS{ + Command{ + Help: "LOR news (msg private to see all)", + Arg: `https://www.linux.org.ru/section-rss.jsp?section=1`, + }, + }) + Register("forum", &RSS{ + Command{ + Help: "LOR forum (msg private to see all)", + Arg: `https://www.linux.org.ru/section-rss.jsp?section=2`, + }, + }) + Register("gallery", &RSS{ + Command{ + Help: "LOR gallery (msg private to see all)", + Arg: `https://www.linux.org.ru/section-rss.jsp?section=3`, + }, + }) + Register("bsd", &RSS{ + Command{ + Help: "Undeadly news (msg private to see all)", + Arg: `http://undeadly.org/cgi?action=rss`, + }, + }) +} |