| 93 | } |
| 94 | |
| 95 | func startBreakTimer(timerInMinutes string, configuration config.Configuration) error { |
| 96 | err, timeoutInMinutes := toMinutes(timerInMinutes) |
| 97 | if err != nil { |
| 98 | return err |
| 99 | } |
| 100 | |
| 101 | timeoutInSeconds := timeoutInMinutes * 60 |
| 102 | timeOfTimeout := time.Now().Add(time.Minute * time.Duration(timeoutInMinutes)).Format("15:04") |
| 103 | say.Debug(fmt.Sprintf("Starting break timer at %s for %d minutes = %d seconds (parsed from user input %s)", timeOfTimeout, timeoutInMinutes, timeoutInSeconds, timerInMinutes)) |
| 104 | |
| 105 | room := getMobTimerRoom(configuration) |
| 106 | startRemoteTimer := room != "" |
| 107 | startLocalTimer := configuration.TimerLocal |
| 108 | |
| 109 | if !startRemoteTimer && !startLocalTimer { |
| 110 | say.Error("No break timer configured, not starting break timer") |
| 111 | Exit(1) |
| 112 | } |
| 113 | |
| 114 | if startRemoteTimer { |
| 115 | timerUser := getUserForMobTimer(configuration.TimerUser) |
| 116 | err := httpPutBreakTimer(timeoutInMinutes, room, timerUser, configuration.TimerUrl, configuration.TimerInsecure) |
| 117 | |
| 118 | if err != nil { |
| 119 | say.Error("remote break timer couldn't be started") |
| 120 | say.Error(err.Error()) |
| 121 | Exit(1) |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | if startLocalTimer { |
| 126 | err := executeCommandsInBackgroundProcess(getSleepCommand(timeoutInSeconds), getVoiceCommand("mob start", configuration.VoiceCommand), getNotifyCommand("mob start", configuration.NotifyCommand), "echo \"mobTimer\"") |
| 127 | |
| 128 | if err != nil { |
| 129 | say.Error(fmt.Sprintf("break timer couldn't be started on your system (%s)", runtime.GOOS)) |
| 130 | say.Error(err.Error()) |
| 131 | Exit(1) |
| 132 | } |
| 133 | } |
| 134 | |
| 135 | say.Info("It's now " + currentTime() + ". " + fmt.Sprintf("%d min break timer ends at approx. %s", timeoutInMinutes, timeOfTimeout) + ". So take a break now! :)") |
| 136 | return nil |
| 137 | } |
| 138 | |
| 139 | func getUserForMobTimer(userOverride string) string { |
| 140 | if userOverride == "" { |