Advertisement
Rakurai

Random Breaks for AutoIt Script

Jul 21st, 2012
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AutoIt 4.21 KB | None | 0 0
  1. ; *******************************************************************************
  2. ; USER SETTINGS
  3.  
  4. Local $enableShortBreaks        = True  ; true if the bot should take short breaks
  5. Local $shortBreakFrequencyMin   = 30    ; minimum time between short breaks
  6. Local $shortBreakFrequencyMax   = 45    ; maximum time between short breaks
  7. Local $shortBreakLengthMin      = 5     ; minimum length of short breaks
  8. Local $shortBreakLengthMax      = 10    ; maximum length of short breaks
  9.  
  10. Local $enableLongBreaks         = True  ; true if the bot should take long breaks
  11. Local $longBreakFrequencyMin    = 3     ; minimum time between long breaks
  12. Local $longBreakFrequencyMax    = 5     ; maximum time between long breaks
  13. Local $longBreakLengthMin       = 2     ; minimum length of long breaks
  14. Local $longBreakLengthMax       = 3     ; maximum length of long breaks
  15.  
  16. Local $enableRunningTooltip     = False ; display a tooltip when running
  17. Local $enablePausedTooltip      = True  ; display a tooltip when taking a break
  18.  
  19. Local $BotUnPauseKey            = "{PAUSE}"     ; UNpause the bot script, must be implemented in bot (can be same as pause key)
  20. Local $BotSafePauseKey          = "-"       ; set the SafePause setting in the bot, must be implemented in bot
  21. Local $ScriptStopKey            = "{F11}"   ; stop THIS script
  22.  
  23. ; END USER SETTINGS
  24. ; *******************************************************************************
  25.  
  26. HotKeySet($ScriptStopKey, "Stop")
  27.  
  28. Local $nextShortBreak   = Call("RandomShortBreak")
  29. Local $nextLongBreak    = Call("RandomLongBreak")
  30. Local $minutesSinceShortBreak = 0
  31. Local $minutesSinceLongBreak = 0
  32.  
  33. Local $screenSize = WinGetClientSize("[CLASS:D3 Main Window Class]")
  34. Local $tooltipX = $screenSize[0] - 100
  35. Local $tooltipY = 0
  36.  
  37. ; Main Loop
  38. While True
  39.     If $enableRunningTooltip Then
  40.         Local $str = "Random Break Bot"
  41.         If $enableShortBreaks Then
  42.             $str = StringFormat("%s\nSinceShort:   %d\nNextShort:    %d", $str, $minutesSinceShortBreak, $nextShortBreak)
  43.         EndIf
  44.        
  45.         If $enableLongBreaks Then
  46.             $str = StringFormat("%s\nSinceLong:    %d\nNextLong:     %d", $str, $minutesSinceLongBreak, $nextLongBreak)
  47.         EndIf
  48.  
  49.         ToolTip($str, $tooltipX, $tooltipY)
  50.     EndIf
  51.  
  52.     If $enableLongBreaks And $minutesSinceLongBreak >= $nextLongBreak Then
  53.         Call("TakeLongBreak")
  54.         $nextLongBreak = Call("RandomLongBreak")
  55.         $minutesSinceLongBreak = 0
  56.         $minutesSinceShortBreak = 0 ; also reset
  57.     EndIf
  58.  
  59.     If $enableShortBreaks And $minutesSinceShortBreak >= $nextShortBreak Then
  60.         Local $breakTime = Call("TakeShortBreak")
  61.         $nextShortBreak = Call("RandomShortBreak")
  62.         $minutesSinceShortBreak = 0
  63.  
  64.         If $enableLongBreaks Then
  65.             $minutesSinceLongBreak = $minutesSinceLongBreak + $breakTime
  66.  
  67.             ; If we've scheduled a short break that will overlap with the next long break,
  68.             ; push it off so the long break will happen first.
  69.             If $nextShortBreak + $shortBreakLengthMax >= $nextLongBreak - $minutesSinceLongBreak Then
  70.                 $nextShortBreak = $nextLongBreak
  71.             EndIf
  72.         EndIf
  73.     EndIf
  74.  
  75.     Sleep(60000) ; 1 minute
  76.     $minutesSinceShortBreak = $minutesSinceShortBreak + 1
  77.     $minutesSinceLongBreak = $minutesSinceLongBreak + 1
  78. WEnd
  79.  
  80. Func TakeShortBreak()
  81.     Return TakeBreak("short", Random($shortBreakLengthMin, $shortBreakLengthMax, 1))
  82. EndFunc
  83.  
  84. Func TakeLongBreak()
  85.     Return TakeBreak("long", Random($longBreakLengthMin, $longBreakLengthMax, 1))
  86. EndFunc
  87.  
  88. Func TakeBreak($type, $time)
  89.     Send($BotSafePauseKey)
  90.    
  91.     For $i = 1 To $time
  92.         If $enablePausedTooltip Then
  93.             Tooltip(StringFormat("Random Break Bot\nTaking a %s break for %d more minutes.", $type, ($time - $i) + 1), $tooltipX, $tooltipY)
  94.         EndIf
  95.  
  96.         Sleep(60000) ; 1 minute
  97.     Next
  98.  
  99.     Send($BotUnPauseKey)
  100.  
  101.     Return $time
  102. EndFunc
  103.  
  104. Func RandomShortBreak()
  105.     Return Random($shortBreakFrequencyMin, $shortBreakFrequencyMax, 1)
  106. EndFunc
  107.  
  108. Func RandomLongBreak()
  109.     Return Random($longBreakFrequencyMin, $longBreakFrequencyMax, 1)
  110. EndFunc
  111.  
  112. ; Catch the interrupt, stop the script
  113. Func Stop()
  114.     Exit
  115. EndFunc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement