twitch-bot/action_timeout.go

38 lines
701 B
Go
Raw Permalink Normal View History

2020-12-21 00:32:39 +00:00
package main
import (
"fmt"
"time"
"github.com/go-irc/irc"
"github.com/pkg/errors"
)
func init() {
registerAction(func() Actor { return &ActorTimeout{} })
}
2020-12-21 00:32:39 +00:00
type ActorTimeout struct {
Timeout *time.Duration `json:"timeout" yaml:"timeout"`
2020-12-21 00:32:39 +00:00
}
func (a ActorTimeout) Execute(c *irc.Client, m *irc.Message, r *Rule) error {
if a.Timeout == nil {
return nil
}
return errors.Wrap(
c.WriteMessage(&irc.Message{
Command: "PRIVMSG",
Params: []string{
m.Params[0],
fmt.Sprintf("/timeout %s %d", m.User, *a.Timeout/time.Second),
},
}),
"sending timeout",
)
}
func (a ActorTimeout) IsAsync() bool { return false }
func (a ActorTimeout) Name() string { return "timeout" }