github.com/n00py/Slackor@v0.0.0-20200610224921-d007fcea1740/pkg/common/sleep.go (about)

     1  package common
     2  
     3  import (
     4  	"errors"
     5  	"strconv"
     6  	"time"
     7  
     8  	"github.com/n00py/Slackor/pkg/command"
     9  )
    10  
    11  // Sleep pauses for N seconds
    12  type Sleep struct{}
    13  
    14  // Name is the name of the command
    15  func (s Sleep) Name() string {
    16  	return "sleep"
    17  }
    18  
    19  // Run pauses for N seconds
    20  func (s Sleep) Run(clientID string, jobID string, args []string) (string, error) {
    21  	if len(args) != 1 {
    22  		return "", errors.New("sleep takes 1 argument")
    23  	}
    24  	sleeptime, _ := strconv.Atoi(args[0])
    25  	time.Sleep(time.Duration(sleeptime) * time.Second)
    26  	return "", nil
    27  }
    28  
    29  func init() {
    30  	command.RegisterCommand(Sleep{})
    31  }