Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; *******************************************************************************
- ; USER SETTINGS
- Local $enableShortBreaks = True ; true if the bot should take short breaks
- Local $shortBreakFrequencyMin = 30 ; minimum time between short breaks
- Local $shortBreakFrequencyMax = 45 ; maximum time between short breaks
- Local $shortBreakLengthMin = 5 ; minimum length of short breaks
- Local $shortBreakLengthMax = 10 ; maximum length of short breaks
- Local $enableLongBreaks = True ; true if the bot should take long breaks
- Local $longBreakFrequencyMin = 180 ; minimum time between long breaks
- Local $longBreakFrequencyMax = 300 ; maximum time between long breaks
- Local $longBreakLengthMin = 45 ; minimum length of long breaks
- Local $longBreakLengthMax = 90 ; maximum length of long breaks
- Local $enableGUI = True ; Display a GUI over all windows?
- Local $enableLogging = True ; Write breaks taken to a log file?
- Local $logfile = "breaklog.txt" ; will be created if it doesn't exist
- Local $BotUnPauseKey = "{PAUSE}" ; UNpause the bot script, must be implemented in bot (can be same as pause key)
- Local $BotSafePauseKey = "-" ; set the SafePause setting in the bot, must be implemented in bot
- Local $ScriptStopKey = "{F11}" ; stop THIS script
- ; END USER SETTINGS
- ; *******************************************************************************
- #include <WindowsConstants.au3>
- #include <GUIConstantsEx.au3>
- #include <File.au3>
- HotKeySet($ScriptStopKey, "Stop")
- Local $screenSize = WinGetClientSize("[CLASS:D3 Main Window Class]")
- Local $windowSizeX = 130
- Local $windowSizeY = 120
- Local $windowPosX = 0
- Local $windowPosY = $screenSize[1] - $windowSizeY
- Local $textAlignLeft = 10
- Local $textHeight = 13
- Local $textSpacing = 4
- Local $textWidth = $windowSizeX - $textAlignLeft
- Local $textStatusPos = 5
- Local $textSinceShortPos = $textStatusPos + $textHeight + $textSpacing
- Local $textNextShortPos = $textSinceShortPos + $textHeight + $textSpacing
- Local $textSinceLongPos = $textNextShortPos + $textHeight + $textSpacing
- Local $textNextLongPos = $textSinceLongPos + $textHeight + $textSpacing
- Local $window, $lblStatus, $lblSinceShort, $lblNextShort, $lblSinceLong, $lblNextLong
- If $enableGUI Then
- $window = GUICreate("Random Break", $windowSizeX, $windowSizeY, $windowPosX, $windowPosY, -1, BitOR($WS_EX_TOPMOST, $WS_EX_TOOLWINDOW))
- $lblStatus = GUICtrlCreateLabel("Running...", $textAlignLeft, $textStatusPos, $textWidth, $textHeight)
- $lblSinceShort = GUICtrlCreateLabel("", $textAlignLeft, $textSinceShortPos, $textWidth, $textHeight)
- $lblNextShort = GUICtrlCreateLabel("", $textAlignLeft, $textNextShortPos, $textWidth, $textHeight)
- $lblSinceLong = GUICtrlCreateLabel("", $textAlignLeft, $textSinceLongPos, $textWidth, $textHeight)
- $lblNextLong = GUICtrlCreateLabel("", $textAlignLeft, $textNextLongPos, $textWidth, $textHeight)
- Opt("GUIOnEventMode", 1)
- GUISetOnEvent($GUI_EVENT_CLOSE, "Stop")
- GUISetState()
- EndIf
- Local $nextShort, $nextLong, $sinceShort, $sinceLong
- SetSinceShort(0)
- SetSinceLong(0)
- SetNextShort(RandomShort())
- SetNextLong(RandomLong())
- AppendLog("Starting Random Break Script...")
- ; Main Loop
- While True
- If $enableLongBreaks And $sinceLong >= $nextLong Then
- TakeLongBreak()
- SetNextLong(RandomLong())
- SetNextShort(RandomShort())
- SetSinceLong(0)
- SetSinceShort(0) ; also reset
- EndIf
- If $enableShortBreaks And $sinceShort >= $nextShort Then
- Local $breakTime = TakeShortBreak()
- SetNextShort(RandomShort())
- SetSinceShort(0)
- If $enableLongBreaks Then
- SetSinceLong($sinceLong + $breakTime)
- ; If we've scheduled a short break that will overlap with the next long break,
- ; push it off so the long break will happen first.
- If $nextShort + $shortBreakLengthMax >= $nextLong - $sinceLong Then
- SetNextShort($nextLong)
- EndIf
- EndIf
- EndIf
- Sleep(60000) ; 1 minute
- SetSinceShort($sinceShort + 1)
- SetSinceLong($sinceLong + 1)
- WEnd
- Func SetSinceShort($time)
- $sinceShort = $time
- SetGUILabel($lblSinceShort, FormatLabel("SinceShort:", $enableShortBreaks, $time))
- EndFunc
- Func SetSinceLong($time)
- $sinceLong = $time
- SetGUILabel($lblSinceLong, FormatLabel("SinceLong: ", $enableLongBreaks, $time))
- EndFunc
- Func SetNextShort($time)
- $nextShort = $time
- SetGUILabel($lblNextShort, FormatLabel("NextShort: ", $enableShortBreaks, $time))
- EndFunc
- Func SetNextLong($time)
- $nextLong = $time
- SetGUILabel($lblNextLong, FormatLabel("NextLong: ", $enableLongBreaks, $time))
- EndFunc
- Func SetGUILabel($label, $str)
- If $enableGUI Then
- GUICtrlSetData($label, $str)
- EndIf
- EndFunc
- Func FormatLabel($prefix, $enabled, $time)
- Local $timeStr
- If $enabled Then
- $timeStr = String($time)
- Else
- $timeStr = "disabled"
- EndIf
- Return StringFormat("%s %s", $prefix, $timeStr)
- EndFunc
- Func TakeShortBreak()
- Return TakeBreak("Short", Random($shortBreakLengthMin, $shortBreakLengthMax, 1))
- EndFunc
- Func TakeLongBreak()
- Return TakeBreak("Long", Random($longBreakLengthMin, $longBreakLengthMax, 1))
- EndFunc
- Func TakeBreak($type, $time)
- Send($BotSafePauseKey)
- AppendLog(StringFormat("Taking %s break for %d minutes.", $type, $time))
- For $i = 1 To $time
- SetGUILabel($lblStatus, StringFormat("%s break, %dm more", $type, ($time - $i) + 1))
- Sleep(60000) ; 1 minute
- Next
- Send($BotUnPauseKey)
- SetGUILabel($lblStatus, "Running...")
- Return $time
- EndFunc
- Func RandomShort()
- Return Random($shortBreakFrequencyMin, $shortBreakFrequencyMax, 1)
- EndFunc
- Func RandomLong()
- Return Random($longBreakFrequencyMin, $longBreakFrequencyMax, 1)
- EndFunc
- Func AppendLog($str)
- If $enableLogging Then
- _FileWriteLog($logfile, $str)
- EndIf
- EndFunc
- ; Catch the interrupt, stop the script
- Func Stop()
- AppendLog("Stopping Random Break Script...")
- Exit
- EndFunc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement