summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--main.go8
-rw-r--r--score.go12
2 files changed, 13 insertions, 7 deletions
diff --git a/main.go b/main.go
index 49d647c..00d4f52 100644
--- a/main.go
+++ b/main.go
@@ -103,7 +103,11 @@ func (_ Help) Handle(conn *irc.Conn, line *irc.Line) {
}
func (_ Top) Handle(conn *irc.Conn, line *irc.Line) {
- s := fmt.Sprint(NewScores())
+ n := 100
+ if line.Public() {
+ n = 10
+ }
+ s := fmt.Sprint(NewScores(n))
conn.Privmsg(line.Target(), s)
}
@@ -194,7 +198,7 @@ func init() {
})
Register("top", &Top{
Command{
- Help: "Top 10 flooder",
+ Help: "Top 10 flooder (msg private to see top 100)",
},
})
}
diff --git a/score.go b/score.go
index f38cccb..3edf7c8 100644
--- a/score.go
+++ b/score.go
@@ -25,18 +25,20 @@ func (s Scores) Len() int { return len(s) }
func (s Scores) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
func (s Scores) Less(i, j int) bool { return s[i].Count < s[j].Count }
-func NewScores() (s Scores) {
- var total int
+func NewScores(n int) (s Scores) {
for k, v := range score {
s = append(s, Score{
Nick: k,
Count: v,
})
- total += v
}
sort.Sort(sort.Reverse(s))
- if len(s) > 10 {
- s = s[:10]
+ if n > 0 && len(s) > n {
+ s = s[:n]
+ }
+ var total int
+ for _, v := range s {
+ total += v.Count
}
for i := range s {
s[i].Percent = 100.0 * float64(s[i].Count) / float64(total)