mirror of https://github.com/velour/catbase.git
Fixes #56: Add rate limit to outgoing messages
This commit is contained in:
parent
b9d4ce273f
commit
9952154433
|
@ -9,6 +9,7 @@
|
|||
"Pass": "AlePaleTest:test",
|
||||
"FullName": "Ale Pale",
|
||||
"CommandChar": "!",
|
||||
"RatePerSec": 10.0,
|
||||
"QuoteChance": 0.99,
|
||||
"QuoteTime": 1,
|
||||
"LogLength": 50,
|
||||
|
|
|
@ -18,6 +18,7 @@ type Config struct {
|
|||
FullName string
|
||||
Version string
|
||||
CommandChar string
|
||||
RatePerSec float64
|
||||
QuoteChance float64
|
||||
QuoteTime int
|
||||
LogLength int
|
||||
|
|
13
main.go
13
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)
|
||||
|
||||
|
|
Loading…
Reference in New Issue