163 lines
2.9 KiB
AutoHotkey
163 lines
2.9 KiB
AutoHotkey
|
; 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>"
|
||
|
|
||
|
|
||
|
func := A_Args[1]
|
||
|
col := A_Args[2]
|
||
|
Switch A_Args[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")
|
||
|
{
|
||
|
off()
|
||
|
} Else {
|
||
|
MsgBox,, Flag, Not enough parameters passed to script
|
||
|
}
|
||
|
ExitApp
|
||
|
}
|
||
|
|
||
|
Switch func
|
||
|
{
|
||
|
Case "s":
|
||
|
solid(col, length)
|
||
|
Case "b":
|
||
|
blink(col, length)
|
||
|
Case "p":
|
||
|
patt(col, length)
|
||
|
Default:
|
||
|
MsgBox,, Flag, % "Incorrect parameters passed to script: " func ", " col ", " length
|
||
|
}
|
||
|
|
||
|
solid(input, length := 0)
|
||
|
{
|
||
|
Switch input
|
||
|
{
|
||
|
Case "red", "green", "yellow", "blue", "white", "cyan", "magenta":
|
||
|
json_str =
|
||
|
(
|
||
|
{
|
||
|
"userId": "%userID%",
|
||
|
"actionFields":{
|
||
|
"color": "%input%"
|
||
|
}
|
||
|
}
|
||
|
)
|
||
|
Default:
|
||
|
json_str =
|
||
|
(
|
||
|
{
|
||
|
"userId": "%userID%",
|
||
|
"actionFields":{
|
||
|
"color": "custom",
|
||
|
"custom_color": "%input%"
|
||
|
}
|
||
|
}
|
||
|
)
|
||
|
}
|
||
|
req("https://api.luxafor.com/webhook/v1/actions/solid_color", json_str, length)
|
||
|
}
|
||
|
|
||
|
blink(input, length)
|
||
|
{
|
||
|
Switch input
|
||
|
{
|
||
|
Case "red", "green", "yellow", "blue", "white", "cyan", "magenta":
|
||
|
json_str =
|
||
|
(
|
||
|
{
|
||
|
"userId": "%userID%",
|
||
|
"actionFields":{
|
||
|
"color": "%input%"
|
||
|
}
|
||
|
}
|
||
|
)
|
||
|
req("https://api.luxafor.com/webhook/v1/actions/blink", json_str, length)
|
||
|
Default:
|
||
|
MsgBox % input " is not an accepted input"
|
||
|
}
|
||
|
}
|
||
|
|
||
|
patt(input, length)
|
||
|
{
|
||
|
Switch input
|
||
|
{
|
||
|
Case "police", "traffic_lights", "random1", "random2", "random3", "random4", "random5":
|
||
|
json_str =
|
||
|
(
|
||
|
{
|
||
|
"userId": "%userID%",
|
||
|
"actionFields":{
|
||
|
"pattern": "%input%"
|
||
|
}
|
||
|
}
|
||
|
)
|
||
|
req("https://api.luxafor.com/webhook/v1/actions/pattern", json_str, length)
|
||
|
Default:
|
||
|
MsgBox % input " is not an accepted input"
|
||
|
}
|
||
|
}
|
||
|
|
||
|
req(url, data, len := 0)
|
||
|
{
|
||
|
If (InStr(url, "solid"))
|
||
|
{
|
||
|
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()
|
||
|
}
|
||
|
} Else {
|
||
|
start_time := A_TickCount
|
||
|
time_to_run := len * 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()
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
off()
|
||
|
{
|
||
|
data =
|
||
|
(
|
||
|
{
|
||
|
"userId": "%userID%",
|
||
|
"actionFields":{
|
||
|
"color": "custom",
|
||
|
"custom_color": "000000"
|
||
|
}
|
||
|
}
|
||
|
)
|
||
|
whr.Open("POST", "https://api.luxafor.com/webhook/v1/actions/solid_color", false)
|
||
|
whr.SetRequestHeader("Content-Type", "application/json")
|
||
|
whr.Send(data)
|
||
|
}
|
||
|
|
||
|
ExitApp
|