74a501ceeba2dae24e7200d12714dccd

This is for the online poker site Pokerstars, it creates a log file and using it you can determine when you've busted out of a tournament. It searches the file for instances where you've won or lost. Then it takes the HWND of the tournament (it's in the text file as well) and uses AutoItX to close the window. I couldn't figure out how to import the win32api to use sendmessage WM_CLOSE to do it but I suspect there's an easier way.

Also if two windows end up having the same HWND in the log file it will close it even if you're still in the tournament, and it reads the whole file instead of what's just recently been added. Can you tell I'm new to ruby?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
require 'win32ole'
autoit = WIN32OLE.new('AutoItX3.Control')

hwnd = Array.new

while true do
    File.readlines("C:\\Program Files\\PokerStars\\PokerStars.log.0").each do |line|
        
      if line =~ /You finished/ or line =~ /You have/ and !hwnd.include?(line[19..26])
        hwnd.push(line[19..26])
        autoit.Winclose("[HANDLE:#{hwnd[hwnd.length-1].to_s}]") 
      end
    end
    sleep (10)
  
end

Refactorings

No refactoring yet !

Your refactoring





Format Copy from initial code

or Cancel