Make the deadline configurable

This commit is contained in:
2020-01-01 16:18:13 +00:00
parent c31e8d9f51
commit 90dc6edfad
2 changed files with 7 additions and 2 deletions

View File

@@ -22,6 +22,8 @@ type CommandDeadline struct {
Deadline time.Time
}
var Cooldown = 2 * time.Minute // default cooldown is 2 minutes
func NewCommand(next hugot.CommandHandler) hugot.CommandHandler {
return &CommandDeadline{CommandHandler: next, Deadline: time.Now().UTC()}
}
@@ -33,7 +35,7 @@ func NewHears(next hugot.HearsHandler) hugot.HearsHandler {
func (i *HearsDeadline) Heard(ctx context.Context, w hugot.ResponseWriter, m *hugot.Message, matches [][]string) {
now := time.Now().UTC()
if now.After(i.Deadline) {
i.Deadline = now.Add(2 * time.Minute)
i.Deadline = now.Add(Cooldown)
i.HearsHandler.Heard(ctx, w, m, matches)
return
}
@@ -45,7 +47,7 @@ func (i *HearsDeadline) Heard(ctx context.Context, w hugot.ResponseWriter, m *hu
func (i *CommandDeadline) Command(ctx context.Context, w hugot.ResponseWriter, m *hugot.Message) error {
now := time.Now().UTC()
if now.After(i.Deadline) {
i.Deadline = now.Add(2 * time.Minute)
i.Deadline = now.Add(Cooldown)
return i.CommandHandler.Command(ctx, w, m)
}