コード例 #1
0
ファイル: commands.go プロジェクト: gistia/slackbot
func TimerStatus(bot *UserBot, cmd utils.Command) error {
	name := cmd.Arg(0)
	if name == "" {
		return errors.New("Missing timer name")
	}
	timer, err := db.GetTimerByName(bot.lastMessage.User.Name, name)
	if err != nil {
		return err
	}
	if timer == nil {
		return errors.New("You have no started timer with name *" + name + "*")
	}

	if timer.IsFinished() {
		bot.reply("Your timer *" + name + "* is finished. It ran for *" + timer.Duration() + "*.")
	} else {
		bot.reply("Your timer *" + name + "* has been running for *" + timer.Duration() + "*")
	}
	return nil
}
コード例 #2
0
ファイル: commands.go プロジェクト: gistia/slackbot
func claimTimer(bot *UserBot, cmd utils.Command) error {
	timerName := cmd.Arg(0)
	if timerName == "" {
		return errors.New("Missing timer. Usage: `claim <timer-name> <pivotal-task-id>`")
	}

	taskID := cmd.Arg(1)
	if taskID == "" {
		return errors.New("Missing task id. Usage: `claim <timer-name> <pivotal-task-id>`")
	}

	username := bot.lastMessage.User.Name
	timer, err := db.GetTimerByName(username, timerName)
	if err != nil {
		return err
	}
	if timer == nil {
		return errors.New("You have no timer with name *" + timerName + "*")
	}

	err = timer.Stop()
	if err != nil {
		return err
	}
	bot.reply("Timer *" + timer.Name + "* stopped.")

	pvt, err := pivotal.NewFor(username)
	if err != nil {
		return err
	}

	mvn, err := mavenlink.NewFor(username)
	if err != nil {
		return err
	}

	task, err := pvt.GetStory(taskID)
	if err != nil {
		return err
	}

	mvnID := task.GetMavenlinkId()
	if mvnID == "" {
		return errors.New("Can't claim because the Pivotal task doesn't have a mavenlink tag like `[mvn:<id>]`")
	}

	story, err := mvn.GetStory(mvnID)
	if err != nil {
		return err
	}

	_, err = mvn.AddTimeEntry(story, timer.Minutes())
	if err != nil {
		return err
	}

	bot.reply(fmt.Sprintf("Added *%d* minutes to story *%s - %s*",
		timer.Minutes(), story.Id, story.Title))

	return nil
}