Code: Select all
#SingleInstance, Force
#Persistent
#NoEnv
SetWorkingDir %A_ScriptDir%
SetBatchLines -1
Gui Font, s9, Segoe UI
Gui Add, CheckBox, x91 y92 w120 h23 , Ativar
Gui Add, DropDownList, x90 y54 w120 vname ggot, char1||char2||char3||char4||char5||
Gui Add, Text, x16 y7 w120 h23 +0x2000, Lider
Gui Show, w299 h173, Window
SetTimer, ParseChatLog, 1 ;// 3 seconds
return
got:
MyChatID = GetChatID("name") ;// The name assigned to the channel
return
GetChatID(Channel) { ;// Get the unique chat_id value using the channel name
HttpRequest := ComObjCreate("WinHttp.WinHttpRequest.5.1")
HttpRequest.Open("GET", "https://tlk.io/" Channel, true)
HttpRequest.Send()
HttpRequest.WaitForResponse()
RegExMatch(HttpRequest.ResponseText, "chat_id\s=\s'(\d+)';", ChatID)
return ChatID1
}
GetChatLog(ChatID) { ;// Get the JSON data returned from the API URL
HttpRequest := ComObjCreate("WinHttp.WinHttpRequest.5.1")
HttpRequest.Open("GET", "https://tlk.io/api/chats/" ChatID "/messages", true)
HttpRequest.Send()
HttpRequest.WaitForResponse()
return HttpRequest.ResponseText
}
ParseChatLog() { ;// Parse the JSON data
Global MyChatID
Static LastID
MyChatLog := GetChatLog(MyChatID) ;// Get the JSON data
ChatLog := [{}] ;// Create an array containing an object
Pos := 1, Match := ""
While (Pos := RegExMatch(MyChatLog, "({.*?})", Match, Pos + StrLen(Match))) {
RegExMatch(Match1, """id"":(\d+),", id)
RegExMatch(Match1, """user_token"":""(.*?)"",", user_token)
RegExMatch(Match1, """nickname"":""(.*?)"",", nickname)
RegExMatch(Match1, """body"":""(.*?)"",", body)
RegExMatch(Match1, """user"":{(.*?)},", user)
RegExMatch(user1, """token"":""(.*?)"",", u_token)
RegExMatch(user1, """nickname"":""(.*?)"",", u_nickname)
RegExMatch(user1, """provider"":""(.*?)"",", u_provider)
RegExMatch(user1, """avatar"":""(.*?)"",", u_avatar)
RegExMatch(user1, """profile_url"":""(.*?)""}", u_profile_url)
RegExMatch(Match1, """timestamp"":(\d+),", timestamp)
RegExMatch(Match1, """closest_milestone"":(\d+),", closest_milestone)
RegExMatch(Match1, """deleted"":(.*?)}", deleted)
;// Assign parsed items to the array
ChatLog[A_Index] := {"id": id1
,"user_token": user_token1
,"nickname": nickname1
,"body": body1
,"u_token": u_token1
,"u_nickname": u_nickname1
,"u_provider": u_provider1
,"u_avatar": u_avatar1
,"u_profile_url": u_profile_url1
,"timestamp": timestamp1
,"closest_milestone": closest_milestone1
,"deleted": deleted1}
}
;// Do nothing if no new messages
If (LastID = ChatLog[ChatLog.MaxIndex()].id) {
return
}
;// Store ID of last message to variable
LastID := ChatLog[ChatLog.MaxIndex()].id
;// Execute command based on the message text
ExecuteCommand(ChatLog[ChatLog.MaxIndex()].body)
}
ExecuteCommand(Text) {
If (Text = "MsgBox") { ;// Keyword 1
MsgBox, % Hello World! ;// Display message box
} Else If (Text = "start") { ;// Keyword 2
Send, {f10} ;// Open start menu
} Else If (Text = "Notepad") { ;// Keyword 3
Run, notepad.exe ;// Run notepad
} Else { ;// Other
If (Text = "") {
return ;// Do nothing if no text (messages deleted, etc...)
}
MsgBox, % Text ;// Show text if not matching defined keywords
}
}