mirror of https://github.com/velour/catbase.git
Fixes #56 again because I did it wrong.
This commit is contained in:
parent
9952154433
commit
1827765a4d
17
bot/bot.go
17
bot/bot.go
|
@ -3,18 +3,21 @@
|
||||||
package bot
|
package bot
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"code.google.com/p/velour/irc"
|
|
||||||
"github.com/chrissexton/alepale/config"
|
|
||||||
"html/template"
|
"html/template"
|
||||||
"labix.org/v2/mgo"
|
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"code.google.com/p/velour/irc"
|
||||||
|
"github.com/chrissexton/alepale/config"
|
||||||
|
"labix.org/v2/mgo"
|
||||||
)
|
)
|
||||||
|
|
||||||
const actionPrefix = "\x01ACTION"
|
const actionPrefix = "\x01ACTION"
|
||||||
|
|
||||||
|
var throttle <-chan time.Time
|
||||||
|
|
||||||
// Bot type provides storage for bot-wide information, configs, and database connections
|
// Bot type provides storage for bot-wide information, configs, and database connections
|
||||||
type Bot struct {
|
type Bot struct {
|
||||||
// Each plugin must be registered in our plugins handler. To come: a map so that this
|
// Each plugin must be registered in our plugins handler. To come: a map so that this
|
||||||
|
@ -167,6 +170,14 @@ func (b *Bot) SendMessage(channel, message string) {
|
||||||
} else {
|
} else {
|
||||||
message = ""
|
message = ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if throttle == nil {
|
||||||
|
ratePerSec := b.Config.RatePerSec
|
||||||
|
throttle = time.Tick(time.Second / time.Duration(ratePerSec))
|
||||||
|
}
|
||||||
|
|
||||||
|
<-throttle
|
||||||
|
|
||||||
b.Client.Out <- m
|
b.Client.Out <- m
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
4
main.go
4
main.go
|
@ -91,9 +91,6 @@ func handleConnection() {
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
ratePerSec := Config.RatePerSec
|
|
||||||
throttle := time.Tick(time.Second * time.Duration(1.0/ratePerSec))
|
|
||||||
|
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case msg, ok := <-Client.In:
|
case msg, ok := <-Client.In:
|
||||||
|
@ -105,7 +102,6 @@ func handleConnection() {
|
||||||
handleMsg(msg)
|
handleMsg(msg)
|
||||||
|
|
||||||
case <-t.C:
|
case <-t.C:
|
||||||
<-throttle // rate limit our Service.Method RPCs
|
|
||||||
Client.Out <- irc.Msg{Cmd: irc.PING, Args: []string{Client.Server}}
|
Client.Out <- irc.Msg{Cmd: irc.PING, Args: []string{Client.Server}}
|
||||||
t = time.NewTimer(pingTime)
|
t = time.NewTimer(pingTime)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue