View difference between Paste ID: 8LbG2xdQ and CXzDC8zj
SHOW: | | - or go back to the newest paste.
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
11+
Local $longBreakFrequencyMin    = 180     ; minimum time between long breaks
12-
Local $longBreakFrequencyMax    = 5     ; maximum time between long breaks
12+
Local $longBreakFrequencyMax    = 300     ; maximum time between long breaks
13-
Local $longBreakLengthMin       = 2     ; minimum length of long breaks
13+
Local $longBreakLengthMin       = 45     ; minimum length of long breaks
14-
Local $longBreakLengthMax       = 3     ; maximum length of long breaks
14+
Local $longBreakLengthMax       = 90     ; maximum length of long breaks
15
16-
Local $enableRunningTooltip     = False ; display a tooltip when running
16+
Local $enableGUI                = True   ; Display a GUI over all windows?
17-
Local $enablePausedTooltip      = True  ; display a tooltip when taking a break
17+
Local $enableLogging            = True   ; Write breaks taken to a log file?
18
Local $logfile                  = "breaklog.txt" ; will be created if it doesn't exist
19
20
Local $BotUnPauseKey            = "{PAUSE}"     ; UNpause the bot script, must be implemented in bot (can be same as pause key)
21
Local $BotSafePauseKey          = "-"       ; set the SafePause setting in the bot, must be implemented in bot
22
Local $ScriptStopKey            = "{F11}"   ; stop THIS script
23
24
; END USER SETTINGS
25
; *******************************************************************************
26
27
#include <WindowsConstants.au3>
28-
Local $nextShortBreak   = Call("RandomShortBreak")
28+
#include <GUIConstantsEx.au3>
29-
Local $nextLongBreak    = Call("RandomLongBreak")
29+
#include <File.au3>
30-
Local $minutesSinceShortBreak = 0
30+
31-
Local $minutesSinceLongBreak = 0
31+
32
33
Local $screenSize = WinGetClientSize("[CLASS:D3 Main Window Class]")
34-
Local $tooltipX = $screenSize[0] - 100
34+
35-
Local $tooltipY = 0
35+
Local $windowSizeX      = 130
36
Local $windowSizeY      = 120
37
Local $windowPosX       = 0
38
Local $windowPosY       = $screenSize[1] - $windowSizeY
39-
    If $enableRunningTooltip Then
39+
Local $textAlignLeft    = 10
40-
        Local $str = "Random Break Bot"
40+
Local $textHeight       = 13
41-
        If $enableShortBreaks Then
41+
Local $textSpacing      = 4
42-
            $str = StringFormat("%s\nSinceShort:   %d\nNextShort:    %d", $str, $minutesSinceShortBreak, $nextShortBreak)
42+
Local $textWidth        = $windowSizeX - $textAlignLeft
43
Local $textStatusPos    = 5
44-
        
44+
Local $textSinceShortPos = $textStatusPos + $textHeight + $textSpacing
45
Local $textNextShortPos  = $textSinceShortPos + $textHeight + $textSpacing
46-
            $str = StringFormat("%s\nSinceLong:    %d\nNextLong:     %d", $str, $minutesSinceLongBreak, $nextLongBreak)
46+
Local $textSinceLongPos  = $textNextShortPos + $textHeight + $textSpacing
47
Local $textNextLongPos   = $textSinceLongPos + $textHeight + $textSpacing
48
49-
        ToolTip($str, $tooltipX, $tooltipY)
49+
Local $window, $lblStatus, $lblSinceShort, $lblNextShort, $lblSinceLong, $lblNextLong
50
51
If $enableGUI Then
52-
    If $enableLongBreaks And $minutesSinceLongBreak >= $nextLongBreak Then
52+
    $window = GUICreate("Random Break", $windowSizeX, $windowSizeY, $windowPosX, $windowPosY, -1, BitOR($WS_EX_TOPMOST, $WS_EX_TOOLWINDOW))
53-
        Call("TakeLongBreak")
53+
    $lblStatus     = GUICtrlCreateLabel("Running...", $textAlignLeft, $textStatusPos, $textWidth, $textHeight)
54-
        $nextLongBreak = Call("RandomLongBreak")
54+
    $lblSinceShort = GUICtrlCreateLabel("", $textAlignLeft, $textSinceShortPos, $textWidth, $textHeight)
55-
        $minutesSinceLongBreak = 0
55+
    $lblNextShort  = GUICtrlCreateLabel("", $textAlignLeft, $textNextShortPos, $textWidth, $textHeight)
56-
        $minutesSinceShortBreak = 0 ; also reset
56+
    $lblSinceLong  = GUICtrlCreateLabel("", $textAlignLeft, $textSinceLongPos, $textWidth, $textHeight)
57
    $lblNextLong   = GUICtrlCreateLabel("", $textAlignLeft, $textNextLongPos, $textWidth, $textHeight)
58
    Opt("GUIOnEventMode", 1)
59-
    If $enableShortBreaks And $minutesSinceShortBreak >= $nextShortBreak Then
59+
    GUISetOnEvent($GUI_EVENT_CLOSE, "Stop")
60-
        Local $breakTime = Call("TakeShortBreak")
60+
    GUISetState()
61-
        $nextShortBreak = Call("RandomShortBreak")
61+
EndIf
62-
        $minutesSinceShortBreak = 0
62+
63
Local $nextShort, $nextLong, $sinceShort, $sinceLong
64
SetSinceShort(0)
65-
            $minutesSinceLongBreak = $minutesSinceLongBreak + $breakTime
65+
SetSinceLong(0)
66
SetNextShort(RandomShort())
67
SetNextLong(RandomLong())
68
69-
            If $nextShortBreak + $shortBreakLengthMax >= $nextLongBreak - $minutesSinceLongBreak Then
69+
AppendLog("Starting Random Break Script...")
70-
                $nextShortBreak = $nextLongBreak
70+
71
; Main Loop
72
While True
73
    If $enableLongBreaks And $sinceLong >= $nextLong Then
74
        TakeLongBreak()
75
        SetNextLong(RandomLong())
76-
    $minutesSinceShortBreak = $minutesSinceShortBreak + 1
76+
        SetNextShort(RandomShort())
77-
    $minutesSinceLongBreak = $minutesSinceLongBreak + 1
77+
        SetSinceLong(0)
78
        SetSinceShort(0) ; also reset
79
    EndIf
80
81-
    Return TakeBreak("short", Random($shortBreakLengthMin, $shortBreakLengthMax, 1))
81+
    If $enableShortBreaks And $sinceShort >= $nextShort Then
82
        Local $breakTime = TakeShortBreak()
83
        SetNextShort(RandomShort())
84
        SetSinceShort(0)
85-
    Return TakeBreak("long", Random($longBreakLengthMin, $longBreakLengthMax, 1))
85+
86
        If $enableLongBreaks Then
87
            SetSinceLong($sinceLong + $breakTime)
88
89
            ; If we've scheduled a short break that will overlap with the next long break,
90
            ; push it off so the long break will happen first.
91
            If $nextShort + $shortBreakLengthMax >= $nextLong - $sinceLong Then
92-
        If $enablePausedTooltip Then
92+
                SetNextShort($nextLong)
93-
            Tooltip(StringFormat("Random Break Bot\nTaking a %s break for %d more minutes.", $type, ($time - $i) + 1), $tooltipX, $tooltipY)
93+
94
        EndIf
95
    EndIf
96
97
    Sleep(60000) ; 1 minute
98
    SetSinceShort($sinceShort + 1)
99
    SetSinceLong($sinceLong + 1)
100
WEnd
101
102
Func SetSinceShort($time)
103
    $sinceShort = $time
104-
Func RandomShortBreak()
104+
    SetGUILabel($lblSinceShort, FormatLabel("SinceShort:", $enableShortBreaks, $time))
105
EndFunc
106
107
Func SetSinceLong($time)
108-
Func RandomLongBreak()
108+
    $sinceLong = $time
109
    SetGUILabel($lblSinceLong, FormatLabel("SinceLong: ", $enableLongBreaks, $time))
110
EndFunc
111
112
Func SetNextShort($time)
113
    $nextShort = $time
114
    SetGUILabel($lblNextShort, FormatLabel("NextShort: ", $enableShortBreaks, $time))
115
EndFunc
116
117
Func SetNextLong($time)
118
    $nextLong = $time
119
    SetGUILabel($lblNextLong, FormatLabel("NextLong:  ", $enableLongBreaks, $time))
120
EndFunc
121
122
Func SetGUILabel($label, $str)
123
    If $enableGUI Then
124
        GUICtrlSetData($label, $str)
125
    EndIf
126
EndFunc
127
128
Func FormatLabel($prefix, $enabled, $time)
129
    Local $timeStr
130
    
131
    If $enabled Then
132
        $timeStr = String($time)
133
    Else
134
        $timeStr = "disabled"
135
    EndIf
136
137
    Return StringFormat("%s   %s", $prefix, $timeStr)
138
EndFunc
139
140
Func TakeShortBreak()
141
    Return TakeBreak("Short", Random($shortBreakLengthMin, $shortBreakLengthMax, 1))
142
EndFunc
143
144
Func TakeLongBreak()
145
    Return TakeBreak("Long", Random($longBreakLengthMin, $longBreakLengthMax, 1))
146
EndFunc
147
148
Func TakeBreak($type, $time)
149
    Send($BotSafePauseKey)
150
    AppendLog(StringFormat("Taking %s break for %d minutes.", $type, $time))
151
152
    For $i = 1 To $time
153
        SetGUILabel($lblStatus, StringFormat("%s break, %dm more", $type, ($time - $i) + 1))
154
        Sleep(60000) ; 1 minute
155
    Next
156
157
    Send($BotUnPauseKey)
158
    SetGUILabel($lblStatus, "Running...")
159
160
    Return $time
161
EndFunc
162
163
Func RandomShort()
164
    Return Random($shortBreakFrequencyMin, $shortBreakFrequencyMax, 1)
165
EndFunc
166
167
Func RandomLong()
168
    Return Random($longBreakFrequencyMin, $longBreakFrequencyMax, 1)
169
EndFunc
170
171
Func AppendLog($str)
172
    If $enableLogging Then
173
        _FileWriteLog($logfile, $str)
174
    EndIf
175
EndFunc
176
177
; Catch the interrupt, stop the script
178
Func Stop()
179
    AppendLog("Stopping Random Break Script...")
180
    Exit
181
EndFunc