From dd45f63209a8e51979b11182253ee80b5289c10a Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Thu, 25 Oct 2018 19:25:10 +0200 Subject: Drop Version, make lint happy --- Makefile | 5 ----- feeds.go | 2 +- main.go | 33 +++++++++++---------------------- re.go | 8 ++++---- re_test.go | 2 +- rss.go | 14 +++++++------- 6 files changed, 24 insertions(+), 40 deletions(-) delete mode 100644 Makefile diff --git a/Makefile b/Makefile deleted file mode 100644 index 0a08c29..0000000 --- a/Makefile +++ /dev/null @@ -1,5 +0,0 @@ -VERSION != git describe --tags --always -BUILD != date +%FT%T%z - -build: - go build -ldflags "-X main.Version=${VERSION} -X main.Build=${BUILD}" diff --git a/feeds.go b/feeds.go index 43dffd5..668a7c4 100644 --- a/feeds.go +++ b/feeds.go @@ -2,7 +2,7 @@ package main import "time" -var Feeds = []Feed{ +var feeds = []feed{ { Name: "LOR News", URL: `https://www.linux.org.ru/section-rss.jsp?section=1`, diff --git a/main.go b/main.go index 9729e87..3e63b63 100644 --- a/main.go +++ b/main.go @@ -11,20 +11,15 @@ import ( lru "github.com/hashicorp/golang-lru" ) -var ( - Version string - Build string -) - const maxLen = 450 -type Notify struct { +type notify struct { conn *irc.Conn target string } -func NewNotify(conn *irc.Conn, target string) *Notify { - return &Notify{conn: conn, target: target} +func newNotify(conn *irc.Conn, target string) *notify { + return ¬ify{conn: conn, target: target} } func limit(n int, s string) string { @@ -35,7 +30,7 @@ func limit(n int, s string) string { return string(r) } -func (n *Notify) Write(p []byte) (int, error) { +func (n *notify) Write(p []byte) (int, error) { s := limit(maxLen, string(p)) log.Println("send", s) n.conn.Notice(n.target, s) @@ -70,7 +65,7 @@ func privmsg(room string) irc.HandlerFunc { fixed, err := re(tofix.(string), t[1:], global) if err == nil && fixed != tofix { log.Println("regexp", t) - fmt.Fprintf(NewNotify(conn, line.Target()), "%v meant to say: %s", line.Nick, fixed) + fmt.Fprintf(newNotify(conn, line.Target()), "%v meant to say: %s", line.Nick, fixed) return } @@ -88,7 +83,7 @@ func privmsg(room string) irc.HandlerFunc { titles.Add(v, title) } if title != "" { - w := NewNotify(conn, line.Target()) + w := newNotify(conn, line.Target()) if ok { fmt.Fprintf(w, "Title: %v (cached)", title) } else { @@ -103,19 +98,13 @@ func privmsg(room string) irc.HandlerFunc { func main() { var ( - node = flag.String("node", "irc.freenode.org", "IRC server") - notls = flag.Bool("notls", false, "disable TLS") - room = flag.String("room", "#lor", "IRC channel") - name = flag.String("name", "dim13", "bots name") - version = flag.Bool("version", false, "display version and exit") + node = flag.String("node", "irc.freenode.org", "IRC server") + notls = flag.Bool("notls", false, "disable TLS") + room = flag.String("room", "#lor", "IRC channel") + name = flag.String("name", "dim13", "bots name") ) flag.Parse() - if *version { - log.Printf("Version: %v, Build: %v", Version, Build) - return - } - conf := irc.NewConfig(*name) conf.Server = *node if !*notls { @@ -132,7 +121,7 @@ func main() { conn.HandleFunc(irc.CONNECTED, func(conn *irc.Conn, _ *irc.Line) { conn.Join(*room) - Watch(NewNotify(conn, *room), Feeds) + watch(newNotify(conn, *room), feeds) }) conn.HandleBG(irc.PRIVMSG, privmsg(*room)) diff --git a/re.go b/re.go index 4d3fa48..fab6386 100644 --- a/re.go +++ b/re.go @@ -6,17 +6,17 @@ import ( "strings" ) -var ErrNotRE = errors.New("not re") +var errNotRE = errors.New("not re") func re(s, r string, global bool) (string, error) { // min: at least two separators if len(r) < 2 { - return "", ErrNotRE + return "", errNotRE } z := strings.Split(r[1:], string(r[0])) // match // and /// if len(z) < 2 || len(z) > 3 { - return "", ErrNotRE + return "", errNotRE } re, err := regexp.Compile(z[0]) if err != nil { @@ -28,7 +28,7 @@ func re(s, r string, global bool) (string, error) { } return re.ReplaceAllStringFunc(s, func(b string) string { if i != 0 { - i -= 1 + i-- return z[1] } return b diff --git a/re_test.go b/re_test.go index 21aa15f..251de25 100644 --- a/re_test.go +++ b/re_test.go @@ -16,7 +16,7 @@ func TestRE(t *testing.T) { {"/ /A", "abd ddd xxx", "abdAdddAxxx", true, nil}, {"///", "abd ddd xxx", "abd ddd xxx", false, nil}, {"//", "abd ddd xxx", "abd ddd xxx", false, nil}, - {"/", "abd ddd xxx", "", false, ErrNotRE}, + {"/", "abd ddd xxx", "", false, errNotRE}, {"/1/2", "1", "2", false, nil}, {"/^d/X", "abd ddd xxx", "abd ddd xxx", false, nil}, } diff --git a/rss.go b/rss.go index a445054..d14db94 100644 --- a/rss.go +++ b/rss.go @@ -9,18 +9,18 @@ import ( "dim13.org/rss" ) -type Feed struct { +type feed struct { Name string URL string Every time.Duration } -type News struct { - Feed +type news struct { + feed rss.Item } -func (n News) String() string { +func (n news) String() string { s := fmt.Sprintf("%v: %v", n.Name, n.Title) if n.Author != "" { s += fmt.Sprintf(" (%v) ", n.Author) @@ -31,7 +31,7 @@ func (n News) String() string { return s } -func (f Feed) watch(w io.Writer) { +func (f feed) watch(w io.Writer) { ticker := time.NewTicker(f.Every) defer ticker.Stop() for t := range ticker.C { @@ -43,13 +43,13 @@ func (f Feed) watch(w io.Writer) { last := t.Add(-f.Every) for _, i := range r.Channel.Items { if i.PubDate.After(last) { - fmt.Fprint(w, News{f, i}) + fmt.Fprint(w, news{f, i}) } } } } -func Watch(w io.Writer, feeds []Feed) { +func watch(w io.Writer, feeds []feed) { for _, feed := range feeds { go feed.watch(w) } -- cgit v1.2.3