Introduce general send limit to prevent global-timeouts

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2021-04-21 23:44:13 +02:00
parent 210d316786
commit 6116f1bfcd
Signed by: luzifer
GPG key ID: 0066F03ED215AD7D
2 changed files with 4 additions and 6 deletions

9
irc.go
View file

@ -14,9 +14,6 @@ import (
const (
twitchRequestTimeout = 2 * time.Second
// 20 join attempts per 10 seconds per user (2000 for verified bots)
// https://dev.twitch.tv/docs/irc/guide
twitchChannelJoinDelay = time.Second
)
const (
@ -51,6 +48,9 @@ func newIRCHandler() (*ircHandler, error) {
User: username,
Name: username,
Handler: h,
SendLimit: cfg.IRCRateLimit,
SendBurst: 0, // Twitch uses a bucket system, we don't have anything to replicate that in this IRC client
})
h.conn = conn
h.user = username
@ -63,9 +63,6 @@ func (i ircHandler) Close() error { return i.conn.Close() }
func (i ircHandler) ExecuteJoins(channels []string) {
for _, ch := range channels {
i.c.Write(fmt.Sprintf("JOIN #%s", strings.TrimLeft(ch, "#")))
// We need to wait a moment between joins not to get kicked
time.Sleep(twitchChannelJoinDelay)
}
}

View file

@ -20,6 +20,7 @@ var (
cfg = struct {
CommandTimeout time.Duration `flag:"command-timeout" default:"30s" description:"Timeout for command execution"`
Config string `flag:"config,c" default:"./config.yaml" description:"Location of configuration file"`
IRCRateLimit time.Duration `flag:"rate-limit" default:"1500ms" description:"How often to send a message (default: 20/30s=1500ms, if your bot is mod everywhere: 100/30s=300ms, different for known/verified bots)"`
LogLevel string `flag:"log-level" default:"info" description:"Log level (debug, info, warn, error, fatal)"`
StorageFile string `flag:"storage-file" default:"./storage.json.gz" description:"Where to store the data"`
TwitchClient string `flag:"twitch-client" default:"" description:"Client ID to act as"`