forked from TLMcode/AHKs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FireflyFeesBot.ahk
148 lines (113 loc) · 4.65 KB
/
FireflyFeesBot.ahk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#include FcnLib.ahk
#include firefly-FcnLib.ahk
#include firefly-Bot-FcnLib.ahk
#singleinstance force
assignGlobals()
bot:=true
;NOTE 2012-05-01 should be the first day where you can see when the bot finished adding fees based on the file modified date. You should be able when Mel stopped adding fees and when the Bot finished adding those fees based on file modified dates
;NOTE 2012-06-16 should be the first date where you have no conflicted copy files for the iniFs (checkins and fee files also). This was when I added the ModMin feature into the iniF lib
if NOT IsVM()
fatalerrord("this macro is only for VMs")
;First things first, write a start message and do the checkin
;addtotrace("Started bot script")
;addtotrace("Started bot script (faint grey line)")
FireflyCheckin("Bot", "Started")
CheckBotHealth()
;roll over and play dead (test the check-ins)
;PlayDead()
iniFolder:=GetPath("FireflyIniFolder")
;if the bot doesn't have any fees to add, then wait for a little bit
if ( GetNumberOfFeesNotYetAdded() == 0 )
{
iniPP("Finished adding fees")
FireflyCheckin("Bot", "Finished adding fees")
ArchiveOldInifParts( GetPath("FireflyIniFolder") )
;TODO this needs to happen on each individual computer, and only if the file hasn't been touched recently
;ArchiveOldInifParts( GetPath("FireflyCheckinIniFolder") )
SleepSeconds(30)
Reload()
}
;i think i did this because I wanted to restart the sucker remotely
;currentlyDebugging := 1
;if currentlyDebugging
;{
;ms := Random(20, 10000)
;Sleep, %ms%
;Run, ForceReloadAll.exe
;SleepMinutes(99)
;ExitApp
;}
;addtotrace("purple line - sending queued emails - triggered by bot")
;addtotrace("sending queued emails - triggered by bot")
Run, SendQueuedEmails.ahk
;addtotrace("faint blue line - restarted the script normally")
RefreshLogin()
FireflyCheckin("Bot", "Finished RefreshLogin")
uiSections := IniFolderListAllSections(iniFolder)
feesJson := GetSimpleFeesJson()
listFees := ListFees()
Loop, parse, uiSections, CSV
{
thisReferenceNumber:=A_LoopField
Loop, parse, listFees, CSV
{
thisFee:=A_LoopField
timerEntire := StartTimer()
;checking if the entire ref num was aborted
if ( FeeLookup(thisReferenceNumber, thisFee) == "ABORTED")
continue
;checking if already added
;addtotrace("checking if fee is already added")
if IsFeeAddedCorrectly(thisReferenceNumber, thisFee)
continue
;go to the correct file
ArrangeWindows()
FireflyCheckin("Bot", "Started OpenReferenceNumber")
;addtotrace("opening ref num " . thisReferenceNumber)
OpenReferenceNumber(thisReferenceNumber)
FireflyCheckin("Bot", "Getting Fees (before)")
; get the file num
;commented to make it run faster
fileNumber := GetFileNumber()
IniFolderWrite(iniFolder, thisReferenceNumber, "FileNumber", fileNumber)
;addtotrace("getting fees " . thisReferenceNumber)
GetFees()
FireflyCheckin("Bot", "Working")
;checking if the entire ref num was aborted
if ( FeeLookup(thisReferenceNumber, thisFee) == "ABORTED")
continue
;checking if already added
;addtotrace("checking if fee is already added")
if IsFeeAddedCorrectly(thisReferenceNumber, thisFee)
continue
FireflyCheckin("Bot", "Working")
;count the number of times that we try to add the fee
thisKey=BotAttemptedToAddFee-%thisFee%
attempts:=IniFolderRead(iniFolder, thisReferenceNumber, thisKey)
if (attempts == "ERROR")
attempts := 0
attempts++
IniFolderWrite(iniFolder, thisReferenceNumber, thisKey, attempts)
FireflyCheckin("Bot", "Working")
;get info for adding the fee
thisKeySubmitted=DesiredFees-%thisFee%
desiredAmount:=IniFolderRead(iniFolder, thisReferenceNumber, "DesiredFees-" . thisFee)
;FASF - Fees Added So Far
tracemsg=Adding Fee: %feesAddedCountSoFar%FASF %thisReferenceNumber% $%desiredAmount% %thisFee% (faint purple line)
addtotrace(traceMsg)
feesAddedCountSoFar++
FireflyCheckin("Bot", "Adding fee")
;add the friggin fee!
AddFees(thisFee, desiredAmount)
IniFolderWrite(iniFolder, thisReferenceNumber, "BotAddedFee-" . thisFee, desiredAmount)
FireflyCheckin("Bot", "Getting fees (after)")
;look to see if the fee was successfully added
GetFees()
FireflyBotEndTimer(timerEntire, "adding fee S-to-F (not a func)", 35, 90)
FireflyCheckin("Bot", "Finished the fee loop")
}
}
Sleep, 1000
KillFirefox()
Reload()
ExitApp