Twitch 2 Core Commands

; THIS SCRIPT GETS CHATTY LOG FILE AND PUTS RAW CHAT STRING INTO CORE
; THE ACCOMPANYING LUA (CORE) SCRIPT: https://www.luasnippets.com/code-snippets/core-twitch-commands/
#NoEnv
#Persistent
commands := [["!airdrop",6],["!ban",7],["!heal",8],["!kick",9],["!melee",0],["!nextmap",66],["!pay",67],["!troops",68],["!weather",69]]

;NP := "D:\Users\togag\.chatty\logs\#tmwtv.log" ; the log file to read
NP := "D:\Users\togag\.chatty\logs\#meeklo.log" ; the log file to read
LastGrabbed := "start"
settimer, refresh, 2320
return

; need to read last line and send it to our app
refresh:
FileRead, MyText, %NP% ; load-in the .log file
GrabbedText := StrTail(2,MyText) ; grab last x lines of text

if (GrabbedText != LastGrabbed)
{
;GuiControl,, MyEdit, % GrabbedText ; send to GUI
    if WinExist("Core")
    {       
       ; remove special chars to send into Core 
        ;str := RegexReplace(testVar, "[@\{\}$\^%\-+=_;\`<>()\[\]:\*|\\/]", "") ;all working        
        ;str := RegexReplace(GrabbedText, "[@\{\}$\^%\-+=;\`<>\[\]:\*|\\/]", "")        

        ; look through our commands for a match (send to Core if found)
        ; Iterate from 1 to the end of the array:        
        Loop, % commands.Length()
        {
            ;MsgBox % commands[A_Index][1]            
            Haystack := GrabbedText
            Needle := commands[A_Index][1]
            If InStr(Haystack, Needle)
            {
                WinActivate ; use the window found above                
                ; start (_) 5-9,0 (+) end
                ; clear var and add-in the digits, (end operator runs command)                
                Send {F9}
                SendRaw % commands[A_Index][2]
                Send {F10}                
                break
            }
        }
   }
}
LastGrabbed := GrabbedText ; record old comparison
return


;Return the last (k) lines of (str)
StrTail(k,str) ;; Inspired by Laszlo (http://www.autohotkey.com/forum/topic6928.html)
   {
   Loop,Parse,str,`n
      {
      i := Mod(A_Index,k)
      L%i% = %A_LoopField%
      }
   L := L%i%
   Loop,% k-1
      {
      If i < 1
         SetEnv,i,%k%
      i-- ;Mod does not work here
      L := L%i% "`n" L
      }
   Return L
   }

Latest Posts