summaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2015-07-11 20:02:57 +0200
committerDimitri Sokolyuk <demon@dim13.org>2015-07-11 20:02:57 +0200
commit2700844318c370fda20bb39327620014d27dddf0 (patch)
treed662d99faf7fd3e38c928ef0c40544baa07b1763 /main.go
parentcd75246ecebd59ec661c79c9ee713313e2e62414 (diff)
Readd top10
Diffstat (limited to 'main.go')
-rw-r--r--main.go35
1 files changed, 11 insertions, 24 deletions
diff --git a/main.go b/main.go
index 6c35121..bec3f53 100644
--- a/main.go
+++ b/main.go
@@ -41,7 +41,6 @@ type (
var (
commands = make(map[string]Commander)
- top = make(map[string]int)
buffer = ring.New(10)
)
@@ -77,7 +76,7 @@ func (v RSS) Handle(conn *irc.Conn, line *irc.Line) {
news.Channel.Items = news.Channel.Items[:3]
}
for n, i := range news.Channel.Items {
- s := fmt.Sprintf("%2d. %v", n+1, i.Title)
+ s := fmt.Sprintf("%2d. %v - %v", n+1, i.Title, i.Link)
conn.Privmsg(line.Target(), s)
}
}
@@ -114,22 +113,8 @@ func (_ Metar) Handle(conn *irc.Conn, line *irc.Line) {
}
func (_ Top) Handle(conn *irc.Conn, line *irc.Line) {
- score := make(map[int]string)
- var selector []int
- for nick, lines := range top {
- score[lines] = nick
- selector = append(selector, lines)
- }
- sort.Sort(sort.Reverse(sort.IntSlice(selector)))
- if line.Public() && len(selector) > 10 {
- selector = selector[:10]
- } else if len(selector) > 20 {
- selector = selector[:20]
- }
- for n, lines := range selector {
- s := fmt.Sprintf("%2d. %v (%v)", n+1, score[lines], lines)
- conn.Privmsg(line.Target(), s)
- }
+ s := fmt.Sprint(NewScores())
+ conn.Privmsg(line.Target(), s)
}
func privmsg(conn *irc.Conn, line *irc.Line) {
@@ -138,7 +123,7 @@ func privmsg(conn *irc.Conn, line *irc.Line) {
if line.Public() && line.Nick != conn.Me().Nick {
buffer.Value = line
buffer = buffer.Next()
- top[line.Nick]++
+ Count(line.Nick)
}
// lookup command
@@ -207,12 +192,12 @@ func init() {
Help: "This help",
},
})
+ Register("top", Top{
+ Command{
+ Help: "Top 10 flooder",
+ },
+ })
/*
- Register("top", Top{
- Command{
- Help: "Top 10 flooder",
- },
- })
Register("metar", Metar{
Command{
Help: "Weather (argument: ICAO-Code, msg private for verbose output)",
@@ -238,5 +223,7 @@ func main() {
log.Fatal(err)
}
+ go autoSave()
+
<-quit
}