Wednesday, June 14, 2006

Ruby Skype Bot

Here is a very simple Ruby Script that will reply to anything anyone says to you.


require 'win32ole'

oSkype = WIN32OLE.new('SKYPEAPI.Access')
puts "Version: #{oSkype.Version}"
oSkype.Connect()

puts "Getting events"
ev = WIN32OLE_EVENT.new(oSkype, '_IAccessEvents')

ev.on_event('ChatMessageReceived') do |msg|
to = msg.MessageFrom.Handle
puts "#{to} said: #{msg.Body}"
if to != oSkype.CurrentUserHandle
response = "OMG, I can't believe you just said '#{msg.Body}'"
oSkype.SendMessage(to, response)
end
end

# infinite loop to keep the script alive
loop do
WIN32OLE_EVENT.message_loop
end


It requires the Skype ActiveS dll to be registered. The ActiveS site does not have the dll in the latest MSI so, I was able to download it here and make it available for people to register.

No comments: