summaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2015-07-17 14:18:34 +0200
committerDimitri Sokolyuk <demon@dim13.org>2015-07-17 14:18:34 +0200
commit9478c76ea54a69f09676df6d3c86479723f363d9 (patch)
tree7cf7aa7ffc164fb53777a68768f05d043fe7acfb /main.go
parentd76a78f72877154aa37d5a1f0e8846d3918cd92e (diff)
Add cmd timeout and score percent
Diffstat (limited to 'main.go')
-rw-r--r--main.go42
1 files changed, 27 insertions, 15 deletions
diff --git a/main.go b/main.go
index 7424398..1a2cdaa 100644
--- a/main.go
+++ b/main.go
@@ -23,19 +23,21 @@ var (
type Commander interface {
irc.Handler
fmt.Stringer
+ Timeout() bool
}
type Command struct {
Help string
Arg string
+ Last time.Time
}
type (
- Last struct{ Command }
- RSS struct{ Command }
- Theo struct{ Command }
- Help struct{ Command }
- Top struct{ Command }
+ Last struct{ Command }
+ RSS struct{ Command }
+ Theo struct{ Command }
+ Help struct{ Command }
+ Top struct{ Command }
)
var (
@@ -48,6 +50,14 @@ func Register(cmd string, f Commander) {
}
func (v Command) String() string { return v.Help }
+func (v *Command) Timeout() bool {
+ log.Println("timeout:", time.Since(v.Last))
+ if time.Since(v.Last) > time.Minute {
+ v.Last = time.Now()
+ return false
+ }
+ return true
+}
func (_ Last) Handle(conn *irc.Conn, line *irc.Line) {
buffer.Do(func(v interface{}) {
@@ -109,8 +119,10 @@ func privmsg(conn *irc.Conn, line *irc.Line) {
if len(f) == 1 {
cmd := strings.ToLower(f[0])
if c, ok := commands[cmd]; ok {
- log.Println(line.Nick, f)
- go c.Handle(conn, line)
+ if !line.Public() || !c.Timeout() {
+ log.Println(line.Nick, f)
+ go c.Handle(conn, line)
+ }
}
}
@@ -133,46 +145,46 @@ func privmsg(conn *irc.Conn, line *irc.Line) {
func init() {
flag.Parse()
- Register("last", Last{
+ Register("last", &Last{
Command{
Help: "Return last 10 messages",
},
})
- Register("theo", Theo{
+ Register("theo", &Theo{
Command{
Help: "Quote Theo De Raadt",
},
})
- Register("news", RSS{
+ 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{
+ 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{
+ 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{
+ Register("bsd", &RSS{
Command{
Help: "Undeadly news (msg private to see all)",
Arg: `http://undeadly.org/cgi?action=rss`,
},
})
- Register("help", Help{
+ Register("help", &Help{
Command{
Help: "This help",
},
})
- Register("top", Top{
+ Register("top", &Top{
Command{
Help: "Top 10 flooder",
},