| 19 | } |
| 20 | |
| 21 | func startTimer(timerInMinutes string, configuration config.Configuration) error { |
| 22 | err, timeoutInMinutes := toMinutes(timerInMinutes) |
| 23 | if err != nil { |
| 24 | return err |
| 25 | } |
| 26 | |
| 27 | timeoutInSeconds := timeoutInMinutes * 60 |
| 28 | timeOfTimeout := time.Now().Add(time.Minute * time.Duration(timeoutInMinutes)).Format("15:04") |
| 29 | say.Debug(fmt.Sprintf("Starting timer at %s for %d minutes = %d seconds (parsed from user input %s)", timeOfTimeout, timeoutInMinutes, timeoutInSeconds, timerInMinutes)) |
| 30 | |
| 31 | room := getMobTimerRoom(configuration) |
| 32 | startRemoteTimer := room != "" |
| 33 | startLocalTimer := configuration.TimerLocal |
| 34 | |
| 35 | if !startRemoteTimer && !startLocalTimer { |
| 36 | say.Error("No timer configured, not starting timer") |
| 37 | Exit(1) |
| 38 | } |
| 39 | |
| 40 | if startRemoteTimer { |
| 41 | timerUser := getUserForMobTimer(configuration.TimerUser) |
| 42 | err := httpPutTimer(timeoutInMinutes, room, timerUser, configuration.TimerUrl, configuration.TimerInsecure) |
| 43 | if err != nil { |
| 44 | say.Error("remote timer couldn't be started") |
| 45 | say.Error(err.Error()) |
| 46 | Exit(1) |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | if startLocalTimer { |
| 51 | err := executeCommandsInBackgroundProcess(getSleepCommand(timeoutInSeconds), getVoiceCommand(configuration.VoiceMessage, configuration.VoiceCommand), getNotifyCommand(configuration.NotifyMessage, configuration.NotifyCommand), "echo \"mobTimer\"") |
| 52 | |
| 53 | if err != nil { |
| 54 | say.Error(fmt.Sprintf("timer couldn't be started on your system (%s)", runtime.GOOS)) |
| 55 | say.Error(err.Error()) |
| 56 | Exit(1) |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | say.Info("It's now " + currentTime() + ". " + fmt.Sprintf("%d min timer ends at approx. %s", timeoutInMinutes, timeOfTimeout) + ". Happy collaborating! :)") |
| 61 | return nil |
| 62 | } |
| 63 | |
| 64 | func getMobTimerRoom(configuration config.Configuration) string { |
| 65 | if !isGit() { |