From f22db3b8ba23c66dce23602c5e948aa7b6d5af31 Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Tue, 21 Jul 2015 17:06:35 +0200 Subject: Split a bit --- rss.go | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 rss.go (limited to 'rss.go') diff --git a/rss.go b/rss.go new file mode 100644 index 0000000..2dc45a6 --- /dev/null +++ b/rss.go @@ -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`, + }, + }) +} -- cgit v1.2.3