diff --git a/config.json b/config.json index 2890f7f..75188fa 100644 --- a/config.json +++ b/config.json @@ -9,6 +9,7 @@ "Pass": "AlePaleTest:test", "FullName": "Ale Pale", "CommandChar": "!", + "RatePerSec": 10.0, "QuoteChance": 0.99, "QuoteTime": 1, "LogLength": 50, diff --git a/config/config.go b/config/config.go index ce62557..7fc044b 100644 --- a/config/config.go +++ b/config/config.go @@ -18,6 +18,7 @@ type Config struct { FullName string Version string CommandChar string + RatePerSec float64 QuoteChance float64 QuoteTime int LogLength int diff --git a/main.go b/main.go index 32d25df..6ca5b2f 100644 --- a/main.go +++ b/main.go @@ -3,15 +3,16 @@ package main import ( - "code.google.com/p/velour/irc" "flag" - "github.com/chrissexton/alepale/bot" - "github.com/chrissexton/alepale/config" - "github.com/chrissexton/alepale/plugins" "io" "log" "os" "time" + + "code.google.com/p/velour/irc" + "github.com/chrissexton/alepale/bot" + "github.com/chrissexton/alepale/config" + "github.com/chrissexton/alepale/plugins" ) const ( @@ -90,6 +91,9 @@ func handleConnection() { } }() + ratePerSec := Config.RatePerSec + throttle := time.Tick(time.Second * time.Duration(1.0/ratePerSec)) + for { select { case msg, ok := <-Client.In: @@ -101,6 +105,7 @@ func handleConnection() { handleMsg(msg) case <-t.C: + <-throttle // rate limit our Service.Method RPCs Client.Out <- irc.Msg{Cmd: irc.PING, Args: []string{Client.Server}} t = time.NewTimer(pingTime)