Skip to content

Instantly share code, notes, and snippets.

@kimoto
Created October 1, 2010 16:06
Show Gist options
  • Select an option

  • Save kimoto/606408 to your computer and use it in GitHub Desktop.

Select an option

Save kimoto/606408 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'skype'
require 'nkf'
require 'kconv'
require 'uri'
require 'open-uri'
require 'rubygems'
require 'hpricot'
require 'logger'
logger = Logger.new(STDERR)
logger.info "application start"
logger.info Skype.init "test_app"
logger.info Skype.start_messageloop
last_message = message = nil
Skype::ChatMessage.set_notify do |chatmessage, property, value|
message = chatmessage.get_body
logger.info "compare last message: last:#{message.inspect}, now:#{last_message.inspect}"
if message == last_message
logger.info "already sent: last:#{message.inspect}, now:#{last_message.inspect}"
return
end
logger.info "chatmessage: #{message.tosjis}, property:#{property.inspect}, value:#{value.inspect}"
logger.info "if received ?"
#if property == :status and value == "RECEIVED"
if true
logger.info "---- IN RECEIVE"
if message =~ /(http:\/\/[^\s]+)/
url = $1
logger.info "found URL(matched): #{url}"
begin
title_text = open(url){|f|
logger.info "hpricot start"
ret = Hpricot(f.read).search("title").inner_html
logger.info "hpricot exit"
ret
}
logger.info "got title_text"
rescue => ex
logger.info "not response: " + ex.inspect
title_text = "not response"
end
logger.info "rescue exit"
logger.info "send message start: #{title_text.tosjis}"
chatmessage.get_chat.send_message "BOT) " + title_text.toutf8
last_message = message
logger.info "send message exit"
else
logger.info "not found URL(not matched)"
end
else
logger.info "NO received"
end
end
logger.info "attach wait -- start"
Skype.attach_wait
sleep
logger.info "application end"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment