Make the deadline configurable
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user