summaryrefslogtreecommitdiff
path: root/rss.go
blob: 2dc45a6be80430fc74214efe1bfd66e6ded563fd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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`,
		},
	})
}