mirror of
https://github.com/Luzifer/twitch-bot.git
synced 2024-11-08 16:20:02 +00:00
Introduce general send limit to prevent global-timeouts
Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
parent
210d316786
commit
6116f1bfcd
2 changed files with 4 additions and 6 deletions
9
irc.go
9
irc.go
|
@ -14,9 +14,6 @@ import (
|
||||||
|
|
||||||
const (
|
const (
|
||||||
twitchRequestTimeout = 2 * time.Second
|
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 (
|
const (
|
||||||
|
@ -51,6 +48,9 @@ func newIRCHandler() (*ircHandler, error) {
|
||||||
User: username,
|
User: username,
|
||||||
Name: username,
|
Name: username,
|
||||||
Handler: h,
|
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.conn = conn
|
||||||
h.user = username
|
h.user = username
|
||||||
|
@ -63,9 +63,6 @@ func (i ircHandler) Close() error { return i.conn.Close() }
|
||||||
func (i ircHandler) ExecuteJoins(channels []string) {
|
func (i ircHandler) ExecuteJoins(channels []string) {
|
||||||
for _, ch := range channels {
|
for _, ch := range channels {
|
||||||
i.c.Write(fmt.Sprintf("JOIN #%s", strings.TrimLeft(ch, "#")))
|
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)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
1
main.go
1
main.go
|
@ -20,6 +20,7 @@ var (
|
||||||
cfg = struct {
|
cfg = struct {
|
||||||
CommandTimeout time.Duration `flag:"command-timeout" default:"30s" description:"Timeout for command execution"`
|
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"`
|
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)"`
|
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"`
|
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"`
|
TwitchClient string `flag:"twitch-client" default:"" description:"Client ID to act as"`
|
||||||
|
|
Loading…
Reference in a new issue