Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'rubygems'
- require 'net/yail/IRCBot'
- require 'hpricot' # For spitting out titles
- require 'open-uri'
- class Chewy < IRCBot
- BOTNAME = 'Chewbotca'
- BOTVERSION = '0.0.1'
- public
- def initialize(options = {})
- options[:username] = BOTNAME
- options[:realname] = BOTNAME
- options[:nicknames] = %w[ chewy chewbotca surfxica ]
- options[:irc_network] = 'irc.freenode.net'
- options[:channels] = '#bottest'
- # Set up IRCBot, our loving parent, and begin
- super(options)
- self.connect_socket
- self.start_listening
- end
- # Add hooks on startup (base class's start method calls add_custom_handlers)
- def add_custom_handlers
- # Set up hooks
- @irc.prepend_handler(:incoming_msg, self.method(:sort_incoming))
- end
- private
- def sort_incoming(fullactor, user, channel, text)
- if channel =~ /#{bot_name}/
- in_privmsg(user, text)
- else
- in_channel(user, channel, text)
- end
- end
- def in_channel(user, channel, text)
- if text =~ /^http/
- site_title = grab_site_title(text)
- msg(channel, "Title: #{site_title}") unless site_title.nil?
- end
- end
- def grab_site_title(address)
- site = Hpricot( open(address) )
- title = (site/"title").inner_html
- title.strip
- end
- end
Add Comment
Please, Sign In to add comment