refactor code
much better handling of commands, but still needs some improvement
This commit is contained in:
parent
c11053c3c3
commit
2fcdf6fd3b
139
flag.ahk
139
flag.ahk
@ -1,28 +1,13 @@
|
||||
; AutoHotkey.exe C:\Users\Leand.000\Documents\D3K\flag.ahk [Script Parameters]
|
||||
|
||||
#SingleInstance force ; Only one instance at a time
|
||||
FileEncoding, UTF-8 ; Makes sure special characters dont break stuff
|
||||
global whr := ComObjCreate("WinHttp.WinHttpRequest.5.1")
|
||||
|
||||
|
||||
global userID := "<user ID from the control software>"
|
||||
global userID := "user ID from control software"
|
||||
|
||||
|
||||
func := A_Args[1]
|
||||
col := A_Args[2]
|
||||
Switch A_Args[3]
|
||||
If (A_Args.Length() < 3)
|
||||
{
|
||||
Case "hold":
|
||||
length := 10000
|
||||
Case A_Args[3] is number:
|
||||
length := A_Args[3]
|
||||
Default:
|
||||
length := 0
|
||||
}
|
||||
|
||||
If (A_Args.Length() < 2)
|
||||
{
|
||||
If (func = "off")
|
||||
If (A_Args[1] = "off")
|
||||
{
|
||||
off()
|
||||
} Else {
|
||||
@ -31,19 +16,30 @@ If (A_Args.Length() < 2)
|
||||
ExitApp
|
||||
}
|
||||
|
||||
Switch func
|
||||
Switch A_Args[3]
|
||||
{
|
||||
Case "s":
|
||||
solid(col, length)
|
||||
Case "b":
|
||||
blink(col, length)
|
||||
Case "p":
|
||||
patt(col, length)
|
||||
Case A_Args[3] is number:
|
||||
length := A_Args[3]
|
||||
Case "hold":
|
||||
length := 100000
|
||||
Default:
|
||||
MsgBox,, Flag, % "Incorrect parameters passed to script: " func ", " col ", " length
|
||||
length := 0
|
||||
}
|
||||
|
||||
solid(input, length := 0)
|
||||
Switch A_Args[1]
|
||||
{
|
||||
Case "s":
|
||||
solid(A_Args[2], length)
|
||||
Case "b":
|
||||
blink(A_Args[2], length)
|
||||
Case "p":
|
||||
patt(A_Args[2], length)
|
||||
Default:
|
||||
MsgBox,, Flag, % "Incorrect parameters passed to script: " A_Args[1] ", " A_Args[2] ", " length
|
||||
}
|
||||
|
||||
|
||||
solid(input, length)
|
||||
{
|
||||
Switch input
|
||||
{
|
||||
@ -69,7 +65,7 @@ solid(input, length := 0)
|
||||
}
|
||||
)
|
||||
}
|
||||
req("https://api.luxafor.com/webhook/v1/actions/solid_color", json_str, length)
|
||||
translate("https://api.luxafor.com/webhook/v1/actions/solid_color", json_str, length)
|
||||
}
|
||||
|
||||
blink(input, length)
|
||||
@ -77,69 +73,81 @@ blink(input, length)
|
||||
Switch input
|
||||
{
|
||||
Case "red", "green", "yellow", "blue", "white", "cyan", "magenta":
|
||||
color := input
|
||||
Default:
|
||||
MsgBox % input " is not an accepted input"
|
||||
ExitApp
|
||||
}
|
||||
json_str =
|
||||
(
|
||||
{
|
||||
"userId": "%userID%",
|
||||
"actionFields":{
|
||||
"color": "%input%"
|
||||
"color": "%color%"
|
||||
}
|
||||
}
|
||||
)
|
||||
req("https://api.luxafor.com/webhook/v1/actions/blink", json_str, length)
|
||||
Default:
|
||||
MsgBox % input " is not an accepted input"
|
||||
}
|
||||
translate("https://api.luxafor.com/webhook/v1/actions/blink", json_str, length)
|
||||
}
|
||||
|
||||
patt(input, length)
|
||||
{
|
||||
Switch input
|
||||
{
|
||||
Case "police", "traffic_lights", "random1", "random2", "random3", "random4", "random5":
|
||||
Case "police", "rainbow", "sea", "synthetic":
|
||||
pattern := input
|
||||
Case "traffic_lights":
|
||||
pattern := "traffic lights"
|
||||
Case "white_wave":
|
||||
pattern := "white wave"
|
||||
Case "random":
|
||||
Random, rando, 1, 5
|
||||
pattern := "random %rando%"
|
||||
Case "random1":
|
||||
pattern := "random 1"
|
||||
Case "random2":
|
||||
pattern := "random 2"
|
||||
Case "random3":
|
||||
pattern := "random 3"
|
||||
Case "random4":
|
||||
pattern := "random 4"
|
||||
Case "random5":
|
||||
pattern := "random 5"
|
||||
Default:
|
||||
MsgBox % input " is not an accepted input"
|
||||
ExitApp
|
||||
}
|
||||
json_str =
|
||||
(
|
||||
{
|
||||
"userId": "%userID%",
|
||||
"actionFields":{
|
||||
"pattern": "%input%"
|
||||
"pattern": "%pattern%"
|
||||
}
|
||||
}
|
||||
)
|
||||
req("https://api.luxafor.com/webhook/v1/actions/pattern", json_str, length)
|
||||
Default:
|
||||
MsgBox % input " is not an accepted input"
|
||||
}
|
||||
translate("https://api.luxafor.com/webhook/v1/actions/pattern", json_str, length)
|
||||
}
|
||||
|
||||
req(url, data, len := 0)
|
||||
translate(url, data, length)
|
||||
{
|
||||
If (InStr(url, "solid"))
|
||||
If (length = 0)
|
||||
{
|
||||
If (len = 0)
|
||||
{
|
||||
whr.Open("POST", url, false)
|
||||
whr.SetRequestHeader("Content-Type", "application/json")
|
||||
whr.Send(data)
|
||||
} Else {
|
||||
whr.Open("POST", url, false)
|
||||
whr.SetRequestHeader("Content-Type", "application/json")
|
||||
whr.Send(data)
|
||||
Sleep, (len * 1000)
|
||||
off()
|
||||
}
|
||||
req(url, data)
|
||||
} Else {
|
||||
start_time := A_TickCount
|
||||
time_to_run := len * 1000
|
||||
time_to_run := length * 1000
|
||||
end_time := start_time + time_to_run
|
||||
while (A_tickcount < end_time) {
|
||||
whr.Open("POST", url, false)
|
||||
whr.SetRequestHeader("Content-Type", "application/json")
|
||||
whr.Send(data)
|
||||
whr.WaitForResponse()
|
||||
req(url, data)
|
||||
}
|
||||
}
|
||||
|
||||
If (InStr(url, "solid"))
|
||||
{
|
||||
Sleep, (length * 1000)
|
||||
off()
|
||||
}
|
||||
}
|
||||
|
||||
off()
|
||||
@ -154,9 +162,18 @@ off()
|
||||
}
|
||||
}
|
||||
)
|
||||
whr.Open("POST", "https://api.luxafor.com/webhook/v1/actions/solid_color", false)
|
||||
whr.SetRequestHeader("Content-Type", "application/json")
|
||||
whr.Send(data)
|
||||
url := "https://api.luxafor.com/webhook/v1/actions/solid_color"
|
||||
req(url, data)
|
||||
}
|
||||
|
||||
req(url, data)
|
||||
{
|
||||
whr := ComObjCreate("WinHttp.WinHttpRequest.5.1")
|
||||
whr.Open("POST", url, false)
|
||||
whr.SetRequestHeader("Content-Type", "application/json")
|
||||
whr.Send(data)
|
||||
whr.WaitForResponse()
|
||||
}
|
||||
|
||||
|
||||
ExitApp
|
Loading…
Reference in New Issue
Block a user