Twitch 2 Core Commands

; THIS SCRIPT GETS CHATTY LOG FILE AND PUTS RAW CHAT STRING INTO CORE
#NoEnv
#Persistent
commands := [["!start",6],["!reset",7],["!next",8]]


NP := "D:\Users\togag\.chatty\logs\#meeklo.log" ; the log file to read
LastLineCount := 0 ;store last line number to ignore (if not new)
LineCount := 0
settimer, refresh, 2320
return


; need to read last line and send it to our app
refresh:
FileRead, MyText, %NP%

Loop, Parse, MyText, `n, `r ;last line will be blank
LineCount := A_Index

GrabbedText := StrTail(2,MyText) ; grab last x lines of text

if (LineCount != LastLineCount)
{
    ; check for !98 (number/player to follow) - special use case
    ; if 2nd character and beyond is a number between 1 and 100?
    ; <~Meeklo> !89 (everything after "!" should be a number between 1-100)    
    SYM := SubStr(GrabbedText, 11,1) ; should be "!"
    NN := SubStr(GrabbedText, 12) ; rest of the number to compare (1-100)
    LEN := StrLen(NN)
    
    ;If ( (SYM = "!") AND (NN < 101) AND (NN > 0) AND             (LEN) < 6) AND NN > 0 )
    
    if ( (SYM = "!") AND (LEN < 6) AND (NN > 0) )
    
    {
        ;Msgbox, ok
        if WinExist("Core Editor") ; focus Core window if a !command is found.
        {
            WinActivate ; use the window found above
            Click, 600 600
        }
        NN := "0" + NN
        Send {F9}
        SendRaw % NN
        Send {F10}
        WinActivate, #meeklo    
    }
    else
    {
        ; 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)
            {
                if WinExist("Core Editor") ; focus Core window if a !command is found.
                {    
                    WinActivate ; use the window found above
                    Click, 600 600
                }
                ; start (_) 6-9,0 (+) end
                ; clear var and add-in the digits, (end operator runs command)                
                Send {F9}
                SendRaw % commands[A_Index][2]
                Send {F10}
                WinActivate, #meeklo
                break
            }
        }
    }
}
LastLineCount := LineCount ; 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